Go Down

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

#### polymorph

#15
##### Feb 10, 2015, 09:09 pm
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

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

#### polymorph

#16
##### Feb 10, 2015, 09:12 pm
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

#### polymorph

#17
##### Feb 10, 2015, 09:13 pm
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8

#### nickgammon

#18
##### Feb 11, 2015, 12:13 am
My page http://www.gammon.com.au/millis discusses the inaccuracy of millis().

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!