RTC (DS1307 or other) with millisecond resolution

cpixip:

  • just a hint: RTCs like the DS1307 have a rather limited precision, loosing or gaining usually a few seconds per day. They are however typically a factor 10 better than a timing based on the Arduino-clock (i.e. millis()).

In fact, clock-crystals are usually operating at the rather low frequency of 32.768 Hz and are rated with 25 ppm, which gives you +- 2.16 secs error per day (25e-660sec60*24). The crystal the Arduino derives it's clock from (and the millis()-timing) is even rated worse.

There is obviously some confusion here, probably induced by clones with ceramic resonators, or units running on internal clocks.

But if you have an arduino or clone, or any microcontroller chip, that is driven by a crystal, then there is little to no reason to use an external rtc just to keep accurate time. An rtc uses a crystal too. And the timer interrupts work as well as or better than using an external interrupt with a square wave.

http://www.arduino.cc/playground/Code/Time

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1245423319#3

The accuracy of the millis() function is governed by the clock in your Arduino board which is driven by either a crystal or ceramic resonator. A crystal has an accuracy of roughly +/- 50 parts per million (ppm) or so (some are more accurate some are less, but 50ppm is about right for a cheap crystal).

50 ppm = 0.005% accuracy which in your case equals about 0.72 seconds deviation from the nominal delay over 4 hours at 16MHz

A ceramic resonator is about 0.5% accurate = 72 seconds over 4 hours or about 1 minute 12 seconds at 16MHz.
...
The same kind of clock accuracy calculations apply to a DS1307 RTC, the fundamental accuracy of the crystal determines the accuracy of the time it keeps, there's nothing special about the DS1307 in terms of accuracy and it could in fact be worse than the Arduino's internal clock. It all comes down to the simple question of how accurate you need the timing to be for your application and then select an appropriate oscillator.

so you can see that it is not anywhere near "a factor 10 times worse", and for pennies you can easily retrofit a more accurate crystal if the stock one is not accurate enough for you.