Skip to content

Test: Real-Time Clocks (DS3231)

Timekeeping & I2C

Real-Time Clocks: Inside the DS3231

Why a separate clock chip?

A microcontroller can keep time by counting ticks, but only while it has power, and only as well as its oscillator. An internal RC oscillator is good to about 1%, which is 14 minutes a day. A 32.768 kHz watch crystal is far better (32 768 is 2¹⁵, so fifteen divide-by-two stages give exactly 1 Hz), but a cheap one is 20 ppm out, and it runs slow as it moves away from 25 °C. The DS3231 measures its own temperature and trims its crystal to hold ±2 ppm from 0 to 40 °C, and it keeps going on a coin cell when the power goes. Run the clocks and compare.

Challenge: Set the tolerance to 0 ppm (a perfect crystal) and find a bench temperature at which it still drifts by more than a minute in 30 days.

True time, day 0.0

29 Sep 00:00:00

Software tick, internal RC oscillator (1%)

+10000 ppm

29 Sep 00:00:00 (+0.0 s)

MCU with a 32.768 kHz watch crystal

+20.0 ppm

29 Sep 00:00:00 (+0.0 s)

DS3231 (TCXO, on its coin cell)

+0.4 ppm

29 Sep 00:00:00 (+0.0 s)

÷232 768 Hz÷2÷2÷2÷22 048÷2÷2÷2÷2÷264÷2÷2÷2÷2÷221 Hz32 768 = 2¹⁵, so the fifteenth stage ticks once a second. Any error in the crystal passes straight through.
← Start here
Speed

Time error so far: watch crystal and DS3231

−5 s+5 s00 d7 d

The crystal follows a parabola, about −0.034 ppm per °C² either side of 25 °C, so any change of temperature makes it run slower; its tolerance shifts the whole curve. The DS3231’s residual error here is illustrative, within its ±2 ppm specification. Each aging-offset step trims it by about 0.1 ppm (positive slows it). The RC oscillator is off the plot: 1% is 14 minutes a day.