Shop OBEX P1 Docs P2 Docs Learn Events
Simplest watchdog circuit — Parallax Forums

Simplest watchdog circuit

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.
«13

Comments

  • This sounds like it is more of a "better reset a really buggy circuit constantly" rather than a real watchdog. For starters a 1 second pulse is probably at least 1,000 longer than it needs to be, doesn't it matter that it can go on a lunch break and not attend to its duties? If its every 5 mins then you just need a better circuit and software in the first place. I haven't found it necessary to employ a low-level watchdog in many many years, and my stuff is operating in all kinds of harsh and critical environments. Besides, being suddenly reset in the middle of operation would prove disastrous, imagine if you were flying a plane and then suddenly the control systems cut out for 1 second, every 5 minutes, or worse still, during take off or landing. Anyway I'd rather use a 30 cent PIC chip as a smart watchdog in place of a 25 cent comparator anyday.
  • ercoerco Posts: 20,244
    edited 2017-05-05 14:14
  • >to a microcontroller to reset it.

    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
  • tonyp12 wrote: »
    >to a microcontroller to reset it.
    What mcu is it?, many have a watchdog.

    It is currently for the Pi3B, but i hope to later use it for the Propeller as well.
  • Heater.Heater. Posts: 21,230
    Just now I'd like a watch dog 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.


  • jmgjmg Posts: 15,140
    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.
    .
    At those timescales, you are probably better off with a CMOS CD4541 or CD4521.
    Trying to get 5 mins in a RC will be an exercise in frustration, as you chase leakages - nA will matter.
  • There are a host of watchdog ICs available that make the circuit simple. For example, the TLP5010 would be set to 5 minutes by a 42kohm programming resistor. The microprocessor has to feed the dog a pulse within each programmed interval, and if it fails to do so the chip (a 5-pin SOT23) generates a reset pulse. That chip be unobtainium in Malaysia.

    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?

  • I have found these small 12F series PIC chips to be super reliable and have used them for simple and accurate timing and also as bootstrap watchdog or smart watchdog. I have the PIC monitor the receive line looking for a particular sequence so that I can instruct it over remote lines to reset the system or put it in program mode etc. Of course it is nothing to have it operate as a custom watchdog and if you set it to reset the system every 5 minutes regardless of whether the system is working or not, then it would do that accurately and reliably, without any need for crystals or RC timing etc.

    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.
  • I was thinking that the circuit should take this form
    1148 x 680 - 122K
  • By using a high value 47uF ceramic which is available now, the RC current can be increased to uA range.
    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?
  • There is a 10k pull up resistor at the reset pin which i forgot to draw.
  • jmgjmg Posts: 15,140
    B
    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?
    Normally it is 'mostly' discharged when power cycles.
    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
  • Tracy AllenTracy Allen Posts: 6,656
    edited 2017-05-06 20:11
    William, I don't think that circuit above will work. Have you tried it to prove me wrong? After the first cycle, I see it going into oscillation with the 47µF capacitor voltage hanging near the comparator threshold and the 10µF capacitor hanging near the transistor threshold, a rapid cycle of resets.

    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.
  • Tracy AllenTracy Allen Posts: 6,656
    edited 2017-05-06 20:24
    Here is an example of an asymmetrical astable.

    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.)


  • Hi Tracy,

    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.
  • PICs are so simple to program in C or assembler and for a simple but custom watchdog even the assembler code would only be a handful of lines long.

    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)
  • 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/
  • So how many millions of these are you going to make where 10 cents worth of parts plus pcb real estate outweigh 50 cents. In small quantities it doesn't make much sense to try to shave off cents from a design when you can do it better and easier by spending those few cents. So the other question is: Are you asking for the simplest because it is the cheapest because this is for a high volume item?
  • For the benefit of those who are interested, i present here the final Simple WatchDog Circuit with all the values included.
    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.
    1029 x 661 - 126K
  • So how many millions of these are you going to make where 10 cents worth of parts plus pcb real estate outweigh 50 cents. In small quantities it doesn't make much sense to try to shave off cents from a design when you can do it better and easier by spending those few cents. So the other question is: Are you asking for the simplest because it is the cheapest because this is for a high volume item?

    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.
    :D
  • Don't forget that you're paying your assembler for every part that gets placed on the board. Although the parts themselves may cost pennies, reducing overall costs by sourcing fewer, but perhaps more expensive components, can save money in the end.

    -Phil
  • Anyway I'd rather use a 30 cent PIC chip as a smart watchdog.

    +1

  • jmgjmg Posts: 15,140
    When i mentioned "Simplest", i actually meant "Cheapest". Sorry.
    What do you pay pre-placement for assembly ?

    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)

  • jmg wrote: »
    What do you pay pre-placement for assembly ?
    Normally the vendor just give a lump sum quote after viewing the sample board.
    The quote usually comes the same for different board versions.
    jmg wrote: »
    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)

    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.
  • jmgjmg Posts: 15,140
    jmg wrote: »
    What do you pay pre-placement for assembly ?
    Normally the vendor just give a lump sum quote after viewing the sample board.
    The quote usually comes the same for different board versions.
    Even then, you can still get a representative cost-per-part price. More parts do cost more money
    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.

  • Consider a scenario where a Propeller cog calls a subroutine that does the following
    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.
  • I hope you don't think I'm trying to talk you out of doing it the "cheapest" way but we like to throw our 2 cents worth in since this is being discussed on an open forum. If this doesn't work properly it may mean that you need to scrap you boards and issue a revision. This is not cheap nor desired. If you happen to spend a few more cents now and do it right, whichever way you do it, then it will work and you can always redesign and test new prototypes when those big orders come rolling in. Don't cripple the design, address the immediate need.

    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.
Sign In or Register to comment.