How to Set the RTOS Tick in Embedded Development?

How to Set the RTOS Tick in Embedded Development?

Recently, a reader asked this question: Why is the default configuration of the RTOS system tick (Tick) 1000? Can I set it to 100, 10000, or 2000?
Many beginners have this question, including myself when I first learned about RTOS. I was confused about the different values for tick configuration and their impacts.
Today, let’s briefly discuss the RTOS system tick!

What is a System Tick?

A system tick (SysTick), also known as a clock pulse or system heartbeat in some contexts.

The operating system can switch between multiple tasks relying on a system timer to **interrupt at a frequency to provide scheduling (context switching) for task switching.

How to Set the RTOS Tick in Embedded Development?

This timer is what we refer to as the system tick.

In earlier years, 51 and 430 microcontrollers running RTOS used a separate Timer to provide the system tick.

To address the RTOS issue, the Cortex-M core comes with a built-in system tick timer.

How to Set the RTOS Tick in Embedded Development?

You will find that many microcontrollers on the market basically come with the SysTick timer, such as those with Cortex-M0, M3, and M4 cores, and they can be easily used by calling the official API functions.

System Configuration File

Typically, the system tick (OS_TICKS) is located in the system configuration file, and configuring this file is also an important step. (Some systems configure it through a graphical interface, which essentially configures the system configuration file)

For example, FreeRTOSConfig.h

How to Set the RTOS Tick in Embedded Development?

Another example is the ucos system’s os_cfg.h

How to Set the RTOS Tick in Embedded Development?

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, and beginners may not understand the meaning of some options. It’s fine to use the official default configuration, and as you become more familiar, these options will become clear.

What is the Appropriate System Tick Configuration?

Setting the system tick to 1000 means that the system performs a round-robin scheduling every 1ms to check if there are higher priority tasks to execute (and switch tasks).

What does 1ms mean?

You might think that 1ms is a very short time, but for an operating system, 1ms is actually quite long.

For a microcontroller with a 100M main frequency, executing a scheduling operation (dozens of instructions) takes place in the microsecond level. So how long is 1ms for the system?

Why is it configured to 1000?

Many people may have this question: why set it to 1000 instead of 100, 10000, or 2000?

1000 is a relatively suitable medium value. Other values like 100, 10000, or 2000 can also work, but they are not beneficial for the system and programming.

a. If the tick is too high, like 10K or even 100K, it places a significant burden on the system because the scheduling itself consumes CPU time.

b. A 1ms tick is convenient for programming delays. Values like 2k or 10k make delay calculations inconvenient.

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 clearly not favorable for programming;

What is the Impact of Configuring Other Values?

Besides 1000, the only other values that make delay calculations convenient are 1 or 1M. (Clearly1 or 1M are not realistic)

Configuring to 1 means the system only responds once per second; is that still considered a real-time operating system?

Configuring to 1M means scheduling occurs every 1us, and the CPU is essentially only doing scheduling work, leaving no time for anything else.

Aside from that, values like 100, 10000, or 2000 are still possible, but they make delay calculations inconvenient.

Summary

1. For real-time operating systems, the SysTick is best set to the default value of 1000 unless there are special circumstances;

2. In systems where allowed, a higher SysTick value enhances real-time performance; conversely, a lower value degrades it;

3. For processors with relatively low main frequencies (e.g., below 10M), the SysTick value can be adjusted appropriately according to the first point.

How to Set the RTOS Tick in Embedded Development?

How to Set the RTOS Tick in Embedded Development?

1. What is a 0 Ohm resistor?

2. Enums that stump C language experts

3. RISC-V is taking action to avoid MIPS-like fragmentation

4. How do MCUs with different voltage levels communicate?

5. Why don’t microcontroller programs often use malloc, while PCs frequently do?

6. C/C++ coding standards have many valuable references!

How to Set the RTOS Tick in Embedded Development?

Disclaimer: This article is a network reprint, and the copyright belongs to the original author. If there are any copyright issues, please contact us, and we will confirm copyright based on the materials you provide and either pay for the manuscript or delete the content.

Leave a Comment