Go Down

Topic: Keeping accurate time (Read 46384 times) previous topic - next topic

ad2049q

#60
Sep 17, 2016, 07:11 pm Last Edit: Sep 17, 2016, 07:12 pm by ad2049q
Mine was off by +- 2 parts in 10000 from presumption of software "microseconds" == 1.00000 microseconds and was noticed to be somewhat temperature dependent in how far off.  Room temperature was 15 to 20 C.

Yours seems to be off by 2 parts in 1440 which is even worse.
If you make a measured correction, such as 'count to 10014900 "microseconds" and call that a "second" ' that will lessen your error but still drift according to temperature of the crystal.  You have three options - get ntp time on an internet device such as a raspberry pi, or get a real time clock add-on module as mentioned above, or get the module to pick up the atomic synched radio clock if you are in a region which has one.

ad2049q

Your loop relied on

Code: [Select]

void loop()
  {
  do some stuff;
  delay(1000);
  }

So if it takes any time at all to do some stuff then you'll get behind with respect to 1000 "milliseconds".

MarkT

If you live in a blackout-prone area (like a rural or Third World area) the Arduino's crystal will, if calibrated, make a pretty good fallback oscillator. In that case, you get to figure out how to design the power supply as well as the software. If you go the 60Hz route, be careful not to let the pulses exceed the 5 volts!
Your Arduino has a crystal?  Clearly not an Uno then, which use inaccurate ceramic oscillator.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

dwightthinker

This rolls over every 1.2 hours or so, but that is not a problem in this sort of application. Another advantage -- in this application, quite a great one -- is that a clock that runs too fast or too slow is easily adjusted by changing the value of the constant oneSecond. (sort of like the fast/slow lever on a wind-up alarm clock)
Actually, there is an interesting discussion going on about millis().
A single tick of millis() is actually 1.024 milliseconds.
It periodically skips a count to keep the error within
+- 1 millisecond.
This has nothing to do with rollover.
One should always use >= or > with millis() but never ==
as it may never actually count that number.
Of course, these boards do use a resonator for the processor.
The crystal on the board is for communications with the USB.
Dwight

Go Up