Hello, I have a question why is there a call to wdt_reset() in the following function even though we set watchdog timer to work in interrupt mode (not the reset mode)?
void myWatchdogEnable()
{
// clear various "reset" flags
MCUSR = 0;
// allow changes, disable reset
WDTCSR = bit (WDCE) | bit (WDE);
// set interrupt mode and an interval
WDTCSR = bit (WDIE) | bit (WDP3) | bit (WDP0); // set WDIE, and 8 seconds delay
wdt_reset(); // pat the dog
// disable ADC
ADCSRA = 0;
// ready to sleep
set_sleep_mode (SLEEP_MODE_PWR_DOWN);
sleep_enable();
// turn off brown-out enable in software
MCUCR = bit (BODS) | bit (BODSE);
MCUCR = bit (BODS);
sleep_cpu ();
// cancel sleep as a precaution
sleep_disable();
}
Whereas a bit above, in Sketch J wdt_reset() is not present. What is the difference?
Thank You for the answer!
I have another question, though. Is the wdt_reset essential for the following code (using both watchdog and interrupt for waking up)?
The wdt_reset() resets the watchdog timer back to zero. Without it, assuming it runs in the background, the timer might fire much sooner than you expect.