# timer

**URL:** <https://forums.freertos.org/t/timer/1803>\
**Category:** Kernel\
**Created:** [June 14, 2007, 6:05am UTC](https://forums.freertos.org/t/timer/1803 "2007-06-14T06:05:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [June 14, 2007, 6:05am UTC](https://forums.freertos.org/t/timer/1803/1 "2007-06-14T06:05:34Z")

</div>

**[panj](https://sourceforge.net/u/panj/)** wrote on [Thursday, June 14, 2007](https://sourceforge.net/p/freertos/discussion/382005/thread/50eebf4a/#e8ea):

Is FreeRTOS giving Timer functionality?

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [June 14, 2007, 7:49am UTC](https://forums.freertos.org/t/timer/1803/2 "2007-06-14T07:49:35Z")

</div>

**[sotd](https://sourceforge.net/u/sotd/)** wrote on [Thursday, June 14, 2007](https://sourceforge.net/p/freertos/discussion/382005/thread/50eebf4a/#e8ea/2766):

Not directly but you can easily use the tick hook to implement timers.&nbsp; The timer implementation of most RTOSs is hopelessly inefficient, decrementing timer counts on each interrupt.&nbsp; All you need to do is count ticks within the tick hook then call your ‘timer’ function directly at the right time.&nbsp; If you need multiple timer functions to fire at various rates then a common technique is to use a switch statement:

void vApplicationTickHook( void )  
{  
unsigned int Time:

\_\_\_\_Time++;

\_\_\_\_switch( Time )  
\_\_\_\_{  
\_\_\_\_\_\_\_\_case 50: RunTimerFunction1();  
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_break;  
\_\_\_\_\_\_\_\_case 100: RunTimerFunction1();  
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_RunTimerFunction2();  
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_Time = 0;  
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_break;  
\_\_\_\_}  
}

This is a very simple example that can be expanded for more complex cases, but shows RunTimerFunction1() being called every 50 ticks and RunTimerFunction2() being called every 100 ticks.&nbsp; This is much more efficient way of doing it in time and code size.
