How to Set the RTOS Tick Rate Reasonably?

Follow+Star public account, don’t miss wonderful content

How to Set the RTOS Tick Rate Reasonably?

Author | strongerHuang
Public WeChat | Embedded Column
Recently, I have seen everyone discussing the topic of 【RTOS tick setting】…
In fact, for most scenarios, setting it to 1000 (1ms) is relatively reasonable and also a conventional value. Of course, some special situations may be different.

Here I share a platform for embedded recruitment information:

How to Set the RTOS Tick Rate Reasonably?

What is System Tick?

System Tick (SysTick), also known as clock pulse, system heartbeat, etc.
The operating system can switch between multiple tasks relying on a system timer to provide scheduling (context switching) through interrupts at a **frequency to achieve task switching.
How to Set the RTOS Tick Rate Reasonably?
And this timer is what we are talking about in this article, the system tick.
In earlier years, 51 and 430 microcontrollers running RTOS used a separate Timer to provide system ticks.
In consideration of running RTOS, the Cortex-M core comes with this system tick timer.
How to Set the RTOS Tick Rate Reasonably?
You will find that many microcontrollers on the market basically come with the SysTick timer, such as Cortex-M0, M3, M4 cores, and they can be used simply by calling the official API function.

System Configuration File

Usually, the system tick (OS_TICKS) is located in the system configuration file, configuring the system configuration file is also an important step. (Some systems are configured through a graphical interface, which is also a configuration of the system configuration file)
For example, FreeRTOSConfig.h
How to Set the RTOS Tick Rate Reasonably?
Also, the os_cfg.h of ucos system
How to Set the RTOS Tick Rate Reasonably?
OS_TICKS is generally configured to 1000, which is easy to understand from the macro definition and comments, representing the number of system ticks per second.
There are many configuration options here, beginners may not understand some of the options, and can use the official default configuration, and as they become familiar, they will naturally understand these configuration options.

How much should the system tick be configured?

Configuring the system tick to 1000 means that the system will perform a round-robin scheduling every 1ms to check if there are higher priority tasks to execute (and switch tasks).
What does 1ms mean?
You may think that 1ms is a very short time, but for the operating system, 1ms is quite a long time.
For a microcontroller with a 100M main frequency, executing a scheduling (dozens of statements) takes us-level time; how long do you think 1ms is for the system?
Why configure it to 1000?
Many people may have this question, why configure it to 1000, not 100, 10000, or 2000?
1000 is a relatively suitable medium value; other 100, 10000, or 2000 can also be used, but they are not conducive to the system and programming.
a. If the tick is too high, 10K or even 100K, it will put a heavy burden on the system. Because self-scheduling will occupy CPU time.
b. A 1ms tick is convenient for programming delay. Values like 2k or 10k are not convenient for calculations when using system delays.
vTaskDelay(1000);
If the tick value is 1000, it represents a delay of 1 second;
If the tick value is 2000, it represents a delay of 0.5 seconds, which is obviously not conducive to programming;
What impact does configuring to other values have?
Other than 1000, the only values that are convenient for delay calculations are 1, or 1M. (Obviously 1 or 1M are unrealistic)
Configuring to 1, the system only responds once every second, is this still called a real-time operating system?
Configuring to 1M, scheduling once every 1us, the CPU is basically doing scheduling work and not doing anything else.
Besides, 100, 10000, or 2000, while being inconvenient for delay calculations, in principle, they can also be used.

Summary

1. The SysTick of the real-time operating system should be configured to 1000 by default unless there are special circumstances;
2. In systems where it is allowed, the larger the value of SysTick, the higher the real-time performance of the system; conversely, the worse the real-time performance;
3. For processors with relatively low main frequencies (e.g., below 10M), the SysTick value can be appropriately configured as in the first point;
······
———— END ————
How to Set the RTOS Tick Rate Reasonably?
● Column “Embedded Tools”
● Column “Embedded Development”
● Column “Keil Tutorial”
● Selected Tutorials from Embedded Column
Follow the public account Reply “Join Group” to join the technical exchange group according to the rules, reply “1024” to see more content.
How to Set the RTOS Tick Rate Reasonably?
How to Set the RTOS Tick Rate Reasonably?
Click on “Read Original” to see more shares.

Leave a Comment

Your email address will not be published. Required fields are marked *