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

app timer sometimes expires immediately

Hello,

I am using nrf52840 and SDK 15.3.0. and the device wakes up every hour and every day for reporting data.

So I am using app timer to wake up also using app_timer to check timeout for sensor communication response.

And sometimes that sensor communication response ends up with timeout because the app timer expires immediately.

I found some similar questions like below in this devzone and tried to use 64hz rtc1 scale not to exceed MAX_RTC_COUNTER_VAL/2 and the issue looks gone.

My question is was this app timer bug fixed before SDK 15.3.0 or any plan to fix it?

https://devzone.nordicsemi.com/f/nordic-q-a/11738/app_timer-expires-immediately---sdk-10

https://devzone.nordicsemi.com/f/nordic-q-a/29665/sdk-13-app_timer-24-hour-long-timer

Thank you.

Parents
  • Hi,

    The MAX_RTC_COUNTER_VAL/2 is present in most SDK versions. I recommend you use the app_timer2 implementation (app_timer2.c) from SDK 16. If you are using 15.3, just copy that to your older SDK version. app_time2 is a complete rewrite, and it is the default in SDK 16. It does not suffer from the same bugs as the old app_timer implementation.

  • Seems like it works.

    So the apptimer2 supports 64 bit tick counter as well right?

    I was using extra code that calculates rtc1 with overflow counter for supporting a long time os tick counter but it looks like I can use apptimer2 get_now() instead of implementing extra code. Am I correct? or do I need some more set up to avoid rtc counter reset issue? I have never seen rtc counter reset issue with apptimer2 so far but my testing time was not enough and just want to make sure.

    Thanks!

  • Hi,

    eleven-x_devteam said:
    So the apptimer2 supports 64 bit tick counter as well right?

    Not really. It use 64 bit counter internally, and it is not limited to the 24 bit of the physical RTC like the original implementation, but the API still use 32 bit ticks (uint32_t).

    eleven-x_devteam said:
    t looks like I can use apptimer2 get_now() instead of implementing extra code. Am I correct?

    This is an internal static function. You can of course make it none static and u see it, but you need to handle overflows.

    eleven-x_devteam said:
    or do I need some more set up to avoid rtc counter reset issue?

    The RTC should never be reset (or stopped) if you setAPP_TIMER_KEEPS_RTC_ACTIVE to 1 in your sdk_config.h.

  • The RTC should never be reset (or stopped) if you setAPP_TIMER_KEEPS_RTC_ACTIVE to 1 in your sdk_config.h.

    Yeah, I've been using this setting but it was reset with apptimer1 sdk15.

    This is an internal static function. You can of course make it none static and u see it, but you need to handle overflows.

    I thought get_now() can cover the overflows as well.

    It looks like m_base_counter is updated with overflow count in on_overflow_evt() like below.
    static void on_overflow_evt(void)
    {
        NRF_LOG_DEBUG("Overflow EVT");
        m_base_counter += (DRV_RTC_MAX_CNT + 1);
    }
Reply Children
Related