How should I decide appropriate Tick time configTICK_RATE_HZ in RTOS project?
In STM32F4 project, I am using FreeRTOS. I am at initial phase of defining firmware design, I figured out there will be approximately 20-25 RTOS tasks running. FreeRTOS comes with default 1ms tick time which can be configured. So, on what basis should I decide appropriate Tick time for my system.
Solution:Jump to solution
As @Marvee Amasi and @techielew mentioned, you can consider so many things like the required level of real-time precision, power consumption, context switching overhead, and so on. But in most of the system, all tasks do not need a high level of time precision, and even its not just depend on tick but on overall firmware design, So I will suggest you to consider below things for your tick calculation and overall design.
- Calculate approximate execution time of each task in milliseconds. If you have one/two time wise lengthy tasks with respect to execution time, please ignore them for Tick calculation.
- Determine maximum acceptable latency for each task.
- Trade off Tick time between least acceptable latency and the execution time of maximum number of tasks....
6 Replies
It's really just about finding a balance that meets your system's timing needs without creating unnecessary processing overhead. What I mean is that you should choose the tick time in your FreeRTOS system based on how quickly your tasks need to run. Okay now let's say if your tasks require fast response times, use a shorter tick time. If your tasks can have longer intervals, a longer tick time may be suitable. That's really how you could decide the correct "Tick time" for your system.
Once you set the tick, that's the interrupt interval system-wide, so as @Marvee Amasi says you need to configure the tick to the fastest period required to measure each of your 20-25 tasks.
Solution
As @Marvee Amasi and @techielew mentioned, you can consider so many things like the required level of real-time precision, power consumption, context switching overhead, and so on. But in most of the system, all tasks do not need a high level of time precision, and even its not just depend on tick but on overall firmware design, So I will suggest you to consider below things for your tick calculation and overall design.
- Calculate approximate execution time of each task in milliseconds. If you have one/two time wise lengthy tasks with respect to execution time, please ignore them for Tick calculation.
- Determine maximum acceptable latency for each task.
- Trade off Tick time between least acceptable latency and the execution time of maximum number of tasks.
- Try to keep high priority task’s execution time short. wherever possible use event based blocking. So the CPU will have more idle time. It increases responsiveness.
- I assume pre-emption is enabled as it is in FreeRTOS default configurations .
If you don’t want to do this all, keep Tick of 10 ms, and observe your system for responsiveness and performance. As per my experience 10 ms is a well balanced tick for most of the RTOS applications.
Thanks for detailed response. Its really helpful.
You are welcome
i think it is also worth noting that when you set the tick time 1ms, the software timer resolution is 1ms. if your application needs <1ms timer you can use hardware timer or reduce the tick resolution.