How to compensate for the time it takes to run the task in VtaskDelay
Posted: Fri Oct 29, 2021 8:52 am
Hello. I have a complicated task running on my ESP32 device. I would like this task to repeat itself every 2 seconds.
I have set vTaskDelay(2000/portTICK_RATE_MS); at the end of the task but realised that this is not exactly what I need.
Since my task takes approximately 0.1 seconds to run and the vtaskDelay is set to 2 seconds, that means that the next time this task will be scheduled after 2.1 seconds which is not what I want. I want it to be 2 seconds regardless of how long the task took to execute.
For example my task execution time may vary from 0.15s to 0.05s and I want to compensate. Please suggest the most appropriate way to handle that.
I have set vTaskDelay(2000/portTICK_RATE_MS); at the end of the task but realised that this is not exactly what I need.
Since my task takes approximately 0.1 seconds to run and the vtaskDelay is set to 2 seconds, that means that the next time this task will be scheduled after 2.1 seconds which is not what I want. I want it to be 2 seconds regardless of how long the task took to execute.
For example my task execution time may vary from 0.15s to 0.05s and I want to compensate. Please suggest the most appropriate way to handle that.