A20 Builtin RTC CLOCK drift

Started by enrico.capone, October 05, 2022, 12:46:19 PM

Previous topic - Next topic

enrico.capone

Hello i have a problem with the builtin RTC on A20 LIME2 latest release hardware and image

I have attached a 3v backup battery on the pcb on the right of serial console.

The hardware clock after 24 hours of power off i observed a drift aproximately by 3 hours.
This is enormous drift i belive there is something wrong on the oscillator.


olimex@a20-olinuxino:~$ cat /proc/cmdline
root=PARTUUID=bdf775eb-01 rootwait console=ttyS0,115200 panic=10 loglevel=4
olimex@a20-olinuxino:~$ uname -a
Linux a20-olinuxino 5.10.105-olimex #090538 SMP Wed Apr 13 09:06:56 UTC 2022 armv7l GNU/Linux
olimex@a20-olinuxino:~$


LubOlimex

I don't remember anyone mentioning such drift, and a lot of people had asked about the RTC clock. Did you measure the voltage of the battery before and after?

Are you certain the clock you check gets updated by the clock kept alive by the battery?
Technical support and documentation manager at Olimex

enrico.capone

Quote from: LubOlimex on October 05, 2022, 03:58:51 PMI don't remember anyone mentioning such drift, and a lot of people had asked about the RTC clock. Did you measure the voltage of the battery before and after?

Are you certain the clock you check gets updated by the clock kept alive by the battery?


Thanks for the fast reply, the battery is new the voltaga is 3,03 and i disconnected the board from any power source.
I made these steps to test the clock:
1)Sinchronize the time with ntp (timedatectl ntp enable)
2)Write the clock to RTC sudo hwclock --systohc
3) sudo halt
4) disconnect from power source
5) after 24 hours connect the lan to local network without internet access to avoid ntp sync then power on
6) timedatectl to check the time

The drift is visible also with a small power down period and is  proportional to power off time.

It seems to me to a bad oscillator configuration wher powered from backup battery.
Let me know if you can reproduce it and how to solve i have 100 boards to configure and they all need RTC working.

Best regards

LubOlimex

Can you do the following test - disconnect the 3V backup battery, power the board. Run

timedatectl
hwclock --systohc

Now check again timedatectl

Then wait 5 minutes and again timedatectl

Did the clock lag behind even when board is fully powered (no backup battery)?

I believe it might be this thing, where time zone is improper:

https://www.linuxquestions.org/questions/slackware-14/time-lags-by-exactly-3-hours-always-4175451045/
Technical support and documentation manager at Olimex

enrico.capone

Hello,
here the test you suggestested, there is a small lag on rtc 3 seconds for five minutes run
olimex@a20-olinuxino:~$ timedatectl
               Local time: Fri 2022-10-07 10:08:14 CEST
           Universal time: Fri 2022-10-07 08:08:14 UTC
                 RTC time: Fri 2022-10-07 08:08:15
                Time zone: Europe/Rome (CEST, +0200)
System clock synchronized: no
              NTP service: active
          RTC in local TZ: no
olimex@a20-olinuxino:~$ timedatectl && sudo hwclock --systohc
               Local time: Fri 2022-10-07 10:09:03 CEST
           Universal time: Fri 2022-10-07 08:09:03 UTC
                 RTC time: Fri 2022-10-07 08:09:04
                Time zone: Europe/Rome (CEST, +0200)
System clock synchronized: no
              NTP service: active
          RTC in local TZ: no
[sudo] password for olimex:
olimex@a20-olinuxino:~$ timedatectl && sudo hwclock --systohc
               Local time: Fri 2022-10-07 10:09:15 CEST
           Universal time: Fri 2022-10-07 08:09:15 UTC
                 RTC time: Fri 2022-10-07 08:09:16
                Time zone: Europe/Rome (CEST, +0200)
System clock synchronized: no
              NTP service: active
          RTC in local TZ: no
olimex@a20-olinuxino:~$ timedatectl
               Local time: Fri 2022-10-07 10:09:29 CEST
           Universal time: Fri 2022-10-07 08:09:29 UTC
                 RTC time: Fri 2022-10-07 08:09:30
                Time zone: Europe/Rome (CEST, +0200)
System clock synchronized: no
              NTP service: active
          RTC in local TZ: no
olimex@a20-olinuxino:~$ timedatectl
               Local time: Fri 2022-10-07 10:14:30 CEST
           Universal time: Fri 2022-10-07 08:14:30 UTC
                 RTC time: Fri 2022-10-07 08:14:33
                Time zone: Europe/Rome (CEST, +0200)
System clock synchronized: no
              NTP service: active
          RTC in local TZ: no


enrico.capone

I made a test with battery on rtc.
I turned off the board and disconnected from power for 10 minutes i powered on and the drift on rtc is 49 seconds.
The problem is not the timezone.
Is seems that the RTC has a wrong clock.
I've found this post could you evaluate if it is useful?

https://patchwork.ozlabs.org/project/rtc-linux/patch/577CC494.8020103@roslen.de/

Thanks

JohnS


LubOlimex

One thing - are you sure the RTC is off? Did you use another outside clock to determine it. Because if we sync local time and RTC and after a while then we see difference between local time and RTC, I would assume the local time is off, not the RTC.
Technical support and documentation manager at Olimex

enrico.capone

I have tested the drift with an external clock syncronized with ntp.
I'have used the latest distribution without changing any system script.

Could you suggest me steps to do in order to give you all the information you need?
Thanks

LubOlimex

Do you have access to an oscilloscope?
Technical support and documentation manager at Olimex

LubOlimex

I think the issue is that by default in the Linux image it is not the external RTC used, but the internal one, and the internal RTC is very inaccurate. But we are still investigating.
Technical support and documentation manager at Olimex

LubOlimex

#11
Can you try the following:

1. Get devmem2 source code (this requires Internet), compile it and give it permissions with:

wget https://raw.githubusercontent.com/hackndev/tools/master/devmem2.c

gcc devmem2.c -o devmem2

(optional)chmod +x devmem2

2. execute this to enable external RTC clock

./devmem2 0x01c20d00 w 0x16aa4001
By default the value of the register at that address is 0x16aa4000 which is internal RTC. You can check that in the A20 user manual in chapter 1.9.3.26. LOSC CONTROL REGISTER (DEFAULT: 0X00004000):

https://www.olimex.com/Products/SOM/A20/_resources/A20-User-Manual-2013-03-22.pdf

Check if there is lag now. Notice that if you reboot, this setting will be reverted.
Technical support and documentation manager at Olimex

enrico.capone

Hello,
yes we have oscilloscope. (wich signal to test?)

The lag appears if i power down the machine.
Is this setting valid during power off cycle?
If not how can i do the test running with RTC backup battery?

Thanks

LubOlimex

You do this test while powered on, since even then lag is huge. As you pointed in your test - 3 seconds for only 5 minutes, that is more than 30 seconds per hour...

But I need your feedback to see if it fixes the issue at your side too before forwarding to software team.
Technical support and documentation manager at Olimex

enrico.capone

Thanks seems to work!
I also tried to set the bits before power off and it works.
So now to finalize all what is the best way to deploy the solution?
Set the bits somewhere in the starting and stopping scripts?
Thank you.