Calibration of RTC on ESP32-S2

fabiuz7
Posts: 4
Joined: Fri Nov 01, 2019 6:52 pm

Calibration of RTC on ESP32-S2

Postby fabiuz7 » Sun Oct 25, 2020 9:45 pm

Hi,
I was testing ESP32-S2 WROOM module, and I was trying external RTC crystal to minimize the dependency on NTP and WiFi connection. Also, to save energy, the rtc will be used for a more accurate deep sleep time.

I had tested the gettimeofday() function with ONLY RTC source 90khz (internal RC) and then with my external RTC crystal (20ppm) at 20°C, CONFIG_ESP32S2_RTC_CLK_CAL_CYCLES = 576 (the default value) and CONFIG_ESP32S2_TIME_SYSCALL = RTC only.

The first test was very simple: sync once to NTP and then print the time on serial to observe the skew between ESP32-S2 and my laptop. I was expecting to see a great difference between the 2 config over 15 minute time span (i.e. some seconds of skew for RC since its error should range in +-5%, and almost 0sec skew for the external crystal. However, both the RTC performed very well and the skew was nearly 0.

Then I repeat the 2 configs setting CONFIG_ESP32S2_RTC_CLK_CAL_CYCLES = 0. In this case, I observed a great difference between RC and external crystal (many seconds of few vs almost 0). My question is: does external crystal have an advantage over RC if they can be equally calibrated? Of course, external crystal seems that it doesn't need the calibration so that the calibration time can be saved.

ESP_Sprite
Posts: 4106
Joined: Thu Nov 26, 2015 4:08 am

Re: Calibration of RTC on ESP32-S2

Postby ESP_Sprite » Mon Oct 26, 2020 12:43 am

Drift in the RC oscillator can happen because of two reasons: 'intrinsic' differences in the silicon the ESP32S2 is made of, and external influences like temperature and supply voltage changes and perhaps even age of the silicon. Calibration can correct for the first reason, but not for the second one. If you have a very stable power supply and the temperature of your silicon always is the same, RC may be 'good enough'; if not, you should expect some long-term drift.

fabiuz7
Posts: 4
Joined: Fri Nov 01, 2019 6:52 pm

Re: Calibration of RTC on ESP32-S2

Postby fabiuz7 » Mon Oct 26, 2020 9:17 pm

However the calibration is performed only at the start up, isn't it? Because if the operating temperature of the ESP32S2 varies the drift will vary accordingly, and calibration cannot compensate that.

fabiuz7
Posts: 4
Joined: Fri Nov 01, 2019 6:52 pm

Re: Calibration of RTC on ESP32-S2

Postby fabiuz7 » Tue Oct 27, 2020 8:01 pm

I had continued the testing of various configuration of RTC to get the accurate date.

the sketch I used is derived from the "sntp" esp-idf example and basically do the following:

Code: Select all

First iteration: sync time with NTP
print time
Deep sleep fom 15 seconds

Any other iteration:
print time
Deepsleep for 15 seconds
I observed the following behavior:
CONFIG_ESP32S2_TIME_SYSCALL = ESP32S2_TIME_SYSCALL_USE_RTC_FRC1 --> the gettimeofday heavily drift: 1 minute over 20 minutes
CONFIG_ESP32S2_TIME_SYSCALL = ESP32S2_TIME_SYSCALL_USE_RTC --> no measurable drift over 20 minutes

Other time-related params are kept constant:
CONFIG_ESP32S2_RTC_CLK_SRC = ESP32S2_RTC_CLK_SRC_EXT_CRYS
CONFIG_ESP32S2_RTC_CLK_CAL_CYCLES = 576

is it normal to get such a bad performance with ESP32S2_TIME_SYSCALL_USE_RTC_FRC1? If needed I can attach the full code.

Who is online

Users browsing this forum: ESP_Roland, Snedig and 32 guests