Author Topic: watchdog interaction with sleep  (Read 115 times)

jhoward88

  • Newbie
  • *
  • Posts: 13
  • Country: us
watchdog interaction with sleep
« on: April 29, 2020, 03:29:59 PM »
I'm using something like this and getting more reboots than I should.  I suspect something is not ok about using wdt disable/enable cycles like this.
Can anyone give me some advice on it?

Code: [Select]
void loop() {
    wdt_enable(WDTO_8S);   

    if(pinChangeInterruptFlag) {   // we can get interrupted any time, but mostly just 8 second sleeps and wakes
       do_small_stuff()   //takes a couple of seconds

       if (extraStuffNeeded ){     //happens sometimes. uh oh, this might take 6 seconds...
    wdt_disable();         // so lets give ourselves another 8
    wdt_enable(WDTO_8S);
    go_do_extra stuff();
    }
    }


    wdt_disable();
    radio.sleep();   
    LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
}

Thanks,
Jerry

TomWS

  • Hero Member
  • *****
  • Posts: 1924
Re: watchdog interaction with sleep
« Reply #1 on: May 01, 2020, 07:55:20 PM »
I'm thinking you didn't post all of the code so hard to tell what's wrong.