CLRWDT System
Clear the watchdog timer so it doesn't reset the PIC.
| Syntax | CLRWDT |
|---|---|
| Operands | none |
| Operation | 00h → WDT, 0 → WDT prescaler, 1 → TO, 1 → PD |
| Status bits | TO PD |
| Words / cycles | 1 word, 1 cycle |
| Encoding | 00 0000 0110 0100 |
How it works
When the watchdog is enabled in the configuration word, it resets the PIC unless the program clears it regularly. Its nominal time-out is 18 ms, multiplied by the prescaler when OPTION_REG assigns the prescaler to it (PSA = 1, up to 1:128).
CLRWDT restarts the watchdog (and its prescaler) and sets TO and PD. Put it in the main loop so a program that hangs gets reset.
Example
; CLRWDT example from picsimulator.com/instructions/clrwdt.html
list p=16f84a
include <p16f84a.inc>
__CONFIG _CP_OFF & _WDTE_ON & _PWRTE_ON & _XT_OSC
org 0
loop:
clrwdt ; feed the watchdog every pass
goto loop
With the watchdog enabled, remove the CLRWDT and the simulator reports a watchdog reset after the time-out.
Open this example in the simulator
Watch out for
- Clearing the watchdog from inside a timer interrupt defeats it: the interrupt can keep running while the main loop is stuck.