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

App timer accuracy

Hello, I've got a problem with an app_timer starting from the BLE_UART example, I've set

#define APP_TIMER_PRESCALER             4
#define CLOCK_CONFIG_LF_SRC             NRF_CLOCK_LF_SRC_Xtal

and create a timer with

app_timer_create(&m_alert_timer_id, APP_TIMER_MODE_REPEATED, alert_timer_handler);
app_timer_start(m_alert_timer_id,6554,NULL);
nrf_gpio_cfg_output(25);

to obtain a 1s signal on pin 25. The question is : as far as I have a value of 4 for the prescaler, I should use a value of 8192 for a 1 second signal, and not 6554. The cristal used frequency is 32.768KHz (verified with a scope).

Parents
  • According to the nRF52 documents, the calculation for frequency with regards to the prescaler is:

    fRTC [kHz] = 32.768 / (PRESCALER + 1 )

    So to use 8192 the prescaler should be set to 3. I ran into this once on the nRF51 and it took a while for it to sink in that the prescaler starts at 0, not 1.

Reply
  • According to the nRF52 documents, the calculation for frequency with regards to the prescaler is:

    fRTC [kHz] = 32.768 / (PRESCALER + 1 )

    So to use 8192 the prescaler should be set to 3. I ran into this once on the nRF51 and it took a while for it to sink in that the prescaler starts at 0, not 1.

Children
  • it's clealy that, I was confused by the nrf_drv_rtc.c (too much work around the rtc use) which is not used by the app_timer.c since the last as it's own writes in the rtc peripheral... Thanks John.