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

App_timer expires immediately - SDK 10

I am seeing a problem identical to what's described in this question. I'm using SDK version 10.

My timers work fine for a while, but then suddenly and seemingly at random all timers expire the instant they are started. Sometimes it goes away and the timers work again, but sometimes the only fix seems to be a restart.

I've seen two suggested solutions. One is to add a delay or a call to rtc1_compare0_set in compare_reg_update; I'm on SDK 10 and both solutions are already there:

    ...
    rtc1_compare0_set(rtc1_counter_get());  // this should prevent CC to fire again in the background while the code is in RTC-ISR
    nrf_delay_us(MAX_RTC_TASKS_DELAY);
    timer_timeouts_check_sched();
    ...

The only other solution I've found on the forum is to have a dummy timer that is always running. It's recommended in this answer.

Sadly, I do already have a dummy timer always running—I've been using it to force the RTC to stay on so I can use it for timekeeping.

Are there any other known problems or solutions with app_timer? I'm running out of ideas. Thanks!

Parents
  • When the RTC jumps like that and a timer gets scheduled, the timer's ticks_to_expire gets set to 0 in list_insertions_handler because the counter is so far ahead of m_ticks_latest.

    Then, in timer_timeouts_check, ticks_expired is 0 because it gets set to the timer's ticks_to_expire. m_ticks_elapsed consequently gets set to 0, so m_ticks_latest never increases. At this point, any timer that gets scheduled will expire immediately.

    A solution that appears to work is the addition of the following lines of code:

    +        // If we processed all timers, then move the elapsed ticks counter all the way up to now.
    +        if (p_timer == NULL)
    +        {
    +            ticks_expired += ticks_elapsed;
    +        }
             // Queue the ticks expired.
             m_ticks_elapsed[m_ticks_elapsed_q_write_ind] = ticks_expired;
    

    (see next comment)

Reply
  • When the RTC jumps like that and a timer gets scheduled, the timer's ticks_to_expire gets set to 0 in list_insertions_handler because the counter is so far ahead of m_ticks_latest.

    Then, in timer_timeouts_check, ticks_expired is 0 because it gets set to the timer's ticks_to_expire. m_ticks_elapsed consequently gets set to 0, so m_ticks_latest never increases. At this point, any timer that gets scheduled will expire immediately.

    A solution that appears to work is the addition of the following lines of code:

    +        // If we processed all timers, then move the elapsed ticks counter all the way up to now.
    +        if (p_timer == NULL)
    +        {
    +            ticks_expired += ticks_elapsed;
    +        }
             // Queue the ticks expired.
             m_ticks_elapsed[m_ticks_elapsed_q_write_ind] = ticks_expired;
    

    (see next comment)

Children
No Data
Related