In my current endeavor to build a cellular tracker that can run autonomously for months i stumpled upon a strange problem during outdoor tests which could only be resolved the hard way…
Initially i intended to use the built in ATmel-Watchdog feature in two ways – for the sleeping function and for resetting the system in case of failure. According to the official documentation this is a supported use of these functions.
And it worked – the system goes to sleep for an hour, wakes up, does some measurements and uploads them to the internet. If something strange happens which takes longer than 8seconds (the longest possible watchdog timeout) the system will reset itself and startover. Quite nice – especially as the communication with Fona sometimes has issues and can have unexpected delays etc. this is very useful.
Unfortunately my outdoor tests showed a strange behavior, sometimes after days of normal operation. Suddenly the board got stuck and hangs with power on at the System-LED (which sits on PIN13), obviously in a loop or so. This is strange because the watchdog should prevent something like this specifically and normally it should not be possible to let the guy hang himself. Perhaps it’s also an issue with my code, asked a few people but nobody could help (it does not seem to be a memory issue).
Anyway – i got tired of trying to find the source of the problem and btw during my research i found a few others reporting watchdog hanging etc.
So i tried to find an alternative solution – this is where i asked the stackexchange community for help and got exciting support.
The basic idea is to use a 555-timer chip and configure it in a way that it triggers the reset pin of the arduino after the given time. My first contact with that famous chip to be honest and am grateful that newer variants exist that use less power, because the original NEC 555 from 1970 (which is still sold) will consume about 10mA _permanently_. The younger CMOS-versions are pin-compatible and consume 10-times less energy + the can work under less voltage.
As you can see in the video below my first tests work quite well. Currently i am testing a setup where i really replace the software watchdog with the external one completely, which means permanently resetting the board. Which is not too beautiful. I will try another setup where the 555 is only triggered as a fallback-watchdog that is powered while the Board in on and will reset if this takes longer than expected(**see Update at the end). Clearly more elegant, but also comes with some dependencies as well which could undermine stability again because the Arduino has to power a PIN and shut it down properly in this case. As i don’t really know yet what exactly is happening in these cases of failure this more elegant version might have a disadvantage compared to the brute-force approach…
** have this version up and running as well now. It works like this: it’s a normal 555 astable circuit, which would stay high for a few minutes and go low for a second after that. This Output-Pin is connected to the Reset-Pin of the Arduino with a 1K resistor. A Mosfet connects the positive leg (–> please check update below) of the Capacitor in the 555 circuit with Ground and is being triggered by an Arduino Pin. So i am turning this Pin low when the sketch starts and high again at the end. This way the 555 is charging it’s capacitor during the sketch and will hit reset if the sketch takes too long. If not the Arduino discharges the Capacitor during sleep to prevent unintended resets.
—- UPDATE —–
With the help from a friend i figured that the above circuit also works without the Mosfet – you just have to use the right resistors. I do connect to Reset with 1K and to the Arduino control PIN with a 56K resistor. The control-PIN is configured as INPUT when the board wakes up – that way it is practically not existing for the 555-circuit which therefore starts to load. At the end of the code before going to sleep the control-Pin is set to OUTPUT. As this is LOW on default the capacitor starts to unload through this Pin instead of the 555 which has a higher resistor (100k). This way the 555 is not triggered during sleep but it will be triggered during execution if it takes too long.
BTW: this additional circuit consumes about 43micro-Amps on top of the sleeping Arduino (be careful to use a CMOS-version of the 555, the original NEC will consume much more energy and requires higher operating voltage!) which is not great (the Arduino consumes 10x less in sleepmode). But the benefit of a failover procedure can be worth it if autonomous operation is key.