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

RTX timer too slow / too fast

I'm using RTX timers on NRF51 and I'm getting a 7ms per second error. (I.e. osDelay(1000) takes 1007ms).

It appears that NRF_RTC1 is configured incorrectly in SDK examples. I'm using SDK10, but looking at SDK12 sources it seems that the error persists.

Without further ado, here is the fix. In RTX_Conf_CM.c:

(1) OS_TRV should be set to 32 (ignore the formula)

(2) in os_tick_init(), the line

NRF_RTC1->PRESCALER = OS_TRV;

should be changed to:

NRF_RTC1->PRESCALER = OS_TRV - 1;

(see NRF51 Reference Manual v3.0, section 19.1.2). This will cause NRF_RFC1 to tick 1024 times per second.

(3) OS_TICK should be set to 977.

This should cause osDelay(1000) to actually return after 1000ms.

Alternatively, you can set OS_TICK to 1000, and use 1/1024 s ticks , i.e. osDelay(1024) to get a 1 second delay.

Related