Configure Clock and Tick Rate

A real-time operating system (RTOS) uses a system tick which is the time unit the timers are based on. FreeRTOS uses the microcontroller's TCB0 timer to generate its own tick interrupt. The FreeRTOS kernel measures the time using the tick, and every time a tick occurs, the scheduler checks if a task should be woken up or unblocked.

The configCPU_CLOCK_HZ define must be configured for the FreeRTOS timings to be correct. The frequency of the TCB0 clock should be entered here. The TCB0 will by default operate at the same clock frequency as the CPU for the devices listed in the “Relevant Devices” section.

The configTICK_RATE_HZ is used to determine the frequency of the RTOS tick interrupt. The tick rate should not be set too high compared to the CPU frequency as there will be some CPU overhead every time the tick occurs.

If more than one task has the same priority, the RTOS scheduler will switch between these tasks at every tick if configUSE_TIME_SLICING is set to 1. Using a higher tick rate will, therefore, cause the CPU time for each task to be smaller. For example, if a tick rate of 1000 Hz is used, the time slice for each task will be T=1/f=1/1000 Hz, which is 1 ms.