Time drift on reboot

jackland
Posts: 4
Joined: Mon Jan 20, 2020 5:41 pm

Time drift on reboot

Postby jackland » Mon Jan 20, 2020 5:59 pm

Hi All,

The clock on a esp32-cam board seems to keep good time, but after a week's uptime the clock can jump by a couple of hours on reboot. My understanding is that SetTimeOfDay sets both the RTC and the clock based on the high precision timer, but the latter is cleared on a deep-sleep or reboot and so the time is reset from the RTC, which is using the internal (non-crystal) oscillator and so drifts.

I could use a timer to periodically call SetTimeOfDay with the current system time, but this would set both the system clock as well as the RTC and so would probably make the system clock gradually drift. What would be better is a set_rtc_from_system_time or set_rtc function so I could set the RTC every 15 minutes or so and it wouldn't have drifted much by the next reboot. Is there a function like this? I haven't been able to find anything in the documentation so far.

Thanks
Bob

ESP_igrr
Posts: 2067
Joined: Tue Dec 01, 2015 8:37 am

Re: Time drift on reboot

Postby ESP_igrr » Mon Jan 20, 2020 8:17 pm

Hi Bob,
Unless you sync the time from NTP, waking up periodically and setting the RTC time should not make any difference: the total drift will be the same, on average, as if the device would sleep for a long time.
You may try changing the RTC clock to "8M/256", this is an option in menuconfig under "ESP32 specific options". This will still drift more than an XTAL oscillator, but less than the default 150k RTC clock.

jackland
Posts: 4
Joined: Mon Jan 20, 2020 5:41 pm

Re: Time drift on reboot

Postby jackland » Thu Apr 30, 2020 8:03 am

Hi,

Clock drift was much less with the 8M/256 option.

Thanks

Bob

Who is online

Users browsing this forum: Google [Bot], ok-home and 154 guests