Go Down

Topic: How to Get Accurate Timing to Milliseconds?? (Read 1 time) previous topic - next topic

RoboticsProfessor

I'm hearing and reading how millis() is not the answer for accurate time.

Several small clock chips, like DS3231, have month, day, hours, seconds and such, but not a good way to time milliseconds.

I only need milliseconds up to 59 minutes, 59 seconds.

Jack Christensen

How accurate does it need to be? In percent, or PPM, or whatever??
MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

retrolefty


I'm hearing and reading how millis() is not the answer for accurate time.

Several small clock chips, like DS3231, have month, day, hours, seconds and such, but not a good way to time milliseconds.

I only need milliseconds up to 59 minutes, 59 seconds.


Well if you can state your requirements for the max +/- error in milliseconds over a one hour period perhaps it would shed light on the possibilities or difficulties involved. Note that the source of any basic timing error is mostly due to unit to unit variation of the 16Mhz crystal or ceramic resonator used in most arduino boards which drive the basic clocking speed of the controller. Adding to this variation is crystal padding capacitor value variation tolerance and of course error due to ambient temperature variation for all those mentioned parts. Suffice it say that there will be some basic timing error for any crystal controlled device, but if that error is significant or not can only be answered by the designer of a given application or project.

So while there will always be some basic timing error for any arduino board in general, there is nothing to prevent one from measuring the specific error for one's specific board and using some compensating 'correcting factor' in software to improve the situation for that specific piece of software, e.i. a unit to unit calibration function. This of course is limited by the accuracy and resolution capabilities of the test equipment used by the user to measure the error. Typically one needs to have test equipment measurement accuracy of ten times the accuracy of specification to be meet.

Also keep in mind that there is the arduino defined micros() function that can measure up to a 70 min period, with a 4 microsecond 'step' count resolution. It too is no more accurate then the crystal time base, but in your case might be accurate enough and an improvement over using the millis() function for the same period in question.

Lefty

 

macegr

#3
Feb 02, 2012, 12:36 am Last Edit: Feb 02, 2012, 12:45 am by macegr Reason: 1
Since you're saying you need accurate timing to milliseconds, I'm assuming you don't want to be more than 0.5ms off the actual timing. That's 60m * 60s * 1000ms * 2 or 7,200,000. So, you are looking for something that is accurate to 1 part in 7.2 million, or 0.138888... ppm. You might save time by looking at sub-140ppb (parts per billion) oscillators instead.

Edit: forgot to mention that the Arduinos with crystals will usually be +/- 20ppm and the Arduino Uno with resonator will be +/- 100ppm. So, almost a thousand times more inaccurate than you need (based on my assumption of how accurate you need the measurements).

Oscillators in that range and lower will cost between 40 and a few hundred dollars. This one seems like a good deal: http://search.digikey.com/us/en/products/DOC050V-010.0M/CW692-1-ND/2619585

It's an oven-controlled oscillator. Temperature drift is managed by heating the crystal up to a regulated temperature. It will take about one minute to warm up before the readings will be accurate. Also, the accuracy will degrade up to 10ppb per day and 300ppb per year, so be prepared to test and replace these as needed. This is also an OCVXO, which would let you use an external voltage to adjust the frequency a tiny amount to compensate for aging. You'll need to calibrate these every few days of operation for best results.
Unique RGB LED Modules and Arduino shields: http://www.macetech.com/store

Coding Badly

Quote
Arduino Uno with resonator will be +/- 100ppm.


For the record, my Uno is considerably less accurate than that.

Go Up