Calibration of RTC on ESP32-S2
Posted: 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.
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.