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