Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

APP_TIMER_V2 does not appear to generate timer interrupts

I am using SDK 17.1.0 with an nRF52832 design similar to the P10040.

I was previously using the original timer application and things were looking good.
I decided to upgrade to SDK 17.1.0 and am using the uart example under 'ble_peripherals' to boot strap my project.

Based on another project using SDK 17.1.0, I decided to move up to the newer version of the application timer.
I defined the symbols 'APP_TIMER_V2' and 'APP_TIMER_V2_RTC1_ENABLED' in the build.

My first question is:  I do not quite understand "why do I need to enable the RTC1"?  -- and when I try to build without using this symbol then I get a build error that there is no RTC instance defined in the build.

My next comment (based on observations) is that when I enable RTC1 then I notice that the processor enters the nrf_power_mgmt phase but never fires the timer handler that I expect to be triggered every 1 second. I have validated that
    a) the firmware has indeed called the 'app_timer_init()' function, 
    b) that this 1-second timer has been created as a 'repeat-mode' timer with a 1 second timeout with no errors, and
    c) that the timer has indeed been started.

I am sure that I am missing something here -- likely some kind of connection between the hardware RTC and the firmware handler but am still struggling to nail it down.

Cheers
RVM

  • Hello RVM,

    My first question is:  I do not quite understand "why do I need to enable the RTC1"?  -- and when I try to build without using this symbol then I get a build error that there is no RTC instance defined in the build.

    The App timer library is based on the RTC1, which is why you will need to enable this RTC instance.

    My next comment (based on observations) is that when I enable RTC1 then I notice that the processor enters the nrf_power_mgmt phase but never fires the timer handler that I expect to be triggered every 1 second. I have validated that

    Could you show me the code for the configuration and initialization of your app timer instance?
    If the timer is set up correctly to trigger a compare event every 1 second it will wake up the device from the SYSTEM_ON sleep to process the event. Once the event has been processed it will go back to sleep, unless there are other events or functions that need processing before it does.

    Best regards,
    Karl

  • Hi Karl,

    When I do not define the symbol 'APP_TIMER_V2' then this is the design pattern
    that has always worked for me with SDK 15.3.0, 16.0.0 and 17.0.1.

    /*   *** NEVER GETS CALLED WHEN USING SDK 17.2.0 AND 
         'APP_TIMER_V2' AND 'APP_TIMER_V2_RTC1_ENABLED' ARE DEFINED *** */
    void PCT_CORE_TimerHandler_OneSecond(void *timer_data)
    {
      // Basic tick counter.
      static uint32_t ticks = 0;
      ticks++;
      return;
    }
    
    
    APP_TIMER_DEF(OneSecond_TimerId);
    
    /* Initialize timer module */
    lcl_err_code = app_timer_init();
    APP_ERROR_CHECK(lcl_err_code);  // No errors observed
      
    /* Create the Reed Switch activation timer */
    lcl_err_code = app_timer_create(&OneSecond_TimerId, APP_TIMER_MODE_REPEATED, TimerHandler_OneSecond);
    APP_ERROR_CHECK(lcl_err_code); // No errors observed.
    
    
    
    #define TIMER_START(T,D)        { ret_code_t lcl_err_code; lcl_err_code = app_timer_start(T, APP_TIMER_TICKS(D), NULL); APP_ERROR_CHECK(lcl_err_code); }
    
    TIMER_START(PCT_CORE_OneSecond_TimerId, 1000); 

    I am not sure what other steps are required for 'configuration and initialization' of this design.

    I also see no difference whether or not I use the scheduler to manage the timer's functionality

  • My experimentation indicates that all I need to do to get the timer to trigger the IRQ as desired is to 'enable the SD Handler" as below just before starting the timer....

    if (!nrf_sdh_is_enabled()) {
      lcl_err_code = nrf_sdh_enable_request();
    }

    The two things (and there may be more) that come to mind are that without the above code, either the RTC module is not fully functional or the Timer IRQ does not have a high enough priority to be noticed by the NVIC.

  • Hello again,

    RMV said:
    The two things (and there may be more) that come to mind are that without the above code, either the RTC module is not fully functional or the Timer IRQ does not have a high enough priority to be noticed by the NVIC.

    The call to nrf_sdh_enable_request() attempts to start the SoftDevice.
    The RTC0 instance will be blocked when the SoftDevice is enabled, but this should not matter to you since you are using the RTC1 instance.
    Unfortunately I do not notice anything off about the steps you take to initialize and start the RTC.
    Taking a closer look at the app_timer2.c implementation it seems to me that the instance used - RTC1 - is hardcoded, and not based on the APP_TIMER_V2_RTC1_ENABLED define.
    I will create an internal ticket to have this examined more closely.

    Could you also share with me the APP_TIMER define's from your sdk_config.h?

    On a sidenote, I notice that the naming in the supplied code does not match exactly - is this not the exact code you are running / is it pseudocode just to highlight the steps you are taking?

    Best regards,
    Karl

  • On a sidenote, I notice that the naming in the supplied code does not match exactly - is this not the exact code you are running / is it pseudocode just to highlight the steps you are taking?

    Hi,

    Yeah, it looks like this is not exactly what I use to test -- the timer handler names are identical in my build Slight smile

Related