-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to configure sleep RTC calibration (IDFGH-12371) #13402
base: master
Are you sure you want to change the base?
Conversation
DarkZeros
commented
Mar 17, 2024
- The default behaviour is to run some calibration cycles to ensure RTC slow clock is vlaid during the sleep time.
- However, depending on the application this might be redundant or detrimental
- Added an option to configure it if required
* The default behaviour is to run some calibration cycles to ensure RTC slow clock is vlaid during the sleep time. * However, depending on the application this might be redundant or detrimental * Added an option to configure it if required # Conflicts: # components/esp_hw_support/sleep_modes.c
👋 Hello DarkZeros, we appreciate your contribution to this project! 📘 Please review the project's Contributions Guide for key guidelines on code, documentation, testing, and more. 🖊️ Please also make sure you have read and signed the Contributor License Agreement for this project. Click to see more instructions ...
Review and merge process you can expect ...
|
Thank you for your contribution!! But in fact we do not expect users to configure the number of calibration cycles each time they enter sleep. If the number of calibration cycles is too small, not all configuration values may be able to calibrate accurate frequency values. Of course, I have also noticed that too many calibrations in certain scenarios lead to too much overhead in and out of sleep. You could try configuring I think the best solution is to implement the global calibration service of rtc_timer. It is possible to automatically calibrate rtc_timer at regular intervals. I am trying to implement it (but the priority is not high). |
@esp-wzh Thanks for the reply. I understand that the current code has its value, this is why I left the defaults as before. My use case is an ultra low power display update code. The time is handled by external RTC (+interrupt), therefore exact slow RTC is non needed, and the extra calibration cycles in/out sleep is causing 2ms total extra time (around 4% total power usage). I think this might also be useful for cases where time accuracy is not critical. So it may be interesting for other people to set this to 0, or even higher values for long sleep time (ie: 1day sleep). But feel freeto take it or not. I have forked the IDF project for my case, so it is ok if it is not taken upstream. :) |
Yes, I understand the problem you encountered, and this solution is reasonable in your case. But what I am worried about is that when using the automatic sleep mode hosted by the esp_pm component (with FreeRTOS tickless idle enabled), there are certain requirements for the accuracy of the tick source provided by slow_clock. For example, freertos suppresses a 100ms ticks, butt if rtc_timer is particularly inaccurate, the chip sleeps for 101ms, so the events that need to be processed on the 100ms tick will be lost, and then FreeRTOS will crash. |
I won´t claim myself an expert in the ESP32 system. So take everything I say with caution. Therefore, if the chip goes to sleep for ie: 100ms, needs to calibrate the RTC clock to know 100ms how many ticks it means of the RTC clock. To set it to as-closer as possible to 100ms. So even if this is set to 0, a crash in RTOS I think is non possible, however it can cause a de-sync with other timers and external chips. However, in my case the assumptions are the other way around, the RTC clock is very very accurate. So calibrating it makes no sense, it always gives 16000000, and a fast calibration of just 10 cycles tipically gives a bad calibration of 15999980, ...and so on. |
Yes, you're right, I didn't think clearly. After discussion, we do not intend to solve this problem using the method in this PR. We would like to add an menuconfig option to configure the calibration interval (count in rtc_timer time instead the number of calibration times) for calibrating slow_clock. During the calibration request process, only when the time from the current moment to the last calibration time is greater than the configured threshold, the hardware will actually be called to calibrate, otherwise the previous calibration value will be returned. How do you think? If it's ok, we will complete it in the near future. |
That would definitely be a step forward, because it would not incur multiple calibrations that are redundant. I think in general, for RTC calibration it doesn´t really need to be a blocking process. |
@DarkZeros It's indeed a good suggestion. That's what I'm planning to do. We can add an new API After starting the calibration, the CPU can continue to run the code, and the RTC clock calibration module is calibrating in parallel at this time. When the program needs to use the calibration value, it calls the You are very thoughtful. The use of this pair of interfaces should have restrictions on the behavior between them. Actions that disrupt the calibration process are not allowed to occur. It should only be used in scenarios that have been strictly evaluated, but I think that at least in the current IDF sleep process, this solution can be used to improve the time overhead of entering and exiting sleep. |