RTC interrupt handler is triggering with wrong timing.

SDK: 6.0.16.1144

Kit: DA14531MOD-00DEVKT-P

Module: Custom board even with DA14531MOD

Keil uVision: v5.38.0.0

I am using default example "prox_reporter". I have added few debug messages to know when the interrupt is triggering. I have left the example code as it is and as per the configure_rtc_wakeup() method RTC interrupt should trigger for every 10 seconds:

static void configure_rtc_wakeup(void)
{
	arch_printf("::%s(START)\n", __FUNCTION__);
    rtc_time_t alarm_time;

    // Init RTC
    rtc_reset();

    // Configure the RTC clock; RCX is the RTC clock source (14420 Hz)
    rtc_clk_config(RTC_DIV_DENOM_1000, 14420);
    rtc_clock_enable();

    rtc_config_t cfg = {.hour_clk_mode = RTC_HOUR_MODE_24H, .keep_rtc = 0};

    rtc_time_t time = {.hour_mode = RTC_HOUR_MODE_24H, .pm_flag = 0, .hour = 11,
                       .minute = 55, .sec = 30, .hsec = 00};

    // Alarm interrupt in ten seconds
    alarm_time = time;
    alarm_time.sec += 10;

    // Initialize RTC, set time and data, register interrupt handler callback function and enable seconds interrupt
    rtc_init(&cfg);

    // Start RTC
    rtc_set_time_clndr(&time, NULL);
    rtc_set_alarm(&alarm_time, NULL, RTC_ALARM_EN_SEC);

    // Clear pending interrupts
    rtc_get_event_flags();
    rtc_register_intr(rtc_interrupt_hdlr, RTC_INTR_ALRM);
#if defined (CFG_EXT_SLEEP_WAKEUP_RTC)
    app_easy_wakeup_set(app_wakeup_cb);
#endif
		arch_printf("::%s(STOP)\n", __FUNCTION__);
}

However the rtc_interrupt_hdlr() is called for every one minute instead of 10 seconds. Surprisingly, even if I change 

alarm_time.sec += 10;

to

alarm_time.sec += 1;

it is still triggering with the same time. I erased the code and did burn again to make sure that old code is not running. What could be the wrong. 

Captured log messages. The time stamp indicates that the rtc_interrupt_hdlr() is triggered almost for each minute.

18:05:01.017 -> ::configure_rtc_wakeup(START)
18:05:01.017 -> ::configure_rtc_wakeup(STOP)
18:05:10.737 -> ::rtc_interrupt_hdlr(START)
18:05:10.737 -> ::app_wakeup_cb(START)
18:06:09.596 -> ::rtc_interrupt_hdlr(START)
18:07:07.756 -> ::rtc_interrupt_hdlr(START)
18:08:05.943 -> ::rtc_interrupt_hdlr(START)

18:08:10.718 -> ::configure_rtc_wakeup(START)
18:08:10.750 -> ::configure_rtc_wakeup(STOP)
18:08:20.455 -> ::rtc_interrupt_hdlr(START)
18:08:20.455 -> ::app_wakeup_cb(START)
18:09:19.327 -> ::rtc_interrupt_hdlr(START)
18:10:17.469 -> ::rtc_interrupt_hdlr(START)
18:11:15.666 -> ::rtc_interrupt_hdlr(START)

18:11:20.459 -> ::configure_rtc_wakeup(START)
18:11:20.459 -> ::configure_rtc_wakeup(STOP)
18:11:30.176 -> ::rtc_interrupt_hdlr(START)
18:11:30.176 -> ::app_wakeup_cb(START)
18:12:29.039 -> ::rtc_interrupt_hdlr(START)
18:13:27.225 -> ::rtc_interrupt_hdlr(START)
18:14:25.392 -> ::rtc_interrupt_hdlr(START)

18:14:30.167 -> ::configure_rtc_wakeup(START)
18:14:30.167 -> ::configure_rtc_wakeup(STOP)
18:14:39.888 -> ::rtc_interrupt_hdlr(START)
18:14:39.888 -> ::app_wakeup_cb(START)
18:15:38.767 -> ::rtc_interrupt_hdlr(START)
18:16:36.926 -> ::rtc_interrupt_hdlr(START)

1) Why the timing is wrong?

2) Why triggering time is not changing?

And the same configure_rtc_wakeup() method I copied to my own application and there its taking even more time. For

rtc_time_t alarm_time;

// Init RTC
rtc_reset();

// Configure the RTC clock; RCX is the RTC clock source (14420 Hz)
rtc_clk_config(RTC_DIV_DENOM_1000, 14420);
rtc_clock_enable();

rtc_config_t cfg = {.hour_clk_mode = RTC_HOUR_MODE_24H, .keep_rtc = 0};

rtc_time_t time = {.hour_mode = RTC_HOUR_MODE_24H, .pm_flag = 0, .hour = 11,
                   .minute = 55, .sec = 30, .hsec = 00};

// Alarm interrupt in ten seconds
alarm_time = time;
alarm_time.sec += 10;

// Initialize RTC, set time and data, register interrupt handler callback function and enable seconds interrupt
rtc_init(&cfg);

// Start RTC
rtc_set_time_clndr(&time, NULL);
rtc_set_alarm(&alarm_time, NULL, RTC_ALARM_EN_SEC);

// Clear pending interrupts
rtc_get_event_flags();
rtc_register_intr(rtc_interrupt_hdlr, RTC_INTR_ALRM);

its triggering for every10 minutes.

3) How to debug it to know why its taking that much time?

Thanks,

Harish

Parents
  • Hi Harish,

    Please note that there are adv time there, after adv done than start sleep.

    I have test my site it works fine.

    BR,

    Jason

  • Hi Jason,

    I do not understand how  .adv* parameters will come into picture here. I am taking about the RTC timeout/interrupts. And in my custom code where its long time to trigger say 10min instead of 10 seconds, I am not advertising at that time as I have not started advertising by that time. Because I will enable BT advertising after multiple RTC timeouts and after certain time.

    I could see that you are getting timeouts and log messages. Can I see how you are initializing alarm_time and setting alarm_time.sec before calling  rtc_set_alarm(). And also rtc_interrupt_hdlr in rtc_register_intr() looks like? Say, how its is re-initializing RTC alarm trigger.

    Thanks,

    Harish

Reply
  • Hi Jason,

    I do not understand how  .adv* parameters will come into picture here. I am taking about the RTC timeout/interrupts. And in my custom code where its long time to trigger say 10min instead of 10 seconds, I am not advertising at that time as I have not started advertising by that time. Because I will enable BT advertising after multiple RTC timeouts and after certain time.

    I could see that you are getting timeouts and log messages. Can I see how you are initializing alarm_time and setting alarm_time.sec before calling  rtc_set_alarm(). And also rtc_interrupt_hdlr in rtc_register_intr() looks like? Say, how its is re-initializing RTC alarm trigger.

    Thanks,

    Harish

Children
  • Hi Harish,

    1, As I know, you are using the default SDK, If you have custom code please share with me the changes you made.

    2, About the adv parameter, in the default SDK, The RTC starts in the 

        .app_on_adv_undirect_complete       = app_advertise_complete, api. which callback will been triggered after advertising stopped. 
    3, Default procedure: power - advertising - advertising stopped with advertise_period expired -- initializing RTC and RTC alarm -- go to sleep mode -- RTC alarm -- wake up procedure...
    BR,
    Jason
  • Hi Jason,

    Sorry for the late reply.

    Understood. But my question was about wrong triggering times. So, the issue will be in the RTC init and re-init in the call back, hence I am asking the snippet from your code how they are initialized.

    Thanks,

    Harish

  • Hi Jason,

    My issue is solved. Look like the timer init logic is wrong.

    I was using "alarm_time.sec += 10" which is goes beyond 60 seconds and I used with mod operator like "alarm_time.sec = (alarm_time.sec + 10) % 60" And with this the timer triggering time is working as expected. 

    However I did not understand why it did not worked in sample SDK example correctly as the case there also it might have ended up with crossing 59 limit. 

    In any way, the issue is solved as of now and as I am doing some logic check to not to exceed 59 for the seconds field.

    Thanks & Regards

    Harish