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 Reply 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