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

FreeRTOS RTC Prescaler Produces Incorrect Time

In SDK 11 the FreeRTOS port has the following line is declared in portmacro_cmsis.h

#define portNRF_RTC_PRESCALER  ( (uint32_t) (ROUNDED_DIV(configSYSTICK_CLOCK_HZ, configTICK_RATE_HZ) - 1) )
In the above example configSYSTICK_CLOCK_HZ is 32.768kHZ and configTICK_RATE_HZ is 1.0kHz.

According to the nRF52 datasheet (section 25.2) the above prescaler calculation is correct. When I toggle an I/O to measure the timing I am getting ~973us, not 1.007ms as I would expect given the prescaler equation. If I remove the - 1 from the above define then I get an output of 1.007ms.

Thanks

  • Hi, I think the best now is to configure configTICK_RATE_HZ to 1024 and

    1. do NOT use portTICK_PERIOD_MS because configTICK_RATE_HZ > 1000 because this will make portTICK_PERIOD_MS = 0.

    2. You have to use pdMS_TO_TICKS because configTICK_RATE_HZ > 1000 and as the millisecond argument given increases then the accuracy becomes better.

    I am not sure if we can do anything about it as long as we use RTC for low power modes and with only integer prescalar values we can achieve limited tick frequencies.

    This for me looks more of a limitation with FreeRTOS to work with 32KHz oscillators with integral prescalars. Maybe @www.FreeRTOS.org can comment on it!?

Related