Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Arduino Uno timing accuracy?

Status
Not open for further replies.

MikeMl

Well-Known Member
Most Helpful Member
I have a periodic stream of pulses roughly 10ms between rising edges. I want to measure the period of the pulses. I am willing to take data for up to 10s (average of ~1000 periods) before computing the answer. What absolute accuracy can I expect considering the untrimmed 16MHz resonator and the millis() function in the Uno?
 
Using FreqMeasure your count of CPU cycles is expected to be 16k and over 1k samples is expect to be 16M. THe resolution is now greater than the Xtal accuracy of < 50 ppm which can be tuned or replaced with a 1ppm TCXO to determine your accuracy.
 
The Arduino does very poorly at measuring time, at least in my experience. The libraries are very bulky and waste a lot of time that is not taken into account. The millis() function alone is horrifically inaccurate. I would recommend either writing your own libraries and take the instruction timing into account (nearly impossible to do with C++), or use a bare micro (AVR, PIC) running Assembly (for most efficient code).
 
Millis is not that bad
millis() is interrupt driven so delay() won't impact it, at least not on an ATmega based board.

That isn't to say that millis() is totally accurate either. Each tick of the timer is not exactly 1ms, but is 1.024ms. This error gradually accumulates until a correction is made. This can be seen in the implementation of the TIMER0_OVF (timer 0 overflow) interrupt handler.

Another source of inaccuracy is the oscillator/crystal itself, which is not exactly 16MHz. It is pretty close though, and as long as temperature doesn't change too much, is relatively stable.

The above means that you might be about 1ms out when using millis()
With a little testing you could hit time almost on the head. The ardunio's I have got crystals and playing with some code for time it was as good as my alarm clock it lost a sec or two a day.
 
Well you need a frequency counter with start stop lucky i have one. but you could detect a level rise with a gate and a level stop with a gate now to get to the count you need registers quite a few 10ms is long time
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top