How to Implement a 6-Hour Delay in FreeRTOS Task?
I would like to know if i can do vtaskdelay of a period of 6 hours, what is the way to do it.
I have a task I wanted to be excuted eeach 6 hours whats is the best way to do it .?
Thanks
Solution:Jump to solution
@youcef_ali
vTaskDelay
takes the delay period in ticks, you need to convert the 6 hours into ticks based on your system's tick rate. Normally, u'll are to multiply the number of seconds in 6hours with your ticks per second which would result in a very high number and using large value isn't ideal so a better approach would be using a loop i.e 👇 (this is assuming ur tick is 1000/sec)
```c
#define HOUR_TICKS (3600000) // 1 hour in ticks
void vTaskFunction(void *pvParameters)...4 Replies
Solution
@youcef_ali
vTaskDelay
takes the delay period in ticks, you need to convert the 6 hours into ticks based on your system's tick rate. Normally, u'll are to multiply the number of seconds in 6hours with your ticks per second which would result in a very high number and using large value isn't ideal so a better approach would be using a loop i.e 👇 (this is assuming ur tick is 1000/sec)
thank you, what do you see the best approach using a task with delay or a timer ?
Timer as it has high precision and doesn't consume much resources thuo it might be hard to setup thuo
Why the loop? Assuming a 32-bit int, why not (6 * HOUR_TICKS)??
That being said, a 6 Hour delay might not be the best use for a task! … but if you do use a task, i assume it’s a very low priority one (i.e.) just higher than the idle task.
I would prefer having a way to check that the task is still running, right now, it it’s not, you have to wait 6 hours or more to find out.