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

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

Children
Related