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.
Calibration of RTC on ESP32-S2
-
- Posts: 10
- Joined: Fri Nov 01, 2019 6:52 pm
- Location: Italy
- Contact:
Calibration of RTC on ESP32-S2
Find me on GitHub
-
- Posts: 9759
- Joined: Thu Nov 26, 2015 4:08 am
Re: Calibration of RTC on ESP32-S2
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.
-
- Posts: 10
- Joined: Fri Nov 01, 2019 6:52 pm
- Location: Italy
- Contact:
Re: Calibration of RTC on ESP32-S2
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.
Find me on GitHub
-
- Posts: 10
- Joined: Fri Nov 01, 2019 6:52 pm
- Location: Italy
- Contact:
Re: Calibration of RTC on ESP32-S2
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:
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.
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
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.
Find me on GitHub
Who is online
Users browsing this forum: Majestic-12 [Bot] and 158 guests