Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pulseIn function inaccuracy
28-01-2017, 06:34 PM, (This post was last modified: 29-01-2017, 02:28 PM by Aldeen19.)
#1
Photo  pulseIn function inaccuracy
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.


Attached Files Thumbnail(s)
   
Aldeen19
Reply
29-01-2017, 06:39 PM,
#2
RE: pulseIn function inaccuracy
(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
Reply
29-01-2017, 07:18 PM,
#3
RE: pulseIn function inaccuracy
(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.
Aldeen19
Reply
29-01-2017, 10:53 PM,
#4
RE: pulseIn function inaccuracy
(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
Reply
30-01-2017, 02:16 PM,
#5
Smile  RE: pulseIn function inaccuracy
(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!


Attached Files Thumbnail(s)
                   
Aldeen19
Reply
31-01-2017, 12:44 AM,
#6
RE: pulseIn function inaccuracy
(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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)