This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Alternative way of using app timer as low power delay?

Hey all! I have been using your amazing app timer for a while now but I was wondering if there was a better way to create a low power delay than my current design which goes something like this:

timer2_handler()

{

    //execute code after 10ms has passed

}

timer1_handler()

{

    start_timer2(10ms in ticks);

}

This works nicely because the code returns to the power management state(wfe if i'm not mistaken) that is running in main(). However I was wondering if there is a way to perform the wait inside timer1_handler's context? This is mainly because if I require multiple delays in succession(such as waiting for sensors to wake up, etc.) then I would need to spawn more timers and as a result, more handlers, which can become very hard to follow the flow.

I've tried something like this(from this post: https://devzone.nordicsemi.com/f/nordic-q-a/26451/low-power-delay-implementation):

static void timer2_wait_handler(void *p_context)
{

NRF_LOG_INFO("in app timer");
NRF_LOG_FLUSH();
timerFlag = 1;

}


static void timer1_timer_handler(void *p_context)
{
timerFlag = 0;
NRF_LOG_INFO("before delay");
app_timer_start(timer2_wait_id,APP_TIMER_TICKS(1000),NULL);
while(!timerFlag)
{
sd_app_evt_wait();
}
NRF_LOG_INFO("after delay");
}

However the while loop is never 'escaped', and the timer 2  handler is never called(tried both logging and breakpoints). The timer2 handler is called if I comment out the while loop, but that would remove the in function delay aspect.

So is if there is a better way to have low power delay functions which don't rely on multiple handlers being executed in succession?

Related