# FreeRTOS SW Timers inaccurate

**URL:** <https://forums.freertos.org/t/freertos-sw-timers-inaccurate/6968>\
**Category:** Kernel\
**Created:** [January 9, 2018, 3:16pm UTC](https://forums.freertos.org/t/freertos-sw-timers-inaccurate/6968 "2018-01-09T15:16:31Z")\
**Posts on this page:** 5\
**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:** [January 9, 2018, 3:16pm UTC](https://forums.freertos.org/t/freertos-sw-timers-inaccurate/6968/1 "2018-01-09T15:16:31Z")

</div>

**[smurali](https://sourceforge.net/u/smurali/)** wrote on [Tuesday, January 09, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/ade9a12b/#aae9):

We have been using FreeRTOS SW timers all this while for periods ranging from 10ms to 1 minute.  
Recently we added a timer for 5 minutes. This paritcular timer seems very inaccurate. It usually takes around 5 minutes 45 seconds to trigger the interrupt. Is there something that i am missing?

configTIMER\_TASK\_PRIORITY is 2

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [January 9, 2018, 3:23pm UTC](https://forums.freertos.org/t/freertos-sw-timers-inaccurate/6968/2 "2018-01-09T15:23:07Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, January 09, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/ade9a12b/#aae9/ef15):

> Is there something that i am missing?

Don’t know, as I don’t know what you have.

Which port are you using? Does the chip have a stable and accurate  
clock? Or is it using a lower accuracy internal resonator? Have you  
checked the accuracy of the clock and the tick frequency using a scope?  
Are you setting the tick frequency to something that can be achieved  
exactly, or are you using a slow low power clock and attempting a tick  
frequency that can’t actually be achieved exactly (considering rounding  
errors, etc.).

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [January 10, 2018, 11:37pm UTC](https://forums.freertos.org/t/freertos-sw-timers-inaccurate/6968/3 "2018-01-10T23:37:19Z")

</div>

**[smurali](https://sourceforge.net/u/smurali/)** wrote on [Wednesday, January 10, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/ade9a12b/#ac46):

We are using a port with 64MHz CPU clock which is stable. The configTICK\_RATE\_HZ is set 1000

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [February 15, 2018, 5:29am UTC](https://forums.freertos.org/t/freertos-sw-timers-inaccurate/6968/4 "2018-02-15T05:29:05Z")

</div>

**[smurali](https://sourceforge.net/u/smurali/)** wrote on [Thursday, February 15, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/ade9a12b/#7f2d):

Any updates?

---

<div class="post-metadata">

**Author:** ![htibosch](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/htibosch/32/62_2.png) [@htibosch](https://forums.freertos.org/u/htibosch)\
**Post date:** [February 19, 2018, 2:27am UTC](https://forums.freertos.org/t/freertos-sw-timers-inaccurate/6968/5 "2018-02-19T02:27:27Z")

</div>

**[heinbali01](https://sourceforge.net/u/heinbali01/)** wrote on [Monday, February 19, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/ade9a12b/#934a):

> We are using a port with 64MHz CPU clock which is stable.  
> The configTICK\_RATE\_HZ is set 1000

Richard asked you a lot more. The information he’s asking for is necessary to make a correct diagnosis.

These were his questions:

- Which port are you using?

Richard is asking what platform and CPU you are using ( and please be exact about this ).

- Does the chip have a stable and accurate clock?
- Or is it using a lower accuracy internal resonator?

The phrase “64MHz CPU clock which is stable” is not really convincing. Maybe the CPU gets 64 MHz, but oscillators are usually slower, like e.g. 8 or 12 MHz.  
Can you tell what component is generating the clock? What are it properties?  
Or does it run on an internal resonator?

- Have you checked the accuracy of the clock and the tick frequency using a scope?

Did you?  
I know that X-tals come in different qualities, just like resistors. Cheap resistors have a resistance of e.g. 22 K +/- 5%. The actual frequency of X-tals also varies from part to part.

- Are you setting the tick frequency to something that can be achieved exactly?
- Or are you using a slow low power clock and attempting a tick frequency that can’t actually be achieved exactly (considering rounding errors, etc.).

On some platforms and for some clocks, a frequency of exactly 1000 Hz can not be produced, at the best an approximation. You will have to check the reference of your CPU and look-up the timer that produces the FreeRTOS clock-tick. It has an input frequency ( which can be changed in some cases ), and it has a divisor. You will find a formula like:

```auto
    F-output = F-input / divisor

```

If the deviation can be explained and if is quite constant ( 5:45 in stead of 5:00 ), you may want to “calibrate” the clock and use a different frequency in your calculations ( E.g. 869 Hz ).
