Skip to main content
2 of 4
if/then
nio
  • 161
  • 5

There is one mechanism that can get MCU from erratic state and it's the watchdog timer. If you're implementing some code that will repeatedly run in a loop, that will not run anytime longer than some fixed time, you can set this time as watchdog period and enable the timer.

Then, you have to repeatedly reset the timer in the loop. If your code freezes at some condition loop that will never end, then the watchdog will count to zero and eventually reset the MCU.

This way you are losing data, but if you run the AVR WDT in interrupt mode, you can store some data before resetting the MCU.

So the watchdog timer can guard your code from occasional unintended endles loops.

nio
  • 161
  • 5