8

I recently learned about watchdog timers, and am trying to implement one for my circuit for the purpose of resetting my (AVR) microcontroller if it hangs (i.e., doesn't respond to the watchdog).

Based on some research, it appears to me that there are around four options:

  1. Connect my microcontroller with an external dedicated watchdog-timer-specific IC.
  2. Connect my microcontroller with an additional microcontroller (some very basic, inexpensive one), the latter coded for the sole dedicated purpose of watchdog-timing.
  3. Lay out my own 555-timer-based watchdog circuit and connect it to my microcontroller.
  4. Use the internal watchdog timer capability on my microcontroller.

.

Which of the above approaches would you rank higher and why?

I would like to set a watchdog time of around 6 seconds, based on certain criteria for the way I'm making the rest of my design and code (the device will be a battery-powered, periodic temperature logger).

A little note: My preference would be Option 1, for simplicity, however, based on the couple I have found, these parts either appear to be expensive (I'd like a solution under 1.25 USD at most), or only allow only less than 2 seconds for the watchdog timing period.

Brian Carlton
  • 13,252
  • 5
  • 43
  • 64
boardbite
  • 4,892
  • 11
  • 47
  • 73
  • 1
    4) is cheap and simple. Is your objection only that you can't set it to 6 seconds? That's quite a long time by microcontroller standards – pjc50 Oct 12 '12 at 16:47
  • 1
    @pjc50: It is definitely cheap :) And even the 6-second timing is possible I believe. However, articles like [this one](http://www.ganssle.com/watchdogs.htm) suggest that the internal watchdog may not be as robust as a dedicated external one. And the reason for the 6 second time is, on my microcontroller, I have an Arduino bootloader which includes a wait time of 4 seconds on first start. (I could learn to re-program this but that is still on my learning curve) – boardbite Oct 12 '12 at 16:53
  • 1
    You should definitely fix the bootloader. The 4 seconds of waiting are 4 extra seconds of battery consumption which you can get rid of. Instead of waiting, have it e.g. sample a dedicated pin which is pulled down when in deployment. – Igor Skochinsky Oct 12 '12 at 16:58

3 Answers3

14
  1. More expensive, as you already found out. But it should give you the highest level of reliability: because the watchdog is completely independent of the microcontroller it will still keep running, and reset the microcontroller when the latter is on fire, so to say. See 4)
  2. Brian is against it, but there are cheap microcontrollers in a small package, like the PIC10F200 in SOT-23, which you can use as a retriggerable MMV (monostable multivibrator), which the watchdog actually is. If you would consider a 555, a 10F200 is better: no external parts, and more accurate timing (1% accuracy).
  3. a 555? Seriously?
  4. The internal watchdog will do if the dedicated IC is too expensive. If you're really paranoid you can think of a scenario where some hardware error will lock up the microcontroller and the watchdog with it. I've never known this happen, but I don't know how well you sleep.

Like pjc50 says 6 seconds is a long time. A typical microcontroller will execute tens of millions of instructions in that time, and then a lot can go wrong. Suppose you're controlling some load with PWM, and a low 10 % duty cycle keeps the dissipation low. Microcontroller goes bananas and the output gets stuck at a high level, 100 % duty cycle. The load doesn't like it, and dies. You don't want to wait 6 seconds for that to happen. There should be some part of your code where you pass much more frequenct. A main loop may be as short as 10 ms, then you could set the watchdog's timeout at 100 ms, for instance. If you kick the dog once every 10 ms, then a timeout means that you missed it 10 times! Once, OK, but ten times is disaster, and you have to take action. The load will be switched off after 100 ms instead of 6 seconds, which may be the difference between dead or alive.

stevenvh
  • 145,145
  • 21
  • 455
  • 667
  • 2
    @Nick - Nice that you like it, but actually I *did* spend more time writing the rest of the answer :-). – stevenvh Oct 12 '12 at 17:29
  • 1
    What's wrong with 555 timers? :) – Justin ᚅᚔᚈᚄᚒᚔ Oct 12 '12 at 19:16
  • 3
    @Justin - There are people for whom a 555 is religion: you can solve all world problems and then some with a 555. Well, a 555 is quite versatile, typical applications are monostable and astable multivibrators, PWM, but it's not the best for everything. In [this question/answer](http://electronics.stackexchange.com/questions/34975) OP spend a couple of weeks to design a 555 circuit for a task which isn't made for. The same job could be programmed into a microcontroller in an hour. I'm not questioning OP's skills here nor his approach, as I understand it he *had* to use a 555... – stevenvh Oct 13 '12 at 15:40
  • @Justin (continued) ... but stepping back a few steps will get you other solutions which may be better. Here a PIC10F200 microcontroller is a 1 component solution, which you can program to any advanced WDT protocol you want. One of the few advantages the 555 has over a microcontroller is that it can operate at higher voltages, like 12 V, but here 5 V is available anyway, so that doesn't count. For the rest: **there is absolutely no 555 application a microcontroller can't do better**, with less parts, more accurate and with higher repeatability. 555 cheaper? Yes, unless... – stevenvh Oct 13 '12 at 15:45
  • @Justin (continued) ... you need a 1% accurate timing. Ever purchased a 1% X7R capacitor? That alone is more expensive than the microcontroller which runs on an internal oscillator calibrated to 1 %! – stevenvh Oct 13 '12 at 15:47
  • 2
    Every time someone uses words like "absolutely" I feel compelled to find a counter-example. In this case: A microcontroller is more sensitive to cosmic rays and radiation than a 555, so IMO in some applications a 555 would be preferable in terms of reliability. – apalopohapa Oct 14 '12 at 11:10
  • 2
    @apalopohapa - I stand corrected. In spacecraft 555s may be a better choice than microcontrollers. Of course, computers made of 555s are (guesstimate) *15 orders of magnitude less accurate*, larger, more power hungry, and not so easy to program in C++ or Ada... :-) – stevenvh Oct 14 '12 at 17:27
  • 555s are definitely my weapon of choice for building spacecrafts ;). On a more down to earth case, my overall point is mtbf. e.g for a failsafe I'd rather look for the simplest design with lower overall mtbf, which usually excludes the complexity of a uC. In fact, sometimes those failsafes are in case a uC fails (in spite of a wdt). – apalopohapa Oct 14 '12 at 18:15
  • I imagine 555s are more popular amongst submarine and fission reactor control circuit engineers as well. :) Thanks for the response, Steven. After a brief foray into electronics as a kid (thanks Tandy), I'm just now beginning to learn beyond "build this pre-designed circuit", so perspective on the pros/cons of various approaches is always welcome. – Justin ᚅᚔᚈᚄᚒᚔ Oct 15 '12 at 14:00
5
  1. Watchdog timer is simple, works, cheap. Ovbious choice.
  2. An additional microcontroller is overkill. It isn't helpful since you have to program it, it is more expensive, more area.
  3. This makes sense. But I would do 1 instead. More modern.
  4. I would use this if it works. They only question is can it be set to 6 seconds.
Brian Carlton
  • 13,252
  • 5
  • 43
  • 64
  • Thanks for the comparison. The only thing though is that #1 does not appear to be cheap! I haven't found any watchdog-timer-capable IC with quantity-pricing less than a dollar as I mentioned, whereas as you probably know, there are many microcontrollers (for option #2) that are less than USD 0.50. – boardbite Oct 12 '12 at 16:51
2

If your circuit/device is not controlling life-critical hardware, you can probably get away with using the internal watchdog. Otherwise (or actually, in any case) check out these two great articles from Jack Ganssle:

http://www.ganssle.com/watchdogs.htm

http://www.ganssle.com/articles/watchdogsredux.htm

By the way, if you can't set watchdog to long interval, you can try the approach of waking up often enough to kick the watchdog, but only going the full taking measurements/writing logs thing once in a while.

Igor Skochinsky
  • 996
  • 1
  • 7
  • 11