Corne Smith said:
> I've got a basic question that I still don't understand.
>
> What is the wachdog timer used for ?
> I know it is used to reset the PIC,but why ?
In case your code goes in the weeds, then the watchdog timer pulls it back
in.
This could be due to noise or perhaps even a bug in your program. It is a
"safety" precaution.
The theory is that if the watchdog doesn't get reset, then the processor
isn't executing the right code.
Corne Smith wrote:
>
> Hi dudes
>
> I've got a basic question that I still don't understand.
>
> What is the wachdog timer used for ?
> I know it is used to reset the PIC,but why ?
>
> Cheers
>
> Corne
Just in case your code goes pear shaped. if it dont get a "nudge" every
so often then there is a good chance that your appplication has hung or
is running out of control. Under these situations then the WD timer can
be used to reset the CPU to a known state to enable your system to
recover.
--
Cheers Peter ..........
==================================
New Ideas come from those who
didn't know it wasn't possible
==================================
Others have described its main use, but I have used it in the
past time time out serial communication so you are not stuck in
an endless loop.
For example, if another processor is clocking serial data to
a PIC in a manner similar to I2C, you might have code that
looks a bit like:
movlw .8
movwf bitctr
q btfss porta, 0 ; wait for a high then read the data in
goto $-1
read the databit into a register
btfsc porta, 0 ; wait for a low before continuing
goto $-1
decfsz bitctr
goto q
If, for whatever reason, the other processor sends less than 8
bits, the code would be stuck in an endless loop never leaving this
section of code.
However, if the watchdog is enabled, it will reset the after 18ms
(more with the pre-scaler) and as the PIC allows you to differentiate
between a POR reset and a watchdog reset, you can take appropriate
action.
On Thu, 20 Mar 1997 14:11:39 +0200 Corne Smith
<.....csmithKILLspam.....WPSMTP.AVITRONICS.CO.ZA> writes:
>Hi dudes
>
>I've got a basic question that I still don't understand.
>
>What is the wachdog timer used for ?
>I know it is used to reset the PIC,but why ?
>
>Cheers
>
>Corne
>
I think it's because ALL computers will crash, it's just a
question of how long it will be until they crash. The watchdog timer
detects the crash and resets the system. This compares favorably to a
system I put in Kansas ten years or so ago where I had to drive over 100
miles to press the reset at a remote FM transmitter site. Now,
EVERYHTING I do includes a watchdog!
Another post asked why the watchdog kept resetting his PIC even
though he had CLRWDT in his code. It IS important that the CLRWDT be
executed BEFORE the WDT times out. It's pretty common to put a CLRWDT at
ONE PLACE in the main program loop so if the processor doesn't make it
around to there at least every so often, we assume the thing crashed and
reset it. If the main loop has a smaller loop inside it that keeps the
main loop from being completed in time, you can get a WDT timeout. I had
this happen because of loops I put in to allow for A/D settling time.
Finally, CLRWDT should NOT be put in an interrupt service routine
since sometimes the main program can crash, but interrupts keep running
fine.
The two flags may be set in different parts of the code; your interrupt
handler may also do some "faster" watchdogging of its own. For example, if
your inner loop should run at least once every interrupt, you could do:
Interrupt:
btfss ImOkFlag
goto Oops
...
Oops:
movlw 0
option ; Set minimum watchdog time
goto $ ; Wait for watchdog
In this case, you could use a fairly slow timeout on your outer loop and still
tell quickly if your inner loop failed. Alternatively, you could do something
like:
In this case, your interrupt would keep the watchdog happy as long as the
interrupt was running happily, but if the main loop died for 256 interrupt
times the system would restart.