# Timer with a long response time problem

**URL:** <https://forums.freertos.org/t/timer-with-a-long-response-time-problem/22462>\
**Category:** Kernel\
**Created:** [February 3, 2025, 9:24am UTC](https://forums.freertos.org/t/timer-with-a-long-response-time-problem/22462 "2025-02-03T09:24:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![pistoletov1974](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/pistoletov1974/32/4554_2.png) [@pistoletov1974](https://forums.freertos.org/u/pistoletov1974)\
**Post date:** [February 3, 2025, 9:24am UTC](https://forums.freertos.org/t/timer-with-a-long-response-time-problem/22462/1 "2025-02-03T09:24:24Z")

</div>

HI,i need a timer with a one-time duration of 1.5 hours.once. Here is the initialization of the timer  
`reset_timer = xTimerCreate("RESET_TMR",pdMS_TO_TICKS(5400000UL),pdFALSE, (void*)0, (TimerCallbackFunction_t)reset_tmr_cb);`

configuration of ticks

```auto
#define configTICK_RATE_HZ ( ( TickType_t ) 1000 )
#define configUSE_16_BIT_TICKS 0

```

The problem is that the timer is triggered after 18 minutes and not after 90…What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![RAc](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rac/32/1389_2.png) [@RAc](https://forums.freertos.org/u/RAc)\
**Post date:** [February 3, 2025, 10:20am UTC](https://forums.freertos.org/t/timer-with-a-long-response-time-problem/22462/2 "2025-02-03T10:20:18Z")

</div>

does all of your other timing work as expected? For example, if you have a blinky app where you vTaskDelay() for one second between LED events, do you see ± 1 second blink intervals, or is that way off as well?

---

<div class="post-metadata">

**Author:** ![pistoletov1974](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/pistoletov1974/32/4554_2.png) [@pistoletov1974](https://forums.freertos.org/u/pistoletov1974)\
**Post date:** [February 3, 2025, 11:57am UTC](https://forums.freertos.org/t/timer-with-a-long-response-time-problem/22462/3 "2025-02-03T11:57:39Z")

</div>

Yes. All other timings in app (max 20 sec) works fine

---

<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:** [February 3, 2025, 12:23pm UTC](https://forums.freertos.org/t/timer-with-a-long-response-time-problem/22462/4 "2025-02-03T12:23:21Z")

</div>

1.5 hours overflows the interger mathematics in pdMS\_TO\_TICKS, as it will multiply the time by the tick rate, which will then exceed 2^32. The overflow point with a 1 ms/1000 Hz tick is about 1 hour 12 minutes, which is why you end up with 18 minutes.

Solutions:

1. specify your time (if over than an hour) as an “unsigned long long” with the ULL suffix

2. create a new conversion macro pdS\_TO\_TICKS for long delays that doesn’t divide the result by 1000, so you give the parameter as a smaller number.

3. look to see if you really need a 1 ms tick rate. In my experience most do not. It mostly is for “error” timeouts, which don’t need the accuracy, or polling loops which rarely need to be that fast or accurate. With even a 2 ms tick rate (500 Hz) your time won’t overflow.

4. If you know you are using 1 ms tick rate, then you don’t need to use pdMS\_TO\_TICKS, but can just pass the value in milli-seconds as the period.

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [February 3, 2025, 4:31pm UTC](https://forums.freertos.org/t/timer-with-a-long-response-time-problem/22462/5 "2025-02-03T16:31:15Z")

</div>

> [@richard-damon](#):
>
> Solutions:

If the port supports, you can also define `configTICK_TYPE_WIDTH_IN_BITS` to `TICK_TYPE_WIDTH_64_BITS` - [FreeRTOS-Kernel/portable/GCC/ARM\_CM4F/portmacro.h at main · FreeRTOS/FreeRTOS-Kernel · GitHub](https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/portable/GCC/ARM_CM4F/portmacro.h#L72).

---

<div class="post-metadata">

**Author:** ![maharvey](https://avatars.discourse-cdn.com/v4/letter/m/e95f7d/32.png) [@maharvey](https://forums.freertos.org/u/maharvey)\
**Post date:** [February 3, 2025, 7:32pm UTC](https://forums.freertos.org/t/timer-with-a-long-response-time-problem/22462/6 "2025-02-03T19:32:15Z")

</div>

One simple solution could be to setup a timer with a 1 minute expiration, and count 90 timer ticks. The overall current consumption (if resuming from sleep) overhead would be negligible, yet you would have a possible cancellation point every minute should you decide later that you no longer want the timer.

---

<div class="post-metadata">

**Author:** ![pistoletov1974](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/pistoletov1974/32/4554_2.png) [@pistoletov1974](https://forums.freertos.org/u/pistoletov1974)\
**Post date:** [February 4, 2025, 6:58am UTC](https://forums.freertos.org/t/timer-with-a-long-response-time-problem/22462/7 "2025-02-04T06:58:17Z")

</div>

Thanks for the reply. It was more important for me to understand what the reason was, I felt that there was an overflow somewhere, but I couldn’t figure out where. In my case, the solution is very simple - an hour’s delay is enough for me, or even since I don’t plan to change the tick time, I can do without this macro

```auto
reset_timer = xTimerCreate("RESET_TMR",5400000UL,pdFALSE, (void*)0, (TimerCallbackFunction_t)reset_tmr_cb);

```

. Now I will know this nuance in pdMS\_TP\_TICKS arithmetic.
