The "High Resolution Timer" can do that for you (with light sleep)...The behaviour that I wanted to achieve was, for example, lets say that one task goes on a delay of 5 secs, and another task on a delay of 10 secs, and the ESP32 goes to sleep for 20 secs, when the ESP32 wakes up, given that 20 secs have passed, these 2 tasks should run automatically, schedule by the FreeRTOS,
ESP-IDF V4.4.6 - Problems when using vTaskDelay with light sleep.
-
MicroController
- Posts: 2705
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: ESP-IDF V4.4.6 - Problems when using vTaskDelay with light sleep.
Re: ESP-IDF V4.4.6 - Problems when using vTaskDelay with light sleep.
Greetings @MicroController
Thank you.
I see. So, if I understand your suggestion, what should I do is set a HRT for each task in replace of the "vTaskDelay()", and then use the callbacks of those timers to run the corresponding tasks when the ESP32 wakes up. Is this correct?The "High Resolution Timer" can do that for you (with light sleep)...
Thank you.
-
MicroController
- Posts: 2705
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: ESP-IDF V4.4.6 - Problems when using vTaskDelay with light sleep.
Yes, that'd be my suggestion. (Though not necessarily creating/running actual tasks from the timer.)
In general, when you have 'short' activities which you want to perform at some predefined time, timers are often what you need.
On the other hand, tasks normally do longer-running stuff; specifically, most tasks are implemented as infinite loops, rarely if ever exiting.
As I said before, if you can define the algorithm to decide when to run an activity vs. when to sleep, i.e. who decides when what should run, other/better solutions may become apparent.
I guess the reason why what you describe may not be too trivial to implement is in this unusual in-between constellation where tasks should decide individually when/for how long to pause, but some other entity then should potentially make a different decision on behalf of the tasks. To me, this hints at some still 'hidden' concept behind the requirement uncovering which would lead to the right solution.
So the basic question is:
Who is actually in charge of delaying activities/tasks?
Maybe think about it like the FreeRTOS "ticks": If you define, say, that the chip should wake up (at most) every 10 seconds, then that's the 'tick rate', and tasks can request to be run/woken up X 10-second-ticks in the future.
In general, when you have 'short' activities which you want to perform at some predefined time, timers are often what you need.
On the other hand, tasks normally do longer-running stuff; specifically, most tasks are implemented as infinite loops, rarely if ever exiting.
As I said before, if you can define the algorithm to decide when to run an activity vs. when to sleep, i.e. who decides when what should run, other/better solutions may become apparent.
I guess the reason why what you describe may not be too trivial to implement is in this unusual in-between constellation where tasks should decide individually when/for how long to pause, but some other entity then should potentially make a different decision on behalf of the tasks. To me, this hints at some still 'hidden' concept behind the requirement uncovering which would lead to the right solution.
So the basic question is:
Who is actually in charge of delaying activities/tasks?
Maybe think about it like the FreeRTOS "ticks": If you define, say, that the chip should wake up (at most) every 10 seconds, then that's the 'tick rate', and tasks can request to be run/woken up X 10-second-ticks in the future.
Last edited by MicroController on Tue Jun 24, 2025 7:42 pm, edited 1 time in total.
Re: ESP-IDF V4.4.6 - Problems when using vTaskDelay with light sleep.
Greetings @MicroController
Yes, I understand. My only doubt about that approach is if tasks can be set as a callback for the timer. I'm guessing that they can't, so I'll have to implement an algoritm combining maybe task notifications and a central task that yields control to the other tasks. A bit complex, but worth it if that helps in reducing power consumption, as the device in which I plan to run this firmware is powered by a battery, charged by a tiny solar panel. Thank you for your suggestions.
I'll keep the post open, in case that there's another suggestion.
Yes, I understand. My only doubt about that approach is if tasks can be set as a callback for the timer. I'm guessing that they can't, so I'll have to implement an algoritm combining maybe task notifications and a central task that yields control to the other tasks. A bit complex, but worth it if that helps in reducing power consumption, as the device in which I plan to run this firmware is powered by a battery, charged by a tiny solar panel. Thank you for your suggestions.
I'll keep the post open, in case that there's another suggestion.
-
MicroController
- Posts: 2705
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: ESP-IDF V4.4.6 - Problems when using vTaskDelay with light sleep.
Of course, you can 'interact' with FreeRTOS tasks from the timer callback directly, e.g. sending notifications.

I'm sure you willI'll keep the post open, in case that there's another suggestion.
Who is online
Users browsing this forum: Qwantbot, Semrush [Bot] and 2 guests