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

nRF52832 RTC inaccuracy LF CLK?

Hi. We are using RTC2 in our application to trigger an event at 256Hz. We also have a compare running to trigger a compare event at 32Hz.

I have found that over an hour, event will have been running slowly about 98% of the rate it should be. Below is the code to setup the RTC.

How do I check that our external LF clk (crystal) is running and not the internal RC clock? This could be causing the problem / inaccuracy.

We are using the softdevice, but may be using the internal oscillator instead of the external one.

Thanks

/** @brief Function initialization and configuration of RTC driver instance.
 */
static void rtc_config(void)
{
    uint32_t err_code;

    //Initialize RTC instance
    nrf_drv_rtc_config_t config = NRF_DRV_RTC_DEFAULT_CONFIG;
    config.prescaler = 127;  //1023 = 32 Hz, 127 = 256 Hz
    config.interrupt_priority = 7;
    err_code = nrf_drv_rtc_init(&rtc, &config, rtc_handler);
    APP_ERROR_CHECK(err_code);

    //Enable tick event & interrupt
    nrf_drv_rtc_tick_enable(&rtc,true);

    //Set compare channel to trigger interrupt after COMPARE_COUNTERTIME seconds
    err_code = nrf_drv_rtc_cc_set(&rtc,2,8,true); //x8 = 32Hz
    APP_ERROR_CHECK(err_code);

    //Power on RTC instance
    nrf_drv_rtc_enable(&rtc);
}

Parents
  • Oh I found this in the sdk_config so must be using the correct LF_CLK source.

    // <0=> NRF_CLOCK_LF_SRC_RC
    // <1=> NRF_CLOCK_LF_SRC_XTAL
    // <2=> NRF_CLOCK_LF_SRC_SYNTH

    #ifndef NRF_SDH_CLOCK_LF_SRC
    #define NRF_SDH_CLOCK_LF_SRC 1
    #endif

    So RTC is inaccurate. How does the priority effect accuracy? It doesn't matter if an event is slightly late due to event priorities but shouldn't the next one be fired exactly 1/256 after the first and so on?

    thanks

  • The accuracy when using internal LF RC is up to <500ppm (<0.05%), however this is given that that LF RC is calibrated (for instance this is done automatically if you have enabled the softdevice with internal LF RC as source). If you need more accurate source than that you need to use external XTAL as LF source, then you may for instance have <20ppm (<0.002%). If you are using RTC then make sure that you have started the LF souce you want to use first (for instance by enable softdevice), else it likely will just use the internal LF RC without calibration (>>0.05%).

    Kenneth

Reply
  • The accuracy when using internal LF RC is up to <500ppm (<0.05%), however this is given that that LF RC is calibrated (for instance this is done automatically if you have enabled the softdevice with internal LF RC as source). If you need more accurate source than that you need to use external XTAL as LF source, then you may for instance have <20ppm (<0.002%). If you are using RTC then make sure that you have started the LF souce you want to use first (for instance by enable softdevice), else it likely will just use the internal LF RC without calibration (>>0.05%).

    Kenneth

Children
Related