Tue 28 Jan 2003 10:34:23 PM UTC, original submission:
The latest (and prior versions?) compiler generates the following code to disable the watchdog --- wdt_disable()---:
Outside interrupt routines:
in _tmp_reg_,__SREG__
cli
wdr
out 33,r24
out _SREG_,__tmp_reg__
out 33,r18
// 33 is the WDTCR
Inside interrupt routines:
ldi r24,lo8(24)
ldi r25,hi8(24)
out 33, r24
out 33, _zero_reg_
If the user is using any watchdog timeout other than 17ms, the interrupt version of the watchdog disable may actually cause a watchdog reset! To prevent this, the WDR instruction should be added in front of the interrupt code as in the non-interrupt code, or the prescaler bits should be preserved during the disable operation. In 'C' the user can avoid the problem by issuing a wdt_reset() instruction just before the wdt_disable() instruction.
In other words, any time you wish to disable the watchdog inside an interrupt routine use the following:
wdt_reset();
wdt_disable();
--
|