PDA

View Full Version : Watchdog Timer Question



kevj
- 16th March 2008, 21:04
My application requires long periods of sleep until an input is received (may be hours or weeks) - using RA2 wake on interrupt for this, and have WDT disabled to keep it from waking the Pic.

However, sometimes the Pic is freezing up. Running a 16F616 via external oscillator at 20mhz, 5v supply. Works great 99% of the time, but when it does hang, it's a real problem.

I know that's what the WDT was really designed to do, but not sure how it really does it. Here's what I want the Pic to do....

1) If WDT times out during sleep - wake in the same spot of code (just like RA2 had generated the interrupt), check and see if it woke up because of RA2 or because of WDT. If WDT, then clear the bit and go back to sleep, if wake by RA2, continue on...

OR (and this is the really important one I'm not sure I really understand)

2) If the oscillator failed or the Pic hung, to generate a Power On Reset (or equivilant), basically, I want it to re-boot as if the power had been turned off and on and start fresh over.


I'm not sure how it determines one of those 2 actions, and if it does reset due to a hang, if it really is a "complete" reset (like a POR would be)

Thanks!

skimask
- 17th March 2008, 01:13
However, sometimes the Pic is freezing up. Running a 16F616 via external oscillator at 20mhz, 5v supply. Works great 99% of the time, but when it does hang, it's a real problem.
Do you have the Power up timer turned on in the config bits?


I'm not sure how it determines one of those 2 actions, and if it does reset due to a hang, if it really is a "complete" reset (like a POR would be)
Apparently this PIC only directly differentiates between a Power On Reset and Brown Out Reset in the PCON register.
But if you look around the datasheet, you'll find a number of registers that are zero'd out differently depending on the type of reset, such as ANSEL. On any reset, it's set to all 1's.
And in the datasheet, it's states that during normal ops, a WDT reset, resets the chip like MCLR had been pulled down. But, if you put the PIC to SLEEP, a WDT causes the PIC to pick up where it left off without changing registers like a 'normal' reset would.

sougata
- 17th March 2008, 01:56
Hi,

The Status register contains two bits :

1. Time Out (bit4)
2. Power Down (bit3)

A watchdog timer wakeup would cause the timeout to be zeroed.

I didn't really get the hung part of your question. Is it no wakeup even after RA2 interrupt or hung in the mid of your app.Oscillators are turned of during the sleep mode (so your osc program counter, timer dependent on osc all freezes) the next instruction is prefetched. WDT has its own oscillator (internal RC). It could be startup problem for your crystal may be a 10Meg resistor between its legs would help or different cap values. Also use the powerup timer if your wake up event is not that time critical.