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:
@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)...
Jump to solution
4 Replies
Solution
Enthernet Code
Enthernet Code•4mo ago
@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)
#define HOUR_TICKS (3600000) // 1 hour in ticks

void vTaskFunction(void *pvParameters)
{
for (;;)
{
// Perform your task here


for (int i = 0; i < 6; i++)
{
vTaskDelay(HOUR_TICKS);
}
}
}
#define HOUR_TICKS (3600000) // 1 hour in ticks

void vTaskFunction(void *pvParameters)
{
for (;;)
{
// Perform your task here


for (int i = 0; i < 6; i++)
{
vTaskDelay(HOUR_TICKS);
}
}
}
youcef_ali
youcef_ali•4mo ago
thank you, what do you see the best approach using a task with delay or a timer ?
Enthernet Code
Enthernet Code•4mo ago
Timer as it has high precision and doesn't consume much resources thuo it might be hard to setup thuo
Jean Labrosse
Jean Labrosse•4mo ago
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.
Want results from more Discord servers?
Add your server