This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

nrf_pwr_mgmt_run returning twice as often as __WFI

I'm using s132.

I'm using the app timer with the app scheduler.

I'm running a simple loop and constantly scheduling the timer in the timer callback.

The callback works as expected, and is triggered at the correct time.

But the main loop wakes up twice as often as the timer callback is called.

My understanding is that `nrf_pwr_mgmt_run` will wait on events. So it's woken up twice. Once for the timer, and once for an unknown reason.

If I use `__WFI` instead of `nrf_pwr_mgmt_run` I get the proper wake up rate.

I'm ok blocking on interrupts (using `__WFI`), but I'm wondering if that's the proper way, and what is that unknown event.

// With
#define APP_SCHEDULER_ENABLED 1
#define APP_TIMER_ENABLED 1
#define APP_TIMER_CONFIG_USE_SCHEDULER 1

// Loop
app_timer_create(&m_timer_id, APP_TIMER_MODE_SINGLE_SHOT, timer_cb);
app_timer_start(m_timer_id, APP_TIMER_TICKS(100), NULL);
while (1) {
    // This runs 20 times a second
    app_sched_execute();
    nrf_pwr_mgmt_run();
}

// Callback
void timer_cb(void *p_context) {
    // This runs 10 times a second
    app_timer_start(m_timer_id, APP_TIMER_TICKS(100), NULL);
}

  • Hello,

    Sorry for the delayed reply.

    I believe what you are seeing is that the app_timer is not as simple as it may look like. 

    The app_timer_start() call doesn't actually start the timer. It will schedule the app_timer to start a timer, and return. Later, when the CPU is free, it will actually start the timer, which will probably run the main()-loop again.

    Best regards,
    Edvin

Related