# xTaskGetTickCount() resolution to microseconds

**URL:** <https://forums.freertos.org/t/xtaskgettickcount-resolution-to-microseconds/15263>\
**Category:** Kernel\
**Created:** [June 14, 2022, 11:19am UTC](https://forums.freertos.org/t/xtaskgettickcount-resolution-to-microseconds/15263 "2022-06-14T11:19:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![traveler86](https://avatars.discourse-cdn.com/v4/letter/t/ad7895/32.png) [@traveler86](https://forums.freertos.org/u/traveler86)\
**Post date:** [June 14, 2022, 11:19am UTC](https://forums.freertos.org/t/xtaskgettickcount-resolution-to-microseconds/15263/1 "2022-06-14T11:19:28Z")

</div>

Hello,

I want to use the xTaskGetTickCount() function to get the time in microseconds.

I know that by using:

xTaskGetTickCount() \* portTICK\_PERIOD\_MS;

whereby

#define portTICK\_PERIOD\_MS ( ( TickType\_t ) 1000 / configTICK\_RATE\_HZ )

I can get the time in milliseconds. What is the best way to have the resolution in microseconds?  
I didn’t found any examples up to now

Thankful for any suggestion!

---

<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:** [June 14, 2022, 11:33am UTC](https://forums.freertos.org/t/xtaskgettickcount-resolution-to-microseconds/15263/2 "2022-06-14T11:33:06Z")

</div>

You could just multiply the number by 1000 to get it in microseconds, but that doesn’t improve the accuracy of the value.

Basically, you need to read a higher speed counter to get more resolution, and that would be port-specific. You could look at the performance counter code for an example, may processors have a counter that runs at the instruction rate, or have timer peripherals that can run at a specified rate that can give you this information.

---

<div class="post-metadata">

**Author:** ![traveler86](https://avatars.discourse-cdn.com/v4/letter/t/ad7895/32.png) [@traveler86](https://forums.freertos.org/u/traveler86)\
**Post date:** [June 14, 2022, 11:42am UTC](https://forums.freertos.org/t/xtaskgettickcount-resolution-to-microseconds/15263/3 "2022-06-14T11:42:59Z")

</div>

Thanks for answering. You mean (the not accurate way) just:

xTaskGetTickCount() \* 1000?

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [June 14, 2022, 11:57am UTC](https://forums.freertos.org/t/xtaskgettickcount-resolution-to-microseconds/15263/4 "2022-06-14T11:57:37Z")

</div>

Richard means `xTaskGetTickCount() * portTICK_PERIOD_MS * 1000`

---

<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:** [June 14, 2022, 2:53pm UTC](https://forums.freertos.org/t/xtaskgettickcount-resolution-to-microseconds/15263/5 "2022-06-14T14:53:54Z")

</div>

Yes, xTaskGetTickCount can’t have more **accuracy** then the tick, but you can give it as much **resolution** as you want. To get more real accuracy, you need to use a faster counter, the availability of which is very processor specific.

---

<div class="post-metadata">

**Author:** ![kanherea](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/kanherea/32/4106_2.png) [@kanherea](https://forums.freertos.org/u/kanherea)\
**Post date:** [June 14, 2022, 6:14pm UTC](https://forums.freertos.org/t/xtaskgettickcount-resolution-to-microseconds/15263/6 "2022-06-14T18:14:29Z")

</div>

Yes, I concur with @richard-damon. You should use a hardware specific counter/timer to get more resolution than the tick count.  
In essence:  
TO-DO:

- Use a hardware timer/counter specific to your processor. Such details can be found in the data-sheet/reference-manual of the MCU.

Not TO-DO:

- Don’t increase the frequency of the tick count too much (think tick count every microsecond). This will most probably be too much for a small processor and context switching overhead will also reduce the performance.
