pdMS_TO_TICKS() seems return the wrong result

We use Renesas RA6M5 MCU. I’m trying to figure out how pdMS_TO_TICKS() works. The MCU frequency is 100MHz. From the following code, the pdMS_TO_TICKS() is:

// FreeRTOSConfig.h
#ifndef configTICK_RATE_HZ
#define configTICK_RATE_HZ (1000)
#endif

// Renesas\aws\amazon-freertos\freertos_kernel\include\projdefs.h
#define pdMS_TO_TICKS( xTimeInMs )    ( ( TickType_t ) ( ( ( TickType_t ) ( xTimeInMs ) * ( TickType_t ) configTICK_RATE_HZ ) / ( TickType_t ) 1000U ) )

Suppose I need to get the ticks for 1 second. The code is

TickType_t xMaxBlockTicks = pdMS_TO_TICKS(1000);

The result of xMaxBlockTicks is 1000. I recall the typical tick is about ~10ms in most of the RTOS. If that’s the case, the xMaxBlockTicks should be 100. But it is 1000. Is it correct? Should I adjust configTICK_RATE_HZ to ensure the ticks for 1 second is 100 ticks?

Thanks!

configTICK_RATE_HZ defines the tick rate that the system will be setup for, and as you say, 1000 is probably faster than most systems need, but what some people use because that makes the tick a milli-second so no conversion needed, and that is what a lot of the demo system use to be stressing the system.

Thanks Richard.
Does it mean I should use the result 1000 which is from pdMS_TO_TICKS(1000)? I don’t have to change anything, correct?

Frequency is the inverse of period. So if you want to to block for 1 second and your tick frequency is 1kHz (aka 1000 times per second) then you’ll want to block for 1000 ticks. This is because the period of each tick is 1/1000 seconds or 0.001s or 1ms.

You can always slow down your frequency to 100 ticks per second (aka 100 Hz). If you do this the call to pdMS_TO_TICKS(1000) will give you the answer of 100. That is, it will take 100 ticks to delay for the second at that frequency.

1 Like

An important thing to keep in mind here is that the FreeRTOS tick and your MCU’s clock cycle are actually separate things. The MCU frequency is related to your hardware. The FreeRTOS tick frequency is more of a logical (aka software) choice.

The simple rule is that your MCU frequency needs to be much greater than the FreeRTOS tick frequency.

Thanks Kody. I appreciate it.
This well explains it!