Hi,
I have a problem with the app timer firing incorrectly.
I am using development board nrf52840-DK, Segger Studio 4.22, SDK 15.3.0_59.
When there has gone more than 256 seconds without any running app timers, the app timer fails and triggers right away.
Can you tell me what I have misunderstood?
I have modified the example /ble_peripheral/ble_app_blinky/ and made the following changes:
In sdk_config.h, I changed APP_TIMER_KEEPS_RTC_ACTIVE to be enabled.
In main.c outside of int main() I have added:
#include "nrf_delay.h"
APP_TIMER_DEF(app_tester_timer);
#define LOG_PRINTF(...) NRF_LOG_INFO(__VA_ARGS__); while(NRF_LOG_PROCESS()== true) {;}
volatile bool timer_triggered = false;
void timer_cb(void);
void timer_cb(void)
{
timer_triggered = true;
NRF_LOG_INFO("\nTimer cb\n");}
In main.c inside of int main() just after ble_stack_init() I have added:
#define APP_TIMER_WAIT_MS (270*1000)
#define APP_TIMER_DELAY_MS (10*1000)
ret_code_t err_code;
LOG_PRINTF("\nTimer Create\n");
err_code = app_timer_create(&app_tester_timer,APP_TIMER_MODE_SINGLE_SHOT,timer_cb);
APP_ERROR_CHECK(err_code);
// For starting app rtc timer(else it will not fail!)
err_code = app_timer_start(app_tester_timer, APP_TIMER_TICKS(50), NULL);
APP_ERROR_CHECK(err_code);
// app rtc timer started, just stop alarm.
err_code = app_timer_stop(app_tester_timer);
APP_ERROR_CHECK(err_code);
LOG_PRINTF("\nWaiting for more than 256 seconds..\n");
nrf_delay_ms(APP_TIMER_WAIT_MS);
LOG_PRINTF("\nWaiting finished\n");
timer_triggered = false;
err_code = app_timer_start(app_tester_timer, APP_TIMER_TICKS(APP_TIMER_DELAY_MS), NULL);
APP_ERROR_CHECK(err_code);
LOG_PRINTF("\nTimer Started..\n");
uint32_t time_elapsed_ms = 0;
while(timer_triggered==false)
{
nrf_delay_ms(10);
time_elapsed_ms += 10;
}
if(time_elapsed_ms < (APP_TIMER_DELAY_MS*0.9))
{
LOG_PRINTF("\nApp timer fired to fast: Elapsed time(ms)=%d, expected(ms)=%d\n", time_elapsed_ms, APP_TIMER_DELAY_MS);
}
else if(time_elapsed_ms < (APP_TIMER_DELAY_MS*0.9))
{
LOG_PRINTF("\nApp timer fired to slow: Elapsed time(ms)=%d, expected(ms)=%d\n", time_elapsed_ms, APP_TIMER_DELAY_MS);
}
else
{
LOG_PRINTF("\nApp timer fired OK : Elapsed time(ms)=%d, expected(ms)=%d\n", time_elapsed_ms, APP_TIMER_DELAY_MS);
}
The app timer always fires in less than 10ms and shows the "App Timer fired to fast...", event though it should wait 10 seconds.
Help from anyone having a clue what is going is appreciated.
Best regards Erik.