March 06, 2016

Arduino Watchdog

For my e-stim box project, safety is important. One issue are unexpected hangups of the Arduino CPU due to undetected coding errors. This may potentially leave the Arduino's outputs in a dangerous state. A convenient way of preventing this is the built-in watchdog. The watchdog can be programmed to automatically reset the CPU after a specified timeout period if the loop() function hangs up and fails to "tame" the watchdog within the timeout period. In the start() function that is executed immediately after a reset, the Arduino's outputs can then be brought to a safe state.

One kludge is the Arduino's core library, which disables the watchdog, after which it cannot be reenabled. To overcome this, edit hardware/arduino/sam/variants/arduino_due_x/variants.cpp and remove (comment) the line reading WDT_Disable(). This is my tiny watchdog class. The watchdog can be configures once by specifying a timeout period in milliseconds, which has to be between 4 ms and 16 seconds in a granularity of 4 ms. The reset function must be called inside loop() and at a rate faster than the timeout period, or the watchdog will automatically reset the CPU.

The implementation is simple: Update: The Arduino folks seem to have reacted to the kludge, and have made the watchdog accessible in the newest core library revision 1.6.5. [1]

References

  • http://forum.arduino.cc/index.php?topic=350058.msg2416416#msg2416416

No comments:

Post a Comment