# Change Timer Tick of RTOS - ThreadX

This question is specifically targeted to a RTOS -- ThreadX.

We are using it for our project. Problem with this is default RTOS tick time is 10ms which is very high. We need to change it to 1ms.

Has anyone used this RTOS?

• ThreadX's a commercial product, I'd expect the vendor's support to be the best place to ask :) Why is the tick period important for you? Is it timer resolution you're concerned about, or preemption? – Code Painters Apr 20 '11 at 14:07
• @Czajnik I want to change it because Thread_Sleep(1) will yeild sleep of 10ms.... I want a thread_sleep of 1ms to speed up the process. – Swanand Apr 21 '11 at 4:34

From what I can tell from the PPT you linked, you are responsible for setting up the hardware timer that generates the tick interrupt and therefore you can set it to whatever value you like. My primary reference is slide 66 in the PPT which says:

The System Tick Rate is set with #define
BSP_TICKS_PER_SECOND which defaults to 100

But chaning the #define won't change the period - altering the period register for the timer you're using will. Once you do that you'll have to change the #define to keep it consisten with the new period.

Tick time depends on how many threads you want to execute and at what frequency. If you keep the tick time to 1mS make sure all the threads will execute in the defined tick time else you may have to place tx_sleep() in all high priority tasks so that low priority tasks get a chance to execute.

So you may have to synchronize your tasks accordingly by either events/semaphores and tx_sleep() calls.

• Using sleep should be a tactic of last resort. 99% of all tasks should be designed such that at the top of the loop the task is pending for an event of some sort (a resource is available, an interrupt has occurred, a message has be placed in a queue, etc). The rest of the loop should process the event, take appropriate action, and pending again. Sleeping in a high-priority task is usually a terrible practice because these tasks should execute very quickly according to Rate Monotonic Scheduling. Sleeping will take it out of the ready-to-run queue and you can miss processing important events. – Erik Jun 9 '11 at 19:57
• @Eric: Thanks for pointing out about the sleep(). swanand: Its always better to avoid using sleep to suspend a high priority tasks. As you can set to sleep as minimum as 1tick and that would suspend the highest priority task for complete 1tick time. – Sai Jun 10 '11 at 16:42

You need to go to tx_initialize_low_level.s, and in line 56 change 100 to 1000 to set SYSYTICK_CYCLES to 1000MHz (1 tick = 1 ms).

Edit: Don't forget to recompile the ThreadX project and put the new library instead of the old one your project has been using, otherwise the changes won't be made!