# Some tasks stop running after some time

**URL:** <https://forums.freertos.org/t/some-tasks-stop-running-after-some-time/18362>\
**Category:** Kernel\
**Created:** [October 19, 2023, 1:23pm UTC](https://forums.freertos.org/t/some-tasks-stop-running-after-some-time/18362 "2023-10-19T13:23:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zak](https://avatars.discourse-cdn.com/v4/letter/z/8e7dd6/32.png) [@Zak](https://forums.freertos.org/u/Zak)\
**Post date:** [October 19, 2023, 1:23pm UTC](https://forums.freertos.org/t/some-tasks-stop-running-after-some-time/18362/1 "2023-10-19T13:23:59Z")

</div>

Hello, i have created a freeRtos project for s32k142 (cortex m4), and it is working, all the tasks that i have seems to be working, but after some time some of them will not work.  
I debugged the task that is not working and it seems like “xTaskGetTickCount” doesn’t give correct tick value

---

<div class="post-metadata">

**Author:** ![ActoryOu](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/actoryou/32/2880_2.png) [@ActoryOu](https://forums.freertos.org/u/ActoryOu)\
**Post date:** [October 20, 2023, 3:37am UTC](https://forums.freertos.org/t/some-tasks-stop-running-after-some-time/18362/2 "2023-10-20T03:37:23Z")

</div>

Hi @Zak,  
The information seems not enough to provide any suggestion. Could you help to elaborate more about what you’re doing and what you’ve done for debugging?

BTW, are [configASSERT](https://www.freertos.org/a00110.html#configASSERT) and [Stack overflow detection](https://www.freertos.org/Stacks-and-stack-overflow-checking.html) enabled in your project?

Thanks.

---

<div class="post-metadata">

**Author:** ![Zak](https://avatars.discourse-cdn.com/v4/letter/z/8e7dd6/32.png) [@Zak](https://forums.freertos.org/u/Zak)\
**Post date:** [October 20, 2023, 8:28am UTC](https://forums.freertos.org/t/some-tasks-stop-running-after-some-time/18362/3 "2023-10-20T08:28:50Z")

</div>

Hello, here is some detail  
okey this is part of my function from the task which is causing the problem

![image](https://d2v6vdsk2p900z.cloudfront.net/original/2X/e/e1c5bfca43a86578c549ef3717da550f97661a38.png)

so at the beginning the value xTickCountTx will be zero, and it will be incremented by the time. on the other hand “ctx-\>List[i].timeout” will be incremented by 50 ( 0 → 50 → 100 → 150 → …) whenever this condition “if( xTickCountTx \>= ctx-\>List[i].timeout )” is correct.

once both “xTickCountTx” and “ctx-\>List[i].timeout” reach 65500 this will happen:  
ctx-\>List[i].timeout = 65550, for all the time.  
xTickCountTx will never reach 65550, it will increment slightly and sometimes even decrement to some lower values (35279, 20048, 11570 etc …).

---

<div class="post-metadata">

**Author:** ![ActoryOu](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/actoryou/32/2880_2.png) [@ActoryOu](https://forums.freertos.org/u/ActoryOu)\
**Post date:** [October 20, 2023, 8:53am UTC](https://forums.freertos.org/t/some-tasks-stop-running-after-some-time/18362/4 "2023-10-20T08:53:35Z")

</div>

May I know `configUSE_16_BIT_TICKS` in your FreeRTOS\_Config.h and `TickType_t` in portmacro.h?  
It’s possible that `xTaskGetTickCount()` returns 16 bits so it never reaches 65550.

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:** [October 20, 2023, 9:45am UTC](https://forums.freertos.org/t/some-tasks-stop-running-after-some-time/18362/5 "2023-10-20T09:45:27Z")

</div>

One thing more to watch out for, unless you can be SURE that this gets run EVERY tick, there is a possibility that the tick counter will just pass your value, so an equality test can be dangerous,

Also, you need to make sure your variables are 32-bit values, as with a 16-bit values 65550 isn’t representable, but is actually just 14 after wrapping.

xTickCountTx is 32-bits, but is the timeout member also 32-bit?

---

<div class="post-metadata">

**Author:** ![Zak](https://avatars.discourse-cdn.com/v4/letter/z/8e7dd6/32.png) [@Zak](https://forums.freertos.org/u/Zak)\
**Post date:** [October 20, 2023, 11:06am UTC](https://forums.freertos.org/t/some-tasks-stop-running-after-some-time/18362/6 "2023-10-20T11:06:10Z")

</div>

Hello, thank you all for your support, yes it was because of the tick\_type is defined as uint16\_t
