{"id":6901,"date":"2022-03-18T11:13:57","date_gmt":"2022-03-18T10:13:57","guid":{"rendered":"https:\/\/willem.aandewiel.nl\/?p=6901"},"modified":"2022-03-18T11:13:57","modified_gmt":"2022-03-18T10:13:57","slug":"external-hardware-watchdog-with-attiny85","status":"publish","type":"post","link":"https:\/\/willem.aandewiel.nl\/index.php\/2022\/03\/18\/external-hardware-watchdog-with-attiny85\/","title":{"rendered":"External Hardware Watchdog with ATtiny85"},"content":{"rendered":"\n<p>This post has 5,439 keer bekeken \/ views<\/p>\n\n\n\n<p>Sometimes the internal Watchdog Timer (WDT) of a MCU is working more against you than that it &#8216;helps&#8217; you. Also an internal WDT is not always up to the task of resetting the main MCU to a known state.<\/p>\n\n\n\n<p>Especially the ESP8266 has some quirks that makes it reboot for not-always-obvious reasons but fails to restart the MCU when needed. And if your house warming system depends on a &#8216;<em>twenty four seven<\/em>&#8216; working system the <em>External Hardware Watchdog Timer<\/em> (EHWDT) I describe in this post can be very handy.<\/p>\n\n\n\n<p>The objective is to have a means to monitor activity on a master processor, for instance, an ESP8266 (or ESP32 or any other type of processor). The master processor needs to have a &#8216;<em>hartbeat<\/em>&#8216; signal that can be fed to the EHWDT. This can be done by toggling a GPIO pin on- and off. For visible feedback you can add a LED to this GPIO pin so you can monitor the hartbeat.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><a href=\"https:\/\/willem.aandewiel.nl\/wp-content\/uploads\/2022\/03\/ATtiny85EWDT-1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/willem.aandewiel.nl\/wp-content\/uploads\/2022\/03\/ATtiny85EWDT-1.png\" alt=\"\" class=\"wp-image-6913\" width=\"447\" height=\"451\" srcset=\"https:\/\/willem.aandewiel.nl\/wp-content\/uploads\/2022\/03\/ATtiny85EWDT-1.png 893w, https:\/\/willem.aandewiel.nl\/wp-content\/uploads\/2022\/03\/ATtiny85EWDT-1-297x300.png 297w, https:\/\/willem.aandewiel.nl\/wp-content\/uploads\/2022\/03\/ATtiny85EWDT-1-150x150.png 150w, https:\/\/willem.aandewiel.nl\/wp-content\/uploads\/2022\/03\/ATtiny85EWDT-1-768x775.png 768w, https:\/\/willem.aandewiel.nl\/wp-content\/uploads\/2022\/03\/ATtiny85EWDT-1-50x50.png 50w\" sizes=\"auto, (max-width: 447px) 100vw, 447px\" \/><\/a><\/figure><\/div>\n\n\n\n<p>The master processor needs to send at least every\u00a0<code>_MAX_HALF_SECONDS<\/code>\u00a0seconds a &#8220;<em>Keep Alive<\/em>&#8221; pulse to the WatchDog [WDT-FEED] (a 3v3 signal is level-shifted by Q1 to [WDT] (PB2, DIL-7)). If the WatchDog does not receive this pulse in time it will make [ESP-RESET] (PB3, DIL-2) HIGH for 500 msec to reset the master processor. <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><a href=\"https:\/\/willem.aandewiel.nl\/wp-content\/uploads\/2022\/03\/ATtiny85EWDT_Reset.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/willem.aandewiel.nl\/wp-content\/uploads\/2022\/03\/ATtiny85EWDT_Reset.png\" alt=\"\" class=\"wp-image-6905\" width=\"464\" height=\"355\" srcset=\"https:\/\/willem.aandewiel.nl\/wp-content\/uploads\/2022\/03\/ATtiny85EWDT_Reset.png 619w, https:\/\/willem.aandewiel.nl\/wp-content\/uploads\/2022\/03\/ATtiny85EWDT_Reset-300x229.png 300w\" sizes=\"auto, (max-width: 464px) 100vw, 464px\" \/><\/a><\/figure><\/div>\n\n\n\n<p>In the image above you see a typical reset circuit for an ESP processor. [ESP-RESET] comes from the ATtiny85 (PB3, DIL-2). The Q3 MOSFET works as a level-shifter (if needed) and on a HIGH signal it will pull [RESET] down.<\/p>\n\n\n\n<p>PB4 (DIL-3) on the ATtiny85 is used to control (in this case) a relay but if you don&#8217;t need a relay you can remove this part of the circuit (Q2, R5 and R6). PB0 (DIL-5) outputs a signal to the [WDT-LED] (D2) which will, after every received &#8220;Keep Alive&#8221; pulse go &#8220;HIGH&#8221; for 500 milliseconds). <\/p>\n\n\n\n<p>Two seconds before the circuit will reset the master processor the PWM_LED will blink rapidly.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><a href=\"https:\/\/willem.aandewiel.nl\/wp-content\/uploads\/2022\/03\/ATtiny85EWDT_pins.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/willem.aandewiel.nl\/wp-content\/uploads\/2022\/03\/ATtiny85EWDT_pins.png\" alt=\"\" class=\"wp-image-6908\" width=\"574\" height=\"177\" srcset=\"https:\/\/willem.aandewiel.nl\/wp-content\/uploads\/2022\/03\/ATtiny85EWDT_pins.png 765w, https:\/\/willem.aandewiel.nl\/wp-content\/uploads\/2022\/03\/ATtiny85EWDT_pins-300x93.png 300w\" sizes=\"auto, (max-width: 574px) 100vw, 574px\" \/><\/a><\/figure><\/div>\n\n\n\n<p>You can find the source for the ATtiny85 WDT on <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/mrWheel\/ATtiny85WatchDog\" target=\"_blank\">github<\/a> as an Arduino Sketch.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Boot sequence:\n==============\n State       | REL_LED | SGNL_LED      | Remark\n ------------+---------+---------------+-------------------------\n<meta charset=\"utf-8\"> Power On    | Blink   | Blink         | <meta charset=\"utf-8\">Inverse from eachother\n             |         |               | <meta charset=\"utf-8\">Relays \"Off\"\n             |         |               | Next: \"Fase 1\"\n ------------+---------+---------------+-------------------------\n Fase 1      | Off     | 900 MS On     | repeat for 25 seconds\n             |         | 100 MS Off    | Relays \"Off\"\n             |         |               | Next: \"Fase 2\"\n ------------+---------+---------------+-------------------------\n Fase 2      | Off     | 500 MS On     | wait for 3 Feeds to pass\n             |         | for every     | Relays \"Off\" \n             |         | Feed received | Next: \"Fase 3\"\n ------------+---------+---------------+-------------------------\n Fase 3      | Off     | Blink Fast!   | wait for 3 Feeds to pass\n             |         | for 2 seconds | Relays \"Off\" \n             |         |               | Next: \"Normal Operation\"\n ------------+---------+---------------+-------------------------\n Normal      | On      | 500 MS On     | Relays \"On\"  \n Operation   |         | for every     | \n             |         | feed received | \n             |         +---------------+-------------------------\n             |         | Blink fast    | If no feed within 2 \n             |         |               | seconds: \n             |         |               | Next: \"Alarm State\" \n             |         |               | else: \"Normal Operation\"\n             |         |               | Relays \"On\"\n ------------+---------+---------------+-------------------------\n Alarm State | Off     | Off           | Relays \"Off\"\n             |         |               | Reset ESP8266\n             |         |               | Restart ATtinyWatchDog \n             |         |               | Next: \"Power On\" state\n ------------+---------+---------------+-------------------------  <\/pre>\n\n\n\n<p>During the &#8216;<em>power on<\/em>&#8216; fase there is some visible feedback during witch time the master processor needs to settle.  First the SGNL_LED and the REL_LED blink a few times. Then the REL_LED dims and the SGNL_LED blinks for 25 seconds. After that the EWDT waits for three hartbeat pulses from the master processor. Now &#8216;<em>normal operation<\/em>&#8216; is started and the EWDT is &#8216;<em>armed<\/em>&#8216;.<\/p>\n\n\n\n<p>If the SGNL_LED starts blinking fast it means that the master processor did not send a hartbeat for more than two seconds and both the master processor and the ATtiny85 will reboot.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post has 5,439 keer bekeken \/ views Sometimes the internal Watchdog Timer (WDT) of a MCU is working more against you than that it &#8216;helps&#8217; you. Also an internal WDT is not always up to the task of resetting &hellip; <a href=\"https:\/\/willem.aandewiel.nl\/index.php\/2022\/03\/18\/external-hardware-watchdog-with-attiny85\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[25,26,47,51,55,154],"class_list":["post-6901","post","type-post","status-publish","format-standard","hentry","category-uncategorised","tag-arduino","tag-attiny","tag-esp8266","tag-firmware","tag-hardware","tag-watchdog"],"views":5439,"_links":{"self":[{"href":"https:\/\/willem.aandewiel.nl\/index.php\/wp-json\/wp\/v2\/posts\/6901","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/willem.aandewiel.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/willem.aandewiel.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/willem.aandewiel.nl\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/willem.aandewiel.nl\/index.php\/wp-json\/wp\/v2\/comments?post=6901"}],"version-history":[{"count":15,"href":"https:\/\/willem.aandewiel.nl\/index.php\/wp-json\/wp\/v2\/posts\/6901\/revisions"}],"predecessor-version":[{"id":6920,"href":"https:\/\/willem.aandewiel.nl\/index.php\/wp-json\/wp\/v2\/posts\/6901\/revisions\/6920"}],"wp:attachment":[{"href":"https:\/\/willem.aandewiel.nl\/index.php\/wp-json\/wp\/v2\/media?parent=6901"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/willem.aandewiel.nl\/index.php\/wp-json\/wp\/v2\/categories?post=6901"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/willem.aandewiel.nl\/index.php\/wp-json\/wp\/v2\/tags?post=6901"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}