Report on DS3231SN timekeeping performance

A while back I built a project that has a DS3231 RTC generate interrupts to a Pro Mini from time to time. Two months ago, I synced the DS3231 time to the website time.gov, and today I checked it against that same site. After two months, it was 4 seconds fast, which annualized is 24 seconds.

I had the Aging register set to -5, which from previous tests I thought was about the right value. So today I changed that to -4, and will check again in a month or two.

My setup promotes good timekeeping in that the DS3231 is enclosed in a project box inside my house, so temperature is pretty constant, and it is powered by a 5V wall wart. I know from past experience that supply voltage affects oscillation frequency significantly.

Anyway, I just wanted to confirm for those considering using this part that with appropriate fine tuning via the Aging register, the DS3231SN can do pretty well. The DS3231M can be fine tuned the same way, but may not do quite as well.

Good post. Can you explain more about the aging register? I have messed with a ds3231 module a little, but no long term projects.

Thanks for sharing!
Posting some simple code showing how you adjust it and how you determined how much to adjust it would be great.

I use the same part and I have found it very close. My system checks it every 8 hours and it may find a second now and then but there is no provision for network latency etc.

The Aging register is register 0x10. It contains a signed byte (int8_t), which means its value ranges from +127 to -128. The default value on power up is zero. A higher value makes the oscillator run slower.

This register is entirely under user control. After you write a value to it, it will remain unchanged until power to the DS3231 is lost.

The DS3231SN should work pretty well with Aging set to zero, so you don't absolutely have to mess with it. However, the DS3231M is another matter. I found that my three M's had optimal Aging settings of -40 to -20.

I don't use a library for the DS3231, so my code is pretty simple:

Aging = readReg(0x10);
writeReg(0x10, Aging);

byte readReg(byte regAddr) {                 // read RTC register
  Wire.beginTransmission(RTCaddr);           // I2C address of DS3231
  Wire.write(regAddr);                       // select register
  Wire.endTransmission();
  delay(10);
  Wire.requestFrom(RTCaddr, 1);
  return (Wire.read());
}

void writeReg(byte reg, byte val) {          // write to RTC register
  Wire.beginTransmission(RTCaddr);
  Wire.write(reg);
  Wire.write(val);
  Wire.endTransmission();
}

As for how much to adjust it, I used to remember how much a change of +/- 1 would produce, but I've long since forgotten that. So you just need to experiment.

Dump the ProMini/RTC and replace it with a XIAO ESP32-C3.
The ESP can get time off the internet.
Accurate within 1 second, forever. Including daylightsavings if your country has it.
Leo..

P.S. The XIAO C3 has a battery connector for a protected LiPo cell and includes built-in charger.
It can run for days on that without loosing time.

[quote="ShermanP, post:5, topic:1442298"]
Aging = readReg(0x10);
writeReg(0x10, Aging);

Thanks, many will appreciate the code and explanation. I appreciate the lack of a library, I use as few as possible.

Following up on this 30 days later, as compared to time.gov, the DS3231 is now two seconds fast, down from four seconds fast. So changing the aging setting by one slowed it down by two seconds in a month.

So to recap, with aging set to -5, it gained 4 seconds over two months.

With aging set to -4, it gained 2 seconds over one month, which is essentially the same. Of course I'm just eyeballing this, not measuring precisely. But it appears a change of one to aging is a really fine tuning kind of thing.

I'll test it again next month.

So I'm changing aging to -3 and resetting the RTC to match time.gov, and we'll see what happens next month.

I should say that between winter and summer, there is a difference of about eight degrees (F) in ambient temperature indoors because of different thermostat settings. I don't know if that makes any difference.