Uno millis() falls behind over long periods (hours/days)

Hi @GameMaker_1

The choice of microcontroller clock source (ceramic oscillator or crystal) depends on the absolute accuracy you require with respect to your reference point. (Time like space is measured from some predefined reference point).

Errors increase gradually as over time, as your clock source measurement diverges from the ideal, in the same way your wrist watch slowly diverges from UTC time + time zone. The accuracy of you clock source determines how fast this divergence take place.

The official Arduino AVR microcontrollers (Uno/Mega) only use a ceramic resonator, so as Danois90 says, they're not that accurate and drift with time and temperature. Using ceramic resonators you'll get plus or minus minutes or more of drift per day.

Some of the later ARM microcontrollers (Due/Zero/MKR) offer a 32.768kHz external crystal that can be used in conjuction with microcontroller's internal RTC. Using these crystals you'll get up to plus or minus 1 to 2 seconds of drift day.

Again as Danois90 pointed out, some external RTC chips such as the DS3231 can offer excellent temperature compensated time measurements with minimal drift.

If you're using an Arduino Uno and need to trigger real-time events during the day then an external RTC is the way to go.

1 Like