piclist 1999\10\24\214601a >
Thread: WDT (was: PIC Wierdness)
picon face BY : Thomas Brandon email (remove spam text)

The WDT appears to be one of the most misunderstood parts of a PIC (or
Scenix). The basic idea of the WDT is to allow you to detect logical failure
of your system and trigger a reset. The WDT is a timer that like the other
timers increments every x instruction where x is the value fo the prescaler.
However where other timers generate an interrupt on overflow from 0xFF (255)
to 0x00 (0). Hence with a 10MHz clock and prescaler of 1:1 would increment
every inst. (10MHz = 2.5MIPS = 400ns). Thus it would take 256 inst. (256 *
400 = 102.4us) to rollover. Hence, if you don't clear the WDT (with CLRWDT)
every ~100us, the MCU will generate a reset.

I'm not exactly sure why Jason used the WDT for his timing if he had a
CLRWDT in every routine. I would have thought using TMR0 to generate an
interrupt on overflow would have been easier in terms of not having to keep
track of when CLRWDTswere executed.

The general use of the WDT is to generate a reset when the devices enters an
unknown state and thus fails to function correctly. For instance, if you
have a device that is recieving serial communications, you could use the WDT
to reset communications if the device lost synchronisation for a given
period. In this case you could set the WDT prescaler to overflow at the
maximum time without synchronisation. You would then add a CLRWDT at a point
that was only executed when synchronisation was present (e.g. when the stop
bit was checked indicating succesful transfer). Thus the WDT would only be
reset when synchronisation was present, so if you lost sync. for more than
the overflow time of the WDT, a reset would automatically be generated.
Then, the reset code would have a routine to reset tyhe serial channel
allowing sync to be reestablished.

However, if CLRWDT's are scattered throughout the code it is difficult to do
anything useful with the WDT. The main problem is if multiple routines are
resetting the WDT within th e appropriate period, they must all go wrong for
the reset to occur. For instance, if you added a CLRWDT to the recieving
routine of the above example. Now, recieving may not be occuring but as it
continues to send data a reset is never generated. Hence, care must be
exercised when using a WDT to detect multiple critical failures as one
section may fail but fail to create a long enough delay to generate a reset.

{Original Message removed}
<014901bf1e8a$f90f8fd0$09255e81@psy.unsw.edu.au> 7bit

See also: www.piclist.com/techref/microchip/devices.htm?key=pic
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) WDT (was: PIC Wierdness)

month overview.

new search...