Atmel AVR132 Скачать руководство пользователя страница 7

7

AVR 132 Application Note

2551A–AVR–11/03

Using the WDT in 
Combined Operation

It is also possible to set up the WDT to work as a wakeup timer when entering sleep
mode, and switch to WDT System Reset operation when back in active mode. With this
setup there is no need for disabling the WDT Interrupt Mode, as it is automatically dis-
abled by the hardware. To use the WDT as a periodic wakeup source, the application
therefore has to enable the WDT Interrupt Mode prior to entering sleep mode every
time.

Re-enabling the WDT Interrupt Mode inside the interrupt handler is not recommended,
as it could cause the WDT to get stuck in WDT Interrupt Mode, if some parts of the code
fail.

When the CPU is back in active mode, the WDR instruction is used for resetting the
WDT inside the main loop as described earlier. With WDT Interrupt Mode disabled, the
WDT functions just as it did without the wakeup functionality.

If timeout warning prior to system reset is needed for parameter backup etc., the WDT
Interrupt handler needs some slight changes. The interrupt handler must use a flag to
decide whether it should serve a wakeup interrupt or a timeout warning interrupt. An
example interrupt handler is shown in Figure 5.

Figure 5.  Dual purpose WDT Interrupt Handler

Note that the wakeup flag must be set manually prior to entering sleep mode to ensure
that the correct part of the handler is executed on wakeup. The WDT Interrupt Mode
must be re-enabled outside the interrupt handler after serving the wakeup interrupt.

The right branch of the flowchart is described in the section on parameter backup.

Startup Considerations

When designing for devices having the Enhanced Watchdog Timer, it is important to
evaluate the WDT Reset Flag in the startup code. This applies even if the application
never intends to use the WDT. If the WDT System Reset Mode should unintentionally
be enabled and cause a system reset, the WDT Reset Flag will be set and the WDT
System Reset Mode is kept enabled after the system reset. Therefore the startup code
should check the WDT Reset Flag and disable the WDT System Reset Mode if it is
enabled but never used. These considerations apply when the WDTON fuse is unpro-

Backup vital

parameters

WDT Interrupt Handler

WDT Interrupt Mode

disabled

Set Write Complete

Flag

Infinite loop

Wakeup Flag

set ?

Clear Wakeup Flag

Return

No

Yes

Re-enable WDT

Interrupt Mode

SLEEP

Set Wakeup Flag

Continue

Section from main code

where entering sleep

Содержание AVR132

Страница 1: ...ous damage to its surroundings Automatic handling and recovery of such cases is the job of a watchdog timer The Enhanced Watchdog Timer WDT runs independent of the rest of the system causing system re...

Страница 2: ...age 3 shows what happens when a WDT timeout occurs The dotted boxes describe actions performed by the system The solid lined boxes describe actions to be performed by the application When using the En...

Страница 3: ...tion path through the main loop of your application This includes expected interrupt handlers as well If your main loop is very large several checkpoints could be inserted inside the loop to allow a s...

Страница 4: ...period The Everything ok check at the end of the loop is the part of the loop deciding whether the application is operating correctly or not One solution is to use flags that are set in different part...

Страница 5: ...to WDT System Reset The Write Complete Flag could be a byte in EEPROM indicating whether the backup operation was finished before the system reset This flag is checked in the startup code if the WDT...

Страница 6: ...3V supply voltage An example on how to use the WDT as a wakeup source is shown in Figure 4 Figure 4 Using the WDT as a Wakeup Timer If periodic wakeups are preferred the disabling of the WDT Interrupt...

Страница 7: ...pt or a timeout warning interrupt An example interrupt handler is shown in Figure 5 Figure 5 Dual purpose WDT Interrupt Handler Note that the wakeup flag must be set manually prior to entering sleep m...

Страница 8: ...safe state or at least be able to supply some debugging information to the operator Changing the WDT Configuration To prevent accidental changes to the WDT configuration special timed sequences are n...

Страница 9: ...igure 7 Figure 7 Circuit Diagram for Application Example The examples demonstrate the following concepts Using the WDT as a system reset source Using the WDT as a Wakeup Timer Using the WDT as a combi...

Страница 10: ...dashed frames are only used in the Combined Operation code example and are described later Figure 8 Initialization Routine When Using the WDT as a System Reset Source Any res et f lags s et Initializa...

Страница 11: ...uman operator to manually reset an application that has been halted by too many WDT System Resets The opera tor must of course try to find the source of the WDT System Resets before resetting Blindly...

Страница 12: ...in the switch block Execute Command In this routine the command code decides which action to perform Command 1 has no particular action but it keeps the main loop running healthy by being a valid comm...

Страница 13: ...loop of this example flashes the LED connected to PB0 10 times to show that it is awake It then resets the WDT enables the WDT Interrupt Mode and enters sleep mode When the WDT times out it wakes up t...

Страница 14: ...decides what action to take If it is already cleared an error has occurred and the failure LED is lit The rest of the interrupt handler implementation complies with the flowchart The rest of the code...

Страница 15: ...9F Tonetsu Shinkawa Bldg 1 24 8 Shinkawa Chuo ku Tokyo 104 0033 Japan Tel 81 3 3523 3551 Fax 81 3 3523 7581 Memory 2325 Orchard Parkway San Jose CA 95131 USA Tel 1 408 441 0311 Fax 1 408 436 4314 Mic...

Отзывы: