Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PulseIn problem
22-05-2014, 05:43 PM,
#1
PulseIn problem
hi!

I am working with PulseIn function get time from a square signal, the point is that this function should deliver on time delivery in micro seconds and a value too high. for example, if the input signal is 1.8kHz should print approximately 555 microseconds, and prints 7048 that this measure is that? use a timeout of 1 second.
regards
Reply
23-05-2014, 09:29 AM,
#2
RE: PulseIn problem
Hello Zarekx,

(22-05-2014, 05:43 PM)Zarekx Wrote: I am working with PulseIn function get time from a square signal, the point is that this function should deliver on time delivery in micro seconds and a value too high. for example, if the input signal is 1.8kHz should print approximately 555 microseconds, and prints 7048 that this measure is that? use a timeout of 1 second.

the pulseIn-function doesn't take the cpu it runs on and the value of the system clock into account. If you want reliable results you have to write your own function.

I had the same problem with the measurement of the pulse length of an ultrasonic sensor. I've adapted the pulseIn funtion working with both an pic18f25k50 and pic32mx220.

Look here for the code.

Greetings
Oliver
Reply
23-05-2014, 11:00 AM, (This post was last modified: 23-05-2014, 11:02 AM by moreno.)
#3
RE: PulseIn problem
Hi

A small suggestion.
Your code is correct but sometime processor have strange behaviours.

With counter is better avoid equal condition

Instead of
if (numloops++ == maxloops)

is better use
if (numloops++ >= maxloops)

You use 64bit counter, if for some unknown reason the processor fail the equal check, you must wait about 584.942 years in order to have an other chance to check numloops++ == maxloops.


Bye Bye, Moreno
Reply
23-05-2014, 12:51 PM,
#4
RE: PulseIn problem
If you need high resolution time measurement, some works done at http://romanblack.com/ may be of your interest. Good luck.
Reply
23-05-2014, 01:18 PM,
#5
RE: PulseIn problem
(23-05-2014, 11:00 AM)moreno Wrote: You use 64bit counter, if for some unknown reason the processor fail the equal check, you must wait about 584.942 years in order to have an other chance to check numloops++ == maxloops.

584.942 years? Thanks for pointing that out. Smile

djpark Wrote:If you need high resolution time measurement, some works done at http://romanblack.com/ may be of your interest.

Very interesting website! Thanks for the link.

Greetings
Oliver
Reply
23-05-2014, 01:50 PM,
#6
RE: PulseIn problem
(23-05-2014, 12:51 PM)djpark Wrote: If you need high resolution time measurement, some works done at http://romanblack.com/ may be of your interest. Good luck.

Interesting site - thanks!

John
Reply
02-06-2014, 09:29 PM,
#7
RE: PulseIn problem
thanks for your replies, I'll see what results I get with the help they gave me.
Regards and thank you very much!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)