Go Down

Topic: Micros vs. Milis: Accuracy of interrupt measurements (Read 4033 times) previous topic - next topic

polymorph

16,000 pulses per mile. So 1mph is 4.44 pulses per second, 10mph is 44.4 pps, 50mph is 222.2 pps. I'm not surprised that it would shift around at lower speeds using milliseconds to count pulses.

Or to look at it another way, 0.225 seconds per period at 1mph, 0.0225 spp at 10mph, and 0.0045 spp at 50mph.

Yeah, at only 4.5ms per period at 50mph, millis() is far too coarse to count the period.

eRCaGuy_Timer2_Counter - [Update: 17 May 2014 - Timer2_Counter has been turned into a true Arduino Library. New example added.] A generic Arduino micros()-equivalent timing function with 0.5us precision (rather than the 4us precision of the built-in micros() function). --This allows, as one example, a very precise reading of Radio-Control (RC) PPM and PWM signals, from an RC transmitter and receiver, respectively, using external interrupts, with*out* using the Atmega Timer1 which would disable use of the Servo library. Tested only on Arduinos with an Atmega328
http://electricrcaircraftguy.blogspot.com/2014/02/Timer2Counter-more-precise-Arduino-micros-function.html#.VNpkvPnF-Sg

Frequency Counter - using Timer1
http://interface.khm.de/index.php/lab/interfaces-advanced/arduino-frequency-counter-library/

FreqPeriodCounter - Versatile frequency counter which measures frequency, period, pulse width etc. Can be used interrupt triggered or polled.
http://www.avdweb.nl/arduino/hardware-interfacing/frequency-period-counter.html
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8
Multitasking: forum.arduino.cc/index.php?topic=223286.0
gammon.com.au/blink - gammon.com.au/serial - gammon.com.au/interrupts

polymorph

How about pulseIn()? Times to microseconds. You might want to use a divide-by-two in hardware first, to avoid errors due to changes in duty cycle. Just don't forget to take account of that in software.

http://arduino.cc/en/Reference/pulseIn

At 100mph, that would still be 450us per period, or 900us if you divide by two first.
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8
Multitasking: forum.arduino.cc/index.php?topic=223286.0
gammon.com.au/blink - gammon.com.au/serial - gammon.com.au/interrupts

polymorph

Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8
Multitasking: forum.arduino.cc/index.php?topic=223286.0
gammon.com.au/blink - gammon.com.au/serial - gammon.com.au/interrupts

nickgammon

My page http://www.gammon.com.au/millis discusses the inaccuracy of millis().

Also on my http://www.gammon.com.au/interrupts page I advise against counting things using delay (specifically http://www.gammon.com.au/forum/?id=11488&reply=10#reply10 ).

Also see http://www.gammon.com.au/timers where I have various frequency-counting sketches using the hardware timer. Using the hardware eliminates jitter caused by slight delays in interrupts firing.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

polymorph

The OP will have to let us know if any of this helps him.
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8
Multitasking: forum.arduino.cc/index.php?topic=223286.0
gammon.com.au/blink - gammon.com.au/serial - gammon.com.au/interrupts

Go Up