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

Problem while updating App Timer

Hello,

For our nrf52832 custom board developed using nrf SDK 14.2, I need to turn OFF and ON LED accurately in terms of ms, hence after going through this page, I used Single shot timer to trigger ON and OFF and serve the purpose.


Firstly, I use a repeated timer, which runs at a interval of 20ms, and in the callback function (switch_on_off_IRLED()), I turn on the led and trigger single shot timer say for 4ms and turn off the led after its execution for the rest of the repeated interval.

Timers_init()
{
    ret_code_t error_code = app_timer_init();
    APP_ERROR_CHECK(error_code);
}

Create_Timers()
{
    ret_code_t error_code;
    error_code = app_timer_create(&led_on_off_timer_id, APP_TIMER_MODE_REPEATED, switch_on_off_IRLED);
    APP_ERROR_CHECK(error_code);
    
    error_code = app_timer_create(&turn_on_ms, APP_TIMER_MODE_SINGLE_SHOT, Test_on);
    APP_ERROR_CHECK(error_code);
}

Start_Timers()
{
    ret_code_t error_code = app_timer_start(led_on_off_timer_id, APP_TIMER_TICKS(20), NULL);
    APP_ERROR_CHECK(error_code);
}

void switch_on_off_IRLED()
{
	nrf_gpio_pin_write(BSP_LED_3,1);
	Turn_On_LED(4);
}   

void Turn_On_LED(uint8_t time_ms)
{
	ret_code_t error_code = app_timer_start(turn_on_ms, APP_TIMER_TICKS(time_ms), NULL);
	APP_ERROR_CHECK(error_code);
}

void Test_on()
{
    //Turn off
	nrf_gpio_pin_write(BSP_LED_3,0);
}

Later, I came across unusual error, where sometimes LED ON and OFF was getting triggered simultaneously, which was as seen in the debug output. 

<info> app: ON
<info> app: OFF
<info> app: ON
<info> app: OFF
<info> app: ON
<info> app: OFF
<info> app: ON
<info> app: ON
<info> app: OFF
<info> app: OFF
<info> app: ON
<info> app: OFF
<info> app: ON
<info> app: OFF
<info> app: ON
<info> app: OFF
<info> app: ON
<info> app: OFF
<info> app: ON
<info> app: ON
<info> app: OFF
<info> app: OFF
<info> app: ON
<info> app: OFF
<info> app: ON
<info> app: ON
<info> app: OFF
<info> app: ON
<info> app: OFF
<info> app: OFF
<info> app: ON
<info> app: OFF

After coming across this post, thought it could be known issues and I followed steps described here in the solution, downloaded nrf sdk 15.0.0. Replaced app_timer.c with app_timer2.c and drv_rtc.c, added all the necessary dependencies since SDK 14.2 doesn't have nrfx.h and other files which i took from SDK 15.0.0. 

After updating the app_timer the application timer itself doesn't start when i tried in nrf connect. Could anyone guide me here if I am missing any steps? Any help is much appreciated.

Regards,

Nagarjun 

Parents
  • If you are using app_timer.c in nRF5 SDK v14.2 I recommend to increase MAX_RTC_TASKS_DELAY 100 (instead of 47). Also, make sure you always have a repeated timer running if you are starting and stopping other timers.

    If that doesn't solve the problem, then I suggest (as you are already doing) to move to a newer nRF5 SDK, though I don't have a step by step guide on how to backport app_timer2.c to an older nRF5 SDK.

    Kenneth

  • If you are using app_timer.c in nRF5 SDK v14.2 I recommend to increase MAX_RTC_TASKS_DELAY 100 (instead of 47). Also, make sure you always have a repeated timer running if you are starting and stopping other timers.

    Updating MAX_RTC_TASKS_DELAY TO 100 did not seem to solve the problem. And also yes, I am making sure that I run a repeated timer and inside the callback I start and stop the single shot timer.

    If that doesn't solve the problem, then I suggest (as you are already doing) to move to a newer nRF5 SDK, though I don't have a step by step guide on how to backport app_timer2.c to an older nRF5 SDK.

    It's not in the plan to move new nRF SDK yet. Is there anything else, is there anything else which I can try before actually migrating to higher SDK version?

    Nagarjun

  • Yes, very much unusual, nothing else has been changed. Prescalar is set APP_TIMER_CONFIG_RTC_FREQUENCY of 0 corresponding to 32768hz. And SWI_IRQ_PRI, RTC1_IRQ_PRI are set to APP_TIMER_CONFIG_IRQ_PRIORIT of 7.

  • Your app_timer callback handler are not calling any NRF_LOG function, how do you output the log info here?

    Kenneth

  • I had one more timer called Turn OFF LED single shot timer as well similar to Turn_On_LED(uint8_t time_ms) , I removed it above in the callback sample. 

    In my code it looked like this

    void switch_on_off_IRLED()
    {
    	nrf_gpio_pin_write(BSP_LED_3,1);
    	Turn_On_LED(4);
    	nrf_gpio_pin_write(BSP_LED_3,0);
    	Turn_Off_LED(16)
    }  
    
    void Test_on()
    {
    	//nrf_gpio_pin_write(BSP_LED_3,0);
    	NRF_LOG_INFO( "ON");
    }
    
    void Test_off()
    {
    	//nrf_gpio_pin_write(BSP_LED_3,1);
    	NRF_LOG_INFO( "OFF");
    }

    I removed turn off timer, since I read multiple timers with too many start and stops makes up to above behavior. But removing turn off timer did not help, since I was observing same behavior again.

    Nagarjun

  • Are you able to make some simple project I can run on an nRF52-DK to recreate the issue?

    Kenneth

  • I am afraid not. I directly started working on Custom board and do not have nRF52 DK. The best way to recreate this scenario is to run a Repeated timer with a interval 20ms and in the callback, trigger one or two single shot timer and stop within 20ms using SDK 14.2. 

    And also, i tried increasing APP_TIMER_CONFIG_OP_QUEUE_SIZE from 10 to 50, i found that duration of working was increased before irregularity. And than when increased to 100, it disturbed functionality of other things in the application.

    Nagarjun

Reply
  • I am afraid not. I directly started working on Custom board and do not have nRF52 DK. The best way to recreate this scenario is to run a Repeated timer with a interval 20ms and in the callback, trigger one or two single shot timer and stop within 20ms using SDK 14.2. 

    And also, i tried increasing APP_TIMER_CONFIG_OP_QUEUE_SIZE from 10 to 50, i found that duration of working was increased before irregularity. And than when increased to 100, it disturbed functionality of other things in the application.

    Nagarjun

Children
  • I hadn't tried before, just tried it now, increasing Stack_Size from 8192 bytes to 16384 in /toolchain/gcc/gcc_startup_nrf52.S. Still the time behavior was same.

    Mpu Handler is one more repeated timer in my application running every 10ms. Green indicates regular format for a period of 20ms. Red is the unusual one which happens at very repeated interval which I have no track of.

    <info> app: Mpu Handler
    <info> app: Switch_on
    <info> app: Mpu Handler
    <info> app: ON
    <info> app: OFF
    <info> app: Mpu Handler
    <info> app: Switch_on
    <info> app: Mpu Handler
    <info> app: ON
    <info> app: OFF
    <info> app: Mpu Handler
    <info> app: Switch_on
    <info> app: Mpu Handler
    <info> app: ON
    <info> app: OFF
    <info> app: Mpu Handler
    <info> app: Switch_on
    <info> app: Mpu Handler
    <info> app: ON
    <info> app: OFF
    <info> app: Switch_on
    <info> app: Mpu Handler
    <info> app: Mpu Handler
    <info> app: ON
    <info> app: OFF
    <info> app: Switch_on
    <info> app: Mpu Handler
    <info> app: Mpu Handler
    <info> app: ON
    <info> app: OFF
    <info> app: Switch_on
    <info> app: Mpu Handler
    <info> app: ON
    <info> app: OFF
    <info> app: Mpu Handler
    <info> app: Switch_on
    <info> app: Mpu Handler
    <info> app: ON
    <info> app: OFF
    <info> app: Mpu Handler
    <info> app: Switch_on
    <info> app: Mpu Handler
    <info> app: ON
    <info> app: OFF
    <info> app: Mpu Handler
    <info> app: Switch_on
    <info> app: Mpu Handler
    <info> app: ON
    <info> app: OFF
    <info> app: Mpu Handler
    <info> app: Switch_on
    <info> app: Mpu Handler
    <info> app: ON
    <info> app: OFF
    <info> app: Mpu Handler
    <info> app: Switch_on
    <info> app: Mpu Handler
    <info> app: ON
    <info> app: OFF
    <info> app: Mpu Handler
    <info> app: Switch_on
    <info> app: Mpu Handler
    <info> app: ON
    <info> app: OFF

  • I suggest to continue the debugging and see if you can find anything impacting the issue. E.g. does not go to sleep help in any way, look at the duration of the app_timers, e.g. make sure none take a long time to execute and/or check that no other higher priority interrupt take long time (and may be blocking the app_timer). Look at the varibles you are using, try to set them static or volatile in case the compiler is trying to optimize them.

    Kenneth

Related