This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Millisecond counter in case of FreeRTOS usage

I have as starting point the HRS FreeRTOS app. Now I want to add a millisecond counter. But from what I read I'm a little bit confused.

Can someone tell me what's the best route to do.

a) In FreeRTOS you can get a tick count with xTaskGetTickCount. Is the the best route? And how to convert it then to milliseconds because the configTICK_RATE_HZ is set to 1024 in the HRS example?

OR

b) Is is wise to use the app_timer_cnt_get() from the app_timer library? If that's the case do I still need to app_timer_create() and app_timer_start() to use the app_timer_cnt_get()? And how to convert that result to milliseconds? I guess it's linked tot the FreeRTOS timer.

  • Hello,

     

    In FreeRTOS you can get a tick count with xTaskGetTickCount. Is the the best route? And how to convert it then to milliseconds because the configTICK_RATE_HZ is set to 1024 in the HRS example?

     One second is 1024 ticks, so 1 ms = ticks/1024*1000. 

    Look at the definition of APP_TIMER_TICKS in app_timer.h for inspiration on how you can implement this calculation. 

    Perhaps:

    PASSED_MS(TICKS) (uint32_t)ROUNDED_DIV((TICKS)*1000,configTICK_RATE_HZ)

    The same applies for b), except that the tick rate is different. The app timer is running at 32768Hz. 

    BR,

    Edvin

Related