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

  • 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

Related