RTC "tick" Interrupt Timing Anomaly

In my nRF52810 based circuit board I'm trying to use the RTC along with the RTC tick interrupt to toggle an IO pin every 6msec.    In main.c   I use WFE to enter low power mode between the RTC tick event interrupts.  This seems to work fine with the output pin toggling every 6 msec as desired, but 25 seconds later, the output toggle period changes from 6 msec to about every 7 seconds.   This event is very repeatable.  If I comment out the WFE instruction, the problem goes away.  Can you point me in the right direction?  See the “code” below.

// Configure LFCLK 

void lfclk_config(void)
{
// Initialize the low frequency clock 
   nrf_drv_clock_init();

// Request the clock to not generate events
   nrf_drv_clock_lfclk_request(NULL);
}


// RTC1 interrupt handler 

void rtc1_handler(nrfx_rtc_int_type_t int_type)
{
    nrf_gpio_pin_toggle(output_pin); // toggle output
}


// Configure the RTC1

void rtc1_config(void)
{	
    nrfx_rtc_config_t rtc1_config = NRFX_RTC_DEFAULT_CONFIG;

    // Configure the RTC to tick every 6.25ms which results in an 80HZ output frequency
    rtc1_config.prescaler = 203; // tick =  32768 / (203 + 1) = 80Hz = 12.5msec (all approximate).

    // Initialize the rtc 
    nrfx_rtc_init(&rtc1, &rtc1_config, rtc1_handler);
 
    // Enable a tick interrupt on each tick
    nrfx_rtc_tick_enable(&rtc1, true);

    // start the rtc 
    nrfx_rtc_enable(&rtc1);
}


int main(void)
{
     gpio_init(); // Initialize the gpio
     lfclk_config(); //low frequency low power clock configuration
     nrfx_clock_lfclk_start();
     rtc1_config(); // rtc1 configuration 
      
      while (true) 
      {
           __WFE(); 
      }

}

Parents
  • Problem solved.  The clock module had been misconfigured in that the 32khz oscillator was configured to use an external xtal when the board actually relies on the 52810 internal RC oscillator.  Amazing it worked at all and I still don't fully understand what was going on but once the 32khz clock source was correctly set in config.h (via CMSIS Wizard), the clocking is stable and the design works as intended. 

  • Thank you for confirming what the problem was. I have not seen this failure mode before. When the wrong clock source is selected (i.e. using LFXO when crystal is not mounted), I normally expect the program to get "stuck" waiting for the EVENTS_LFCLKSTARTED event. However, in the RTC example we don't wait for this event, but just start the RTC right away. This means the RTC will start off with the RC oscillator.

    From the 52810 PS:

    "The LFCLK clock is started by first selecting the preferred clock source in register LFCLKSRC and then triggering the LFCLKSTART task. If the LFXO is selected as the clock source, the LFCLK will initially start running from the 32.768 kHz LFRC while the LFXO is starting up and automatically switch to using the LFXO once this oscillator is running. The LFCLKSTARTED event will be generated when the LFXO has been started." (LFCLK clock controller)

Reply
  • Thank you for confirming what the problem was. I have not seen this failure mode before. When the wrong clock source is selected (i.e. using LFXO when crystal is not mounted), I normally expect the program to get "stuck" waiting for the EVENTS_LFCLKSTARTED event. However, in the RTC example we don't wait for this event, but just start the RTC right away. This means the RTC will start off with the RC oscillator.

    From the 52810 PS:

    "The LFCLK clock is started by first selecting the preferred clock source in register LFCLKSRC and then triggering the LFCLKSTART task. If the LFXO is selected as the clock source, the LFCLK will initially start running from the 32.768 kHz LFRC while the LFXO is starting up and automatically switch to using the LFXO once this oscillator is running. The LFCLKSTARTED event will be generated when the LFXO has been started." (LFCLK clock controller)

Children
No Data
Related