Pinguino Forum

Full Version: pulseIn function inaccuracy
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have been experimenting on “pulseIn” function for a while to measure duration of pulses and the results were always far beyond their correct values! .. I have noticed that the error margin is non-linear and it increases as the duration gets high.   Is there anyway to compensate the error mathematically to overcome this inaccuracy?
Any idea will be appreciated, thank you in advance.
(28-01-2017, 06:34 PM)Aldeen19 Wrote: [ -> ]I have been experimenting on “pulseIn” function for a while to measure duration of pulses and the results were always far beyond their correct values! .. I have noticed that the error margin is non-linear and it increases as the duration gets high.   Is there anyway to compensate the error mathematically to overcome this inaccuracy?
Any idea will be appreciated, thank you in advance.

The pulseIn function is a strange one. It doesn't take into account the cpu it runs on and the value of the system clock. 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.

You can find my code here in the wiki.

Oliver
(29-01-2017, 06:39 PM)pinguPlus Wrote: [ -> ]
(28-01-2017, 06:34 PM)Aldeen19 Wrote: [ -> ]I have been experimenting on “pulseIn” function for a while to measure duration of pulses and the results were always far beyond their correct values! .. I have noticed that the error margin is non-linear and it increases as the duration gets high.   Is there anyway to compensate the error mathematically to overcome this inaccuracy?
Any idea will be appreciated, thank you in advance.

The pulseIn function is a strange one. It doesn't take into account the cpu it runs on and the value of the system clock. 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.

You can find my code here in the wiki.

Oliver

Well thanks Oliver.  Making a private pulseIn function is really a nice smart idea.
I shall have to study it carefully. Danke.
(29-01-2017, 07:18 PM)Aldeen19 Wrote: [ -> ]Making a private pulseIn function is really a nice smart idea.
I shall have to study it carefully. Danke.

You're welcome. Wink

Could you provide a sketch and a description what you're trying? I'm just curious.

Oliver
(29-01-2017, 10:53 PM)pinguPlus Wrote: [ -> ]
(29-01-2017, 07:18 PM)Aldeen19 Wrote: [ -> ]Making a private pulseIn function is really a nice smart idea.
I shall have to study it carefully. Danke.

You're welcome. Wink

Could you provide a sketch and a description what you're trying? I'm just curious.

Oliver

It is my pleasure Oliver,  
Simply I am trying to build a core for a signal or pulse generator with an LCD to display frequencies and other info for my modest electronic workbench by using Pinguino 4550 - 20 MHz clock.
Please, see attached sketch, code and photos.
Cheers!
(30-01-2017, 02:16 PM)Aldeen19 Wrote: [ -> ]Simply I am trying to build a core for a signal or pulse generator with an LCD to display frequencies and other info for my modest electronic workbench by using Pinguino 4550 - 20 MHz clock.

Interesting. Maybe we could write an wiki article when your project is finished.

Oliver