electromanj
11-23-2010, 12:26 AM
Hello all, I want a watchdog timer in case a project locks up. I want to keep it simple so I used an RC circuit where the capacitor gets recharged at the beginning of each method and if not the resistor discharges and either the prop senses a low input or you could reset the prop all together. The circuit is as follows:
P2 |( Vss
-^^-
Sorry about the schematic I tried to draw it in prop tool but couldn't remember how.
P2 is connected to the positive pin of a 1000uf electrolytic capacitor. The negitive pin is connected to VSS. A 51K ohm resistor is paralleled to the cap between P2 and Vss. (gives about 42 seconds of time delay.)
P2 is set to output, then P2 is set to input and looks for a low signal.(Capacitor is discharged).
Here is my test code.
CON
_clkmode = xtal1 + pll16x ' use crystal x 16
_xinfreq = 5_000_000 ' 5 MHz cyrstal (sys clock = 80 MHz)
Pub setup
dira[11]:=1 'set p11 to output
outa[11]:=1 'turn on led
waitcnt(clkfreq*2+cnt) 'wait 2 seconds
outa[11]:=0 'turn off led ====checking that led is operating
dira[2]:=1 'set p2 to output
outa[2]:=1 'set p2 high to charge cap
waitcnt(clkfreq*1+cnt) 'wait one second
outa[2]:=0 'set p2 low,cap should be charged
dira[2]:=0 'set p2 to input
repeat until ina[2]==0 'wait for p2 to see cap is discharged
blinker 'go to blinker
pub blinker 'blinker method: this would normally reset prop or return to a main method
repeat 50 'blink led 50 times
outa[11]:=1 'set p11 high turn led on
waitcnt (clkfreq/5+cnt) 'wait 1/2 second
outa[11]:=0 'set p11 low turn led off
waitcnt (clkfreq/5+cnt) 'wait 1/2 second
I have a few questions:
1. I am charging the cap really fast. Is that going to be a problem with current on P2? Do I need to add a series resistor to limit the current?
2. Could I reset the prop safely with another I/O pin, such as If P2== 0, P3==0 with P3 connected to the res pin?
3. Is it OK to use the same I/O pin to charge the cap and then sense the discharge, or am I being an overachiever?
Thanks for any help.
P2 |( Vss
-^^-
Sorry about the schematic I tried to draw it in prop tool but couldn't remember how.
P2 is connected to the positive pin of a 1000uf electrolytic capacitor. The negitive pin is connected to VSS. A 51K ohm resistor is paralleled to the cap between P2 and Vss. (gives about 42 seconds of time delay.)
P2 is set to output, then P2 is set to input and looks for a low signal.(Capacitor is discharged).
Here is my test code.
CON
_clkmode = xtal1 + pll16x ' use crystal x 16
_xinfreq = 5_000_000 ' 5 MHz cyrstal (sys clock = 80 MHz)
Pub setup
dira[11]:=1 'set p11 to output
outa[11]:=1 'turn on led
waitcnt(clkfreq*2+cnt) 'wait 2 seconds
outa[11]:=0 'turn off led ====checking that led is operating
dira[2]:=1 'set p2 to output
outa[2]:=1 'set p2 high to charge cap
waitcnt(clkfreq*1+cnt) 'wait one second
outa[2]:=0 'set p2 low,cap should be charged
dira[2]:=0 'set p2 to input
repeat until ina[2]==0 'wait for p2 to see cap is discharged
blinker 'go to blinker
pub blinker 'blinker method: this would normally reset prop or return to a main method
repeat 50 'blink led 50 times
outa[11]:=1 'set p11 high turn led on
waitcnt (clkfreq/5+cnt) 'wait 1/2 second
outa[11]:=0 'set p11 low turn led off
waitcnt (clkfreq/5+cnt) 'wait 1/2 second
I have a few questions:
1. I am charging the cap really fast. Is that going to be a problem with current on P2? Do I need to add a series resistor to limit the current?
2. Could I reset the prop safely with another I/O pin, such as If P2== 0, P3==0 with P3 connected to the res pin?
3. Is it OK to use the same I/O pin to charge the cap and then sense the discharge, or am I being an overachiever?
Thanks for any help.