
46
2552K–AVR–04/11
ATmega329/3290/649/6490
The following code example shows one assembly and one C function for turning off the WDT.
The example assumes that interrupts are controlled (e.g. by disabling interrupts globally) so that
no interrupts will occur during execution of these functions.
Note:
Table 10-2.
Watchdog Timer Prescale Select
WDP2
WDP1
WDP0
Number of WDT
Oscillator Cycles
Typical Time-out
at V
CC = 3.0V
Typical Time-out
at V
CC = 5.0V
0
16K cycles
17.1ms
16.3ms
0
1
32K cycles
34.3ms
32.5ms
0
1
0
64K cycles
68.5ms
65ms
01
1
128K cycles
0.14s
0.13s
1
0
256K cycles
0.27s
0.26s
1
0
1
512K cycles
0.55s
0.52s
1
0
1,024K cycles
1.1s
1.0s
11
1
2,048K cycles
2.2s
2.1s
WDT_off:
; Reset WDT
wdr
; Write logical one to WDCE and WDE
in
r16, WDTCR
ori
r16, (1<<WDCE)|(1<<WDE)
out
WDTCR, r16
; Turn off WDT
ldi
r16, (0<<WDE)
out
WDTCR, r16
ret
C Code Example
void
WDT_off(void)
{
/* Reset WDT */
__watchdog_reset();
/* Write logical one to WDCE and WDE */
WDTCR |= (1<<WDCE) | (1<<WDE);
/* Turn off WDT */
WDTCR = 0x00;
}