ESP-IDF V4.4.6 - Problems when using vTaskDelay with light sleep.
ESP-IDF V4.4.6 - Problems when using vTaskDelay with light sleep.
Greetings.
I'm currently programming an ESP32-WROVER-E module. I'm trying to use light sleep to reduce the module energy consumption. However, suppose that I have the main task, in which I call the function "esp_light_sleep_start()" after setting a timer wakeup with the function "esp_sleep_enable_timer_wakeup()", and this repeats every 1 second. Additionally, suppose that I have another task, in which I print some log and then call a "vTaskDelay()" of 10 seconds. The problem is that it seems that, while in light sleep, the ticks from FreeRTOS stop counting, so the secondary task doesn't run after 10 seconds, but much longer.
I've tried enabling the "CONFIG_FREERTOS_USE_TICKLESS_IDLE" configuration, but that only seem to work when using the "Power Management" functionality. I'm not using that functionality because, after some tests, I noticed that the energy consumption didn't drop as much as intended.
Any ideas on how can I achieve this? Thank you.
I'm currently programming an ESP32-WROVER-E module. I'm trying to use light sleep to reduce the module energy consumption. However, suppose that I have the main task, in which I call the function "esp_light_sleep_start()" after setting a timer wakeup with the function "esp_sleep_enable_timer_wakeup()", and this repeats every 1 second. Additionally, suppose that I have another task, in which I print some log and then call a "vTaskDelay()" of 10 seconds. The problem is that it seems that, while in light sleep, the ticks from FreeRTOS stop counting, so the secondary task doesn't run after 10 seconds, but much longer.
I've tried enabling the "CONFIG_FREERTOS_USE_TICKLESS_IDLE" configuration, but that only seem to work when using the "Power Management" functionality. I'm not using that functionality because, after some tests, I noticed that the energy consumption didn't drop as much as intended.
Any ideas on how can I achieve this? Thank you.
-
nopnop2002
- Posts: 362
- Joined: Thu Oct 03, 2019 10:52 pm
- Contact:
Re: ESP-IDF V4.4.6 - Problems when using vTaskDelay with light sleep.
The main task counts the number of times it has returned from sleep.
When it has returned from sleep 10 times, it uses a queue or similar to release the secondary task from waiting.
When it has returned from sleep 10 times, it uses a queue or similar to release the secondary task from waiting.
Re: ESP-IDF V4.4.6 - Problems when using vTaskDelay with light sleep.
Greetings.
Sorry, I didn't quite understand if what you said is a suggestion about what should I do to solve this issue, or a description of how ESP-IDF works regarding FreeRTOS's delays and ESP32 sleep mode.
In case that it was a suggestion, I would have to ask if there is no other way of solving this issue, because in my real application I have multiple tasks, not just 2, and if I have to control the use of every task from the main task, it will become very inefficient.
Thank you.
Sorry, I didn't quite understand if what you said is a suggestion about what should I do to solve this issue, or a description of how ESP-IDF works regarding FreeRTOS's delays and ESP32 sleep mode.
In case that it was a suggestion, I would have to ask if there is no other way of solving this issue, because in my real application I have multiple tasks, not just 2, and if I have to control the use of every task from the main task, it will become very inefficient.
Thank you.
Re: ESP-IDF V4.4.6 - Problems when using vTaskDelay with light sleep.
Enable Power Management and Tickless Idle. Do not manually use esp_sleep_enable_timer_wakeup() or esp_light_sleep_start(). That will allow you to delay tasks with light sleep.
If power consumption is higher than expected, that seems like a different problem.
If power consumption is higher than expected, that seems like a different problem.
Re: ESP-IDF V4.4.6 - Problems when using vTaskDelay with light sleep.
Greetings @boarchuz
Yes, I understand what you say, and I understand the funcionality of "Power Management". The problem that I have with it is the following. Suppose that I'm using PM and I have 20 tasks, all with their corresponding delays, each with different times. What will happen is, yes, the ESP32 will go to sleep when all task are blocked waiting for their corresponding delays to finish, but if you have, for example, that task 2 ends its delay 1 second after task 1, and task 3 1 second after task 2, and so on, the power consumption will be almost the same as if the ESP32 didn't go to sleep. Or at least that is what I've observed.
Having said that, what I wanted to do is use the manual sleep mode, lets say for 2 minutes, and when the ESP32 wakes up, run all the tasks that are in the ready state, not manually but automatically, schedule by the FreeRTOS system.
Maybe that's not the best approach, but I thought of that because, in the case that I want to achieve the same behaviour using PM, I would have to change some short delay tasks, for example, one that process reading from an external ADC, and for me that seemed to be the same as manually using the "light sleep".
Hope that was clear. In case it wasn't, please ask me for more information.
Thank you.
Yes, I understand what you say, and I understand the funcionality of "Power Management". The problem that I have with it is the following. Suppose that I'm using PM and I have 20 tasks, all with their corresponding delays, each with different times. What will happen is, yes, the ESP32 will go to sleep when all task are blocked waiting for their corresponding delays to finish, but if you have, for example, that task 2 ends its delay 1 second after task 1, and task 3 1 second after task 2, and so on, the power consumption will be almost the same as if the ESP32 didn't go to sleep. Or at least that is what I've observed.
Having said that, what I wanted to do is use the manual sleep mode, lets say for 2 minutes, and when the ESP32 wakes up, run all the tasks that are in the ready state, not manually but automatically, schedule by the FreeRTOS system.
Maybe that's not the best approach, but I thought of that because, in the case that I want to achieve the same behaviour using PM, I would have to change some short delay tasks, for example, one that process reading from an external ADC, and for me that seemed to be the same as manually using the "light sleep".
Hope that was clear. In case it wasn't, please ask me for more information.
Thank you.
Re: ESP-IDF V4.4.6 - Problems when using vTaskDelay with light sleep.
Oh I see, you want to synchronise tasks in order to maximise sleep time. You could use FreeRTOS functions to do so, or light sleep callbacks:
https://github.com/espressif/esp-idf/bl ... _pm.h#L244
https://github.com/espressif/esp-idf/bl ... _pm.h#L244
Re: ESP-IDF V4.4.6 - Problems when using vTaskDelay with light sleep.
Greetings @boarchuz
I see. Regarding those FreeRTOS functions, could you name any of them so I can look for more information?
Regarding light sleep callbacks, but those work in case I use Power Management, not with manual "light sleep", right? Or maybe I can use it with manual "light sleep" if I just enable the "CONFIG_FREERTOS_USE_TICKLESS_IDLE" config.
I see. Regarding those FreeRTOS functions, could you name any of them so I can look for more information?
Regarding light sleep callbacks, but those work in case I use Power Management, not with manual "light sleep", right? Or maybe I can use it with manual "light sleep" if I just enable the "CONFIG_FREERTOS_USE_TICKLESS_IDLE" config.
-
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.
You want multiple tasks to block until some other task 'tells them' to run; then you probably also want the 'controlling' task to wait for all other tasks to finish doing their thing before the system goes back to sleep.Regarding those FreeRTOS functions, could you name any of them so I can look for more information?
For this, you can basically use any of the FreeRTOS primitives, namely:
"Direct-to-task notifications", "Event groups", semaphores, or possibly even one or more queues.
-
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.
Sounds like you may actually be looking for a timer...... and I have 20 tasks, all with their corresponding delays, each with different times.
Try and determine if&where you need tasks, where the 'task' would actually better be implemented via a timer, and possibly an algorithm to schedule the tasks/timers while balancing each task's need for an individual wait time and the wish to execute tasks in 'bursts'.
And, btw, consider upgrading to a newer IDF version. v4.4 (and even v5.0) are already "EOL".
Re: ESP-IDF V4.4.6 - Problems when using vTaskDelay with light sleep.
Greetings @MicroController
Thank you.
I understand. 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, and then the ESP32 would go back to sleep again. But yes, maybe that's not feasible behaviour, and I would have to have a main task in which I use the manual "light sleep", and which runs after it has received a confirmation from all other tasks. Seems a bit complex, but not impossible. Or maybe I'm overthinking it, and it could be simpler.You want multiple tasks to block until some other task 'tells them' to run; then you probably also want the 'controlling' task to wait for all other tasks to finish doing their thing before the system goes back to sleep.
For this, you can basically use any of the FreeRTOS primitives, namely:
"Direct-to-task notifications", "Event groups", semaphores, or possibly even one or more queues.
In my case, I think that tasks are needed, because in that way I can separate different functionalities. For example, a task that gets readings from the external ADC, a task that send LoRaWAN packets to a server, etc. This is because I'm already using FreeRTOS, the use of timers would work better if I were using an "infinite loop" architecture.Sounds like you may actually be looking for a timer...
Try and determine if&where you need tasks, where the 'task' would actually better be implemented via a timer, and possibly an algorithm to schedule the tasks/timers while balancing each task's need for an individual wait time and the wish to execute tasks in 'bursts'.
Yes, I agree, but the problem is that, if I update the IDF version, a lot of functions provided by this IDF will change, and that will mean that I have to make corrections all over the firmware, which takes a considerable amount of time, so I'm waiting to have some free time to do that.And, btw, consider upgrading to a newer IDF version. v4.4 (and even v5.0) are already "EOL".
Thank you.
Who is online
Users browsing this forum: Qwantbot, Semrush [Bot] and 2 guests