Search code examples
freertos

How long is a "tick" in FreeRTOS?


For the functions xTaskGetTickCount() and xTaskGetTickCountFromISR(), the FreeRTOS documentation doesn't give any indication of what a "tick" is, or how long it is, or any links to where to find out.

Returns:

The count of ticks since vTaskStartScheduler was called.

What is a "tick" in FreeRTOS? How long is it?


Solution

  • Generally 1 ms, assuming configTICK_RATE_HZ is 1000 (Hz). But it depends on your settings.

    First found the answer in an archived thread at FreeRTOS forums:

    The tick frequency is set by configTICK_RATE_HZ in FreeRTOSConfig.h. FreeRTOSConfig.h settings are described here:

    http://www.freertos.org/a00110.html

    If you set configTICK_RATE_HZ to 1000 (1KHz), then a tick is 1ms (one one thousandth of a second). If you set configTICK_RATE_HZ to 100 (100Hz), then a tick is 10ms (one one hundredth of a second). Etc.

    And from the linked FreeRTOS doc:

    configTICK_RATE_HZ

    The frequency of the RTOS tick interrupt.

    The tick interrupt is used to measure time. Therefore a higher tick frequency means time can be measured to a higher resolution. However, a high tick frequency also means that the RTOS kernel will use more CPU time so be less efficient. (Emphasis added:)

    The RTOS demo applications all use a tick rate of 1000Hz.

    This is used to test the RTOS kernel and is higher than would normally be required.

    More than one task can share the same priority. The RTOS scheduler will share processor time between tasks of the same priority by switching between the tasks during each RTOS tick. A high tick rate frequency will therefore also have the effect of reducing the 'time slice' given to each task.