The esp32 timer drifted over half an hour in the course of 10 hours (in deep sleep). Is this normal?

cal237
Posts: 5
Joined: Mon Jul 12, 2021 3:15 pm

The esp32 timer drifted over half an hour in the course of 10 hours (in deep sleep). Is this normal?

Postby cal237 » Sat Jul 31, 2021 1:18 pm

My esp32 is supposed to wake up at a certain time. It calculates the number of microseconds for esp_sleep_enable_timer_wakeup() by getting the current time from NTP and calculating the difference between now and the desired wakeup time. I turned in on around 10:30pm and set it to wake up at 8:30am. It woke up at 7:55am. I knew the RTC timer clock was not very accurate, but I was not expecting it to drift that far. Is this normal?

fabianoriccardi
Posts: 10
Joined: Fri Nov 01, 2019 6:52 pm
Location: Italy
Contact:

Re: The esp32 timer drifted over half an hour in the course of 10 hours (in deep sleep). Is this normal?

Postby fabianoriccardi » Mon Aug 02, 2021 7:25 pm

If you rely on the internal oscillator (a simple RC), it should have a relative error of up to 10% (if I recall well). Maybe ESP32 can be slightly better, but in general RC oscillator has a significant drift. So if it deep sleeps few hours, it can drift *minutes*.
Find me on GitHub :geek:

zmlee79
Posts: 2
Joined: Tue Feb 09, 2021 3:50 pm

Re: The esp32 timer drifted over half an hour in the course of 10 hours (in deep sleep). Is this normal?

Postby zmlee79 » Wed Aug 04, 2021 4:31 am

In my tests on some devices, after entering the deep-sleep mode, the frequency of RTC_CAL_8MD256 is reduced by about 6%. By calibrating the error between the sleep mode and the actual time, before entering the sleep mode

const double clockRate = 1.06; // Each device needs to be calibrated independently
REG_WRITE(RTC_SLOW_CLK_CAL_REG, (uint32_t)(0.5 + rtc_clk_cal(RTC_CAL_8MD256, CONFIG_ESP32_RTC_CLK_CAL_CYCLES) * clockRate));

A clock accuracy of about 50ppm can be obtained. I recalibrated the RTC clock by waking up for about 40 milliseconds every about 1 minute in the deep-sleep mode. In the test of my two devices, I got an accuracy of 10ppm, which is very close to the accuracy of a 40M crystal oscillator. The error of one device after running for 3 days is 300 milliseconds, and the error of another 8 hours of testing is 200 milliseconds

Neil.Macmullen
Posts: 11
Joined: Sun Mar 10, 2019 12:48 pm

Re: The esp32 timer drifted over half an hour in the course of 10 hours (in deep sleep). Is this normal?

Postby Neil.Macmullen » Wed Aug 11, 2021 11:26 am

If you need to avoid clock drift then you really need to use an external 32K crystal in your circuit. There are some dedicated APIs for this....

Code: Select all

rtc_clk_32k_enable(true);
rtc_clk_slow_freq_set(RTC_SLOW_FREQ_32K_XTAL);

Who is online

Users browsing this forum: No registered users and 133 guests