Gord_W
Posts: 4
Joined: Wed Jan 20, 2016 4:44 pm

rtc DS3231 hwclock never perfectly aligned with system clock

Wed Jan 20, 2016 5:22 pm

I have a DS3231 on my rPi B 256 MB and I can read and write to the hardware clock OK.

The problem is that there is always an offset between the the system clock and the hwclock of about 0.5 sec. In other words if I set the hwclock with the sysclock and then set the sysclock from the hwclock the sysclock should in theory be unchanged, but in fact it is now ~0.5 sec out.

ntpd is not running. pi is idle >95%. I'm running headless through ssh, if that is of interest.

An example:

root@DietPi:~# ntpdate -b time.nrc.ca
20 Jan 12:02:04 ntpdate[2910]: step time server 132.246.11.227 offset 0.000053 sec <<<<< sys clock now on ntp time
root@DietPi:~# hwclock -w
root@DietPi:~# hwclock -s
root@DietPi:~# ntpdate -b time.nrc.ca
20 Jan 12:03:06 ntpdate[2916]: step time server 132.246.11.227 offset 0.504072 sec <<<<< ~0.5 sec shift in time

The problem is each time the hwclock is set and then sysclock set, the time will move another 0.5 sec each cycle. Do it 10 times and the error is 5 sec.

I was expecting a few (maybe 10s) of ms error to creep in, but 0.5 sec seems a bit high.

I'm using
hwclock from util-linux 2.20.1

the /etc/adjtime file is (no drift corrections applied)
0.000000 1453309355 0.000000
1453309355
UTC

i2c is set at 100KHz, 400KHz doesn't make a difference.

Is this normal? Any way to reduce the round trip error?

thanks,
Gord_W

Gord_W
Posts: 4
Joined: Wed Jan 20, 2016 4:44 pm

Re: rtc DS3231 hwclock never perfectly aligned with system c

Thu Jan 21, 2016 2:02 pm

Hello,

If this is not the right forum for asking questions like this, where should I ask? I'm new at this so a little bit of help would be appreciated.

Gord_W

User avatar
jojopi
Posts: 3041
Joined: Tue Oct 11, 2011 8:38 pm

Re: rtc DS3231 hwclock never perfectly aligned with system c

Thu Jan 21, 2016 5:41 pm

The registers of a real time clock chip generally store the time to a resolution of one second only. There must be a 1/32768th counter or divider internally, but it cannot be read or written programmatically.

hwclock attempts to get sub-second accuracy by reading the time repeatedly until the seconds just change. When writing the RTC, it does so at a system time that is an odd multiple of half a second. The MC146818 chip used in the IBM PC/AT effectively set its sub-second counter to a half whenever the seconds were updated.

However, DS3231 appears to clear its sub-second count to zero when the time is set. So the hwclock -w behaviour introduces an error of -0.5s. This is rather unfortunate, because DS3231 is one of the few RTCs with accuracy better than 0.5s/day.

There is a version of hwclock that can do "hwclock --systohc --correct=0.5": http://giraffe-data.com/software/about_hwclock.html

Gord_W
Posts: 4
Joined: Wed Jan 20, 2016 4:44 pm

Re: rtc DS3231 hwclock never perfectly aligned with system c

Thu Jan 21, 2016 10:24 pm

Many thanks for that info. That correction looks like it is what I need.

My hwclock is the one that comes in util-linux and is the standard rpi issue. The one that you point toward is different and maintained by Bryan Henderson. Would the Henderson one break things?

Do you know if there is a precompiled version around that I can drop in? I've not gone through the compiling process before.

Thanks,
Gord_W

Return to “Troubleshooting”

Who is online

Users browsing this forum: Bing [Bot] and 70 guests