# pdMS\_TO\_TICKS() seems return the wrong result

**URL:** <https://forums.freertos.org/t/pdms-to-ticks-seems-return-the-wrong-result/21205>\
**Category:** Kernel\
**Created:** [August 14, 2024, 6:31pm UTC](https://forums.freertos.org/t/pdms-to-ticks-seems-return-the-wrong-result/21205 "2024-08-14T18:31:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pilot8](https://avatars.discourse-cdn.com/v4/letter/p/9d8465/32.png) [@Pilot8](https://forums.freertos.org/u/Pilot8)\
**Post date:** [August 14, 2024, 6:31pm UTC](https://forums.freertos.org/t/pdms-to-ticks-seems-return-the-wrong-result/21205/1 "2024-08-14T18:31:34Z")

</div>

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:

```auto
// 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

```auto
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!

---

<div class="post-metadata">

**Author:** ![richard-damon](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/richard-damon/32/38_2.png) [@richard-damon](https://forums.freertos.org/u/richard-damon)\
**Post date:** [August 14, 2024, 7:00pm UTC](https://forums.freertos.org/t/pdms-to-ticks-seems-return-the-wrong-result/21205/2 "2024-08-14T19:00:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Pilot8](https://avatars.discourse-cdn.com/v4/letter/p/9d8465/32.png) [@Pilot8](https://forums.freertos.org/u/Pilot8)\
**Post date:** [August 14, 2024, 9:02pm UTC](https://forums.freertos.org/t/pdms-to-ticks-seems-return-the-wrong-result/21205/3 "2024-08-14T21:02:50Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![kstribrn](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/kstribrn/32/2085_2.png) [@kstribrn](https://forums.freertos.org/u/kstribrn)\
**Post date:** [August 14, 2024, 9:17pm UTC](https://forums.freertos.org/t/pdms-to-ticks-seems-return-the-wrong-result/21205/4 "2024-08-14T21:17:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kstribrn](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/kstribrn/32/2085_2.png) [@kstribrn](https://forums.freertos.org/u/kstribrn)\
**Post date:** [August 14, 2024, 9:21pm UTC](https://forums.freertos.org/t/pdms-to-ticks-seems-return-the-wrong-result/21205/5 "2024-08-14T21:21:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Pilot8](https://avatars.discourse-cdn.com/v4/letter/p/9d8465/32.png) [@Pilot8](https://forums.freertos.org/u/Pilot8)\
**Post date:** [August 14, 2024, 10:48pm UTC](https://forums.freertos.org/t/pdms-to-ticks-seems-return-the-wrong-result/21205/6 "2024-08-14T22:48:46Z")

</div>

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