Simplest watchdog circuit
william chan
Posts: 1,326
Hi guys,
How to design a simple watchdog circuit that will send a 1 sec negative pulse every 5 mins ( approximately ) to a microcontroller to reset it.
Assuming we using a RC charging circuit with a comparator, we can feed the dog by periodically dumping the charge in the capacitor via by a pin of the microcontroller.
How to make the comparator output a 1 sec pulse and then discharge the capacitor once the threshold is reached?
As comparators are cheaper than the 555, I would prefer to use the comparator.
How to design a simple watchdog circuit that will send a 1 sec negative pulse every 5 mins ( approximately ) to a microcontroller to reset it.
Assuming we using a RC charging circuit with a comparator, we can feed the dog by periodically dumping the charge in the capacitor via by a pin of the microcontroller.
How to make the comparator output a 1 sec pulse and then discharge the capacitor once the threshold is reached?
As comparators are cheaper than the 555, I would prefer to use the comparator.
Comments
How much cheaper than 4 cents can they be?
http://www.ebay.com/itm/40Pcs-NE555P-555-DIP-8-IC-Timer-Chip-Replacement-Parts-for-Warning-Alarm/111797057489
http://www.ebay.com/itm/40-Pcs-Black-NE555P-555-DIP-8-IC-Timer-Timers-Chip-Through-Hole-Mounting-/281827776834
What mcu is it?, many have a watchdog.
could power gate it, save battery juice as a feature too.
http://www.ti.com/product/tpl5110-q1
Unfortunately both sellers do not ship to Malaysia.
It is currently for the Pi3B, but i hope to later use it for the Propeller as well.
Not because I think our software will be hanging up all the time.
But because the system it sits in consists of units not made by us that we have little experience of. If any of the communications links in and out of there fail I want to cut the power to the whole thing and start again.
To that end we have power supplies with control inputs to cut the power. I just need a little "thing" to do that when it looks like things have gone TU.
Trying to get 5 mins in a RC will be an exercise in frustration, as you chase leakages - nA will matter.
If you want DIY, for long time intervals you need a CMOS input comparator. Or, instead of a comparator, use cheap and available CMOS logic gates. Logic gates can be configured as a resettable astable oscillator. A 5 minute RC circuit requires something like a 30 megaohm resistor with a 10µF capacitor. You can probably build it with a quad CD4001 NAND gate. Another option is the CD4060 oscillator+counter chip.
If you have the means to program it, the PIC chip running on its internal oscillator would be a slam dunk, or how about a BASIC Stamp 1 as a watchdog?
My favorite little chip at present is the 12F1572 with UART and 10-bit ADC etc in a tiny 8-pin MSOP package. Runs at 32MHz internal and cost around 50 cents.
The 10uF capacitor is to control the reset pulse width.
The I/O pin of the micro-controller periodically sets the pin to output and pull down to discharge the capacitor and then set back to input.
The micro is unlikely to hang during this DirOutput->PullDown->DirInput sequence.
This circuit is almost complete except for the initial power-up handling.
How to make sure that the 47uF capacitor is in a discharged state when power is first applied?
You could look at resistor-equipped transistors/ digital transistors / prebiased transistors
A series C into the base, avoids static-lockout possibilities, and you place one on CAP discharge and one on MCU reset, to make both short-acting paths.
Then, you make an ASTABLE oscillator from lowest power COMP/opamp you can find, like Fig 5 here
https://www.maximintegrated.com/en/app-notes/index.mvp/id/724
I agree with jmg about the astable comparator circuit. The positive feedback can be asymmetrical, so the reset pulse is a tiny fraction of the interval.
The output starts high and the capacitor charges through R3 (in series with R4 because you comparator is open collector). Your i/o pin can turn to low output to discharge the capacitor back to zero through the resistor R7 to limit the discharge current.
The threshold is set at a high voltage by the divider network with positive feedback from the output. If the capacitor hits the threshold, the output goes low and pulls the threshold low also due to the positive feedback. The capacitor discharges relatively rapidly through the diode and R5, down to that lower threshold, during which time the µP is in reset.
(It is sooo much simpler with the dedicated chip, or the PIC! The PIC has its built in fairly accurate RC oscillator. Zero external parts needed.)
You have given the correct circuit! The hysteresis feedback is ingenious!
The only problem i could think of is that during initial power up, if the capacitor is still holding substantial charge, it might reset the controller too early.
For example, the Pi3B takes about 50 secs to boot up, then only is it able to start feeding the dog.
How to ensure that the capacitor gets discharged fairly quickly when power is disconnected?
PS: I have no experience in PIC and have no PIC programming tools.
Anyhow, rather than going into the minute detail of implementing watchdog circuits I'd rather ask you the question: Why do you need to generate a reset every 5 minutes (btw, that's not a watchdog since you can't hold it off from firing)
Whenever we "feed the dog", we are holding it off from firing the reset. It is a full fledged watchdog in all sense of the word.
This is accomplished by the I/O pin dumping the charge from the capacitor periodically.
Actually 2 to 3 minutes watchdog timeout is what we really need, as long as it is longer than the 50sec Pi boot time.
Although a PIC circuit may be simpler, it may cost more.
A comparator can cost as little as USD 0.04 each in 100 pcs qty as can be seen below, and passive parts are really cheap.
http://my.rs-online.com/web/p/comparators/8287551/
Thanks to Tracy Allen and JMG for their ingenious input.
Notes:
1. The Diode 1N4448 is chosen because of it's low leakage
2. AS393 comparator is chosen because of it's low leakage and low price
3. If you purchase the high value ceramic 47uF capacitor from Japan, they will ask you what you want to use it for.
This is due to Japan govt export restrictions for new hi-tech parts. Just say it's for your dog. ( joking )
5. If you use the watchdog for a Propeller chip, you can set to a lower timeout of 1 minute or less by using a smaller capacitor like 10uF.
6. The microcontroller can reduce the 2nd and subsequent timeout by controlling the charge dumping time.
The more charge is dumped, the longer the timeout.
I have realized that concern about the initial charge amount in the 47uF capacitor at power up is not a big issue.
Even if the micro-controller was wrongly reset during the first boot ( after power up ),
the second boot will be ok as the capacitor would then be fully discharged after the first reset.
Hi Peter,
When i mentioned "Simplest", i actually meant "Cheapest". Sorry.
Of course we currently only manufacture in small quantities, but we always hope for a bigger future.
-Phil
+1
You also need to analyze the WDOG, for what happens in cases of a FEED pin stuck hi or low ?
ie for a MCU that needs WDOG reset, imagine it can freeze in any pin State.
Then, does your WDOG still work ? (hint: the answer is no)
The quote usually comes the same for different board versions.
Yes, i do agree that if the FEED pin is stuck in low output, this watchdog will fail.
But this would be extremely rare, as the feeding normally occurs only once per minute and completes in about 3ms.
No circuit is perfect.
Seems this design does not need to pass any formal review process ?
The whole premise behind a WDOG design, is to catch extremely rare occurances.
I've no idea where you got the glib "No circuit is perfect." idea from, as a circuit certainly can perform a design task properly.
1. Set Feed Pin to Low
2. Set Feed Pin as Output
3. Delay 1ms
4. Set Feed Pin as Input
The possibility that it would hang between items 2 to 4 is about the same as the possibility that a PIC watchdog chip would also hang.
Reasons could be due to cosmic photons etc.
This is what i meant when i said that no watchdog is perfect.
When I cannot decide which is the best solution then sometimes I allow for both solutions on the pcb and just populate one. This costs nothing. So you could for instance have your comparator circuit but allow for a tiny SOT23 or 8-pin MSOP PIC footprint. Now if it becomes clear that the comparator circuit won't cut the mustard, then you can easily drop in a PIC without redoing your boards. As a smart watchdog you can send serial data to it to tell the watchdog that the main CPU is alive and kicking. Any corruption or stuck signals would not fool such a watchdog and it is highly precise without the need for external timing elements or a "47uf ceramic cap" which would not be very precise in the slightest if you happen to do your calculations in that respect.
Food for thought.