Designing Reliable Embedded Systems: Watchdogs, Brown-Outs and Safe States

A supply sags during a motor start, an I2C sensor holds the bus low, a rare code path loops forever. What separates a robust product from a fragile one is not the absence of faults but how the system detects them and where it ends up afterwards. This article covers the three mechanisms that matter most: the watchdog, brown-out detection and a defined safe state.

At a glance

Watchdog
A hardware timer that resets the processor unless firmware refreshes it in time.
Windowed
A window watchdog also resets on a refresh that arrives too early, catching runaway loops.
BOR
Brown-out reset holds the processor in reset while the supply is below a safe threshold.
Reset cause
Most microcontrollers record why they last reset; logging it makes silent resets visible.

The problem

A processor running below its rated supply voltage can execute instructions incorrectly, corrupt RAM or write garbage to flash. Without brown-out detection, a slow supply ramp or a brief dip can leave the device running in an undefined condition that firmware cannot detect.

Watchdogs are often fitted and then defeated. A refresh placed in a timer interrupt keeps the watchdog satisfied while the main loop is stuck, so the device sits hung and never resets.

Assume the firmware will fail at some point, and decide in advance what the outputs do when it does.

Defining the safe state

Microcontroller pins are typically high-impedance inputs during and immediately after reset, so the hardware, not the firmware, sets what each output does at that moment. Use pull-up or pull-down resistors so that heaters, motors and valves default to off while the processor is resetting or unprogrammed.

In firmware, set outputs to their safe values before anything else, then read the reset cause. A device that has reset repeatedly from the watchdog can enter a limited mode and report the fault rather than cycling indefinitely.

What good looks like

Enable the brown-out reset and choose a threshold above the minimum supply voltage the processor and its flash need at the chosen clock speed.

Refresh the watchdog from one supervisory point only, and only when every task has reported progress since the last refresh.

Define the safe state of every output in hardware, then log the reset cause and count consecutive watchdog resets in firmware.

Mechanisms and the faults they catch
MechanismCatchesTypical action
Power-on resetSupply ramping up from zeroHolds reset until the supply is valid
Brown-out resetSupply dipping below a thresholdResets and holds until the supply recovers
Independent watchdogFirmware hang or stuck loopResets the processor after a timeout
Window watchdogA hang, or a refresh that comes too earlyResets on a late or early refresh
Clock monitorLoss of the external crystalSwitches to an internal oscillator and raises an interrupt
Fault handlerInvalid memory access or instructionRecords state, then resets
General behaviour. Thresholds, timeouts and options vary by device; check the reference manual.

Supervised watchdog refresh

  1. Tasks run: Each sets its own check-in flag
  2. Supervisor checks: All flags set since the last refresh?
  3. Refresh: Clear the flags and refresh the watchdog
  4. Or withhold: A missing flag lets the timeout expire
  5. Restart: Read reset cause, enter safe state
One supervisor refreshes the watchdog only when every task has shown progress.

What it changes

Recovery

Hangs end in a controlled reset, not a device that needs a power cycle.

Data Integrity

Flash is never written while the supply is too low to do it correctly.

Safety

Outputs fall to a known, harmless condition whenever the firmware is not in control.

Diagnosability

Logged reset causes show which faults occur in the field and how often.

Where to go next

Protect stored settings against a reset mid-write: keep two copies with a sequence number and a CRC, and use the newest valid one at start-up.

Test the mechanisms deliberately: hang a task, ramp the supply down slowly, and confirm the device behaves as designed.

Problems this prevents

  • A watchdog refreshed from a timer interrupt
  • Flash corrupted by writes during a supply dip
  • Outputs that switch on while the processor resets
  • Field resets that leave no record of their cause

Discuss your project

Email support@aavico.com or use Get in Touch when the website finishes loading.