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

Watchdog problem

SDK 14.2

I try to use the watchdog using this code

static void nrf_wdt_event_handler(void)
{
     NRF_LOG_INFO(">>>  nrf_wdt_event_handler")
}

int main(void)
{

...

   nrf_drv_wdt_config_t wdtConfig;
   wdtConfig.reload_value= 3*32768;
   wdtConfig.behaviour= NRF_WDT_BEHAVIOUR_PAUSE_SLEEP_HALT;
   wdtConfig.interrupt_priority=7;
   APP_ERROR_CHECK( nrf_drv_wdt_init(&wdtConfig, nrf_wdt_event_handler) );
   APP_ERROR_CHECK( nrf_drv_wdt_channel_alloc(NRF_WDT_RR0));
   nrf_drv_wdt_enable();

...

In my 1sec timer routine I stop calling   nrf_drv_wdt_channel_feed(NRF_WDT_RR0); after 19 seconds.

But the expected watchdog timeout never happens.

Why?

Parents
  • Do you enter sleep in your main loop (with sd_app_evt_wait() or similar?

    The watchdog counter will not tick when system is in sleep, since you use NRF_WDT_BEHAVIOUR_PAUSE_SLEEP_HALT. In this case it will take a very long time to get 3 seconds cpu time on an idle system.

  • Yes I do.

    I assumed the 3 seconds are realtime, only that it would not trigger during sleep periods. Now I realize that it just doesn't tick.

    The watchdog is my last hope in desperation, because my system scans for advertisements briefly every few seconds, and also responds to a button press using  bsp_event_handler.  Occasionly after a few hours the button press is not detected anymore, and scanning stopped. I have no idea why. If it was simply asleep the button-press would wake it up, but it does not in this case. The button handler simply calls sd_nvic_SystemReset(). So I would be happy if I could get a reset behavior in this problematic case, and user experience will remain the same.

    Not sure if a watchdog would really help in my case. I can't let it run during sleep, because it would then wake it up during deep-sleep that is entered several hours after idleing.

  • You can enable the watchdog to run while in sleep mode, it will however not run in "deep-sleep" mode, because the timers are not running in this state, and the watchdog timer would not have a way of running. 

     

    You can use the line below:

    NRF_WDT->CONFIG = (WDT_CONFIG_HALT_Pause << WDT_CONFIG_HALT_Pos) | ( WDT_CONFIG_SLEEP_Run << WDT_CONFIG_SLEEP_Pos);   //Configure Watchdog. a) Pause watchdog while the CPU is halted by the debugger.  b) Keep the watchdog running while the CPU is sleeping.

    It is used in this project from github.

    I know it is made for the nRF51, but it should still be relevant for the WDT.

     

    Perhaps it would be more interresting to find out why the button does not wake up the device. I suggest you create a new case with the corresponding subject. Then describe the problem there, and also describe how you have set up the wakeup button.

    BR,

    Edvin

Reply
  • You can enable the watchdog to run while in sleep mode, it will however not run in "deep-sleep" mode, because the timers are not running in this state, and the watchdog timer would not have a way of running. 

     

    You can use the line below:

    NRF_WDT->CONFIG = (WDT_CONFIG_HALT_Pause << WDT_CONFIG_HALT_Pos) | ( WDT_CONFIG_SLEEP_Run << WDT_CONFIG_SLEEP_Pos);   //Configure Watchdog. a) Pause watchdog while the CPU is halted by the debugger.  b) Keep the watchdog running while the CPU is sleeping.

    It is used in this project from github.

    I know it is made for the nRF51, but it should still be relevant for the WDT.

     

    Perhaps it would be more interresting to find out why the button does not wake up the device. I suggest you create a new case with the corresponding subject. Then describe the problem there, and also describe how you have set up the wakeup button.

    BR,

    Edvin

Children
  • I tried that already but gave up because #include "nrf51_bitfields.h" gave lots of compilation errors.

    For a test I just used

    wdtConfig.behaviour= NRF_WDT_BEHAVIOUR_RUN_SLEEP;

    wdtConfig.reload_value= 3000;

    and now it triggers after 3 seconds as expected.

    Thanks for your advice creating a case. But I can't even repeat this problem reliably here. It happens only occasionly. Not something wishes for.

Related