Renesas
Watchdog Timers and Fail-Safe Reset Design
-
Question 1 of 11
What does a watchdog timer do, and why can software hang?
Reveal answerA watchdog timer is a hardware counter that resets the chip when software stops checking in. Software must restart the count, called a refresh, before it runs out. Software can hang for many reasons. A pointer bug can send the program into the wrong memory. Electrical noise can corrupt a register. A task can wait forever for a sensor that never answers. The watchdog does not fix the bug, but it brings the system back to a known state.
The RL78/F23 and RL78/F24 safety function application note states the watchdog’s purpose plainly. The watchdog detects an inadvertent program loop and responds by generating an internal reset (R01AN6624EJ0110, Section 15.1, p. 59).
-
Question 2 of 11
How do you calculate a watchdog timeout?
Reveal answerThe timeout depends on the watchdog clock, the clock divider, and the number of counts. Divide the clock by the divider to get the count rate. Then multiply the time per count by the number of counts. Here is an example with a 15 kHz clock, a divider of 128, and 1,024 counts.
Count rate = 15,000 Hz ÷ 128 = about 117.2 Hz
Time per count = 1 ÷ 117.2 Hz = about 8.53 ms
Timeout = 1,024 × 8.53 ms = about 8.74 sLow-speed on-chip oscillators are not precise. Check the tolerance in the datasheet and make sure your refresh fits inside the shortest possible timeout.
Renesas works through the same math in the RX Family IWDT module application note. (R01AN1820EJ0461, Section 3, p. 18).
-
Question 3 of 11
What is a windowed watchdog, and why is refreshing too early a fault?
Reveal answerA windowed watchdog accepts a refresh only during a set part of the count, called the window. A refresh before or after the window is a fault, just like a timeout. This catches a program stuck in a loop that keeps calling refresh. It also catches code that runs too fast because it skipped work.
You set the window with a start and an end position, each a percentage of the count still left. Here is an example with the 8.74 s timeout from Question 2, a 75% start, and a 25% end.
Window opens = 8.74 s × 0.25 = about 2.18 s after the last refresh
Window closes = 8.74 s × 0.75 = about 6.55 s after the last refresh
Refresh at 1 s = too early, so the watchdog flags a fault
Refresh at 4 s = inside the window, so the count restarts
Refresh at 7 s = too late, so the watchdog flags a faultThe Renesas Flexible Software Package, or FSP, lists these settings in its r_wdt watchdog timer documentation for RA microcontrollers. The start position can be 100%, 75%, 50%, or 25%. The end position can be 0%, 25%, 50%, or 75%. If the count runs out, called an underflow, or a refresh lands outside the window, the watchdog can either reset the device or generate a non-maskable interrupt (FSP v6.6.0, r_wdt, Features and Configuration).
-
Question 4 of 11
How is an independent watchdog different from a main-clock watchdog?
Reveal answerAn independent watchdog keeps counting even if the main clock fails. Many Renesas RA and RX microcontrollers have two watchdogs.
The standard watchdog timer, or WDT, counts from a clock derived from the main system clock. If that clock fails, the WDT can slow down or stop with it.
The independent watchdog timer, or IWDT, runs from a separate low-speed on-chip oscillator. The trade-off is less accurate timing.
The RA0 quick design guide shows this separation in hardware. The low-speed on-chip oscillator, or LOCO, runs whenever the IWDT is enabled, no matter how the LOCO control register is set. The guide also warns that settings in option-setting memory can turn on the IWDT right after reset (R01AN7309EU0120, Sections 4 and 5, pp. 6 and 8).
-
Question 5 of 11
Should a watchdog trigger a reset or a non-maskable interrupt?
Reveal answerA reset is the safest default because it returns the whole chip to a known state. The other choice is a non-maskable interrupt, or NMI, which normal interrupt masking cannot block. An NMI is useful when the system needs to save fault data or move outputs to a safe state before it restarts. Keep the NMI handler short and end it with a software reset. If the handler itself hangs, the system may never recover.
FSP covers both options in its r_iwdt independent watchdog documentation. An underflow or a refresh outside the permitted window can either reset the device or generate an NMI. When the NMI fires, the driver calls the callback function that was registered when the IWDT was opened (FSP v6.6.0, r_iwdt, Features and NMI Interrupt).
-
Question 6 of 11
Where should refresh calls go, and why is a timer interrupt a bad place?
Reveal answerPlace the refresh only where the code can prove the system is healthy. A timer interrupt keeps firing even when the main loop is stuck. A refresh there would keep the watchdog happy while the application is frozen. A better pattern is to have each task set an “alive” flag when it finishes its work. The main loop refreshes only if every flag is set, then clears the flags for the next pass.
The RL78/F23 and RL78/F24 safety function note gives the basic refresh sequence in a flow chart. Software sets the user option byte, clears the counter once after reset release, and then keeps clearing it during the window open period. Each clear writes the hex value ACH to the WDTE register (R01AN6624EJ0110, Section 15.3, p. 60).
-
Question 7 of 11
How does firmware know a watchdog reset just happened?
Reveal answerFirmware reads the reset status flags first thing at startup. These flags show what caused the reset, such as power-on, the reset pin, low voltage, or a watchdog. If a watchdog caused it, log the event and count it. Several watchdog resets in a row point to a real fault, so the system may need to stay in a safe mode. Clear the flags after reading them so the next reset reports fresh data.
The RA2 quick design guide lists the flags to check. An IWDT reset sets the IWDTRF bit in the RSTSR1 register. A WDT reset sets the WDTRF bit in the same register. The guide tells you to read the reset status registers to find the reset source (R01AN6060EU0104, Sections 6.3, 6.4, and 6.9, pp. 17–18).
-
Question 8 of 11
What happens to the watchdog in low-power modes?
Reveal answerIt depends on a setting you choose. In sleep or standby modes, the CPU stops and cannot refresh the watchdog. If the watchdog keeps counting, it will time out and reset the chip.
One option is to stop the count during low-power modes. Another is to keep it running and wake up on a schedule to refresh it. Stopping the count is simpler, but a hang during sleep then goes undetected.
FSP’s r_iwdt documentation includes a Stop Control setting that selects the IWDT state in low-power mode. If the counter stops in low-power mode, the application must call R_IWDT_Refresh after the microcontroller wakes to restart the watchdog (FSP v6.6.0, r_iwdt, Configuration and Limitations).
-
Question 9 of 11
When should you add an external watchdog or supervisor IC?
Reveal answerAdd an external watchdog when one failure could take out both the CPU and its internal watchdog. An internal watchdog shares the same silicon and power as the CPU. An external watchdog sits on a separate chip. It can catch a bad setting that leaves the internal watchdog disabled.
A supervisor IC also monitors the supply voltage and holds the processor in reset until the supply is stable. The cost is board space and one I/O pin to toggle.
The SLG7WD47666 watchdog timer datasheet shows how a simple external watchdog works. The processor must toggle the WDI input before the timeout ends. If it does not, the device sends a pulse on its open-drain nWDO output, which can trigger a reset or an interrupt. The datasheet lists a 1.6 s timeout and 9 µA typical current (R19DS0139EU0100, Features and Section 2.2, pp. 1 and 5).
-
Question 10 of 11
What state should outputs take during and after a reset?
Reveal answerOutputs must be safe even when no firmware is running. During reset, the pins fall back to their hardware defaults, so the board design must make that default safe. For example, add a pull-down resistor on a motor enable, heater, or relay driver so it stays off. After reset, firmware should drive every output to its safe state before it resumes normal operation.
The RA2 quick design guide explains why external resistors matter. All I/O pins act as inputs right after a reset. A pin stays a floating input while the microcontroller is held in reset and until firmware sets its direction to output (R01AN6060EU0104, Sections 9 and 9.5, pp. 23 and 28).
-
Question 11 of 11
How do watchdogs fit into functional safety standards?
Reveal answerA watchdog helps a product meet safety standards, but it is never enough on its own. IEC 60730 covers automatic electrical controls, such as those in household appliances. It sorts control functions into Class A, B, and C based on how much safety depends on them.
IEC 61508 is the broader functional safety standard for electrical, electronic, and programmable safety systems. Both expect the design to detect faults in program flow and timing. A watchdog covers part of that, alongside tests of the CPU, memory, and clock.
Renesas offers an IEC 60730/60335 self-test library for RL78 microcontrollers. It defines Class B as control functions intended to prevent unsafe operation of the controlled equipment. Class C covers functions intended to prevent special hazards. The library tests instruction decode, CPU registers, internal memory, the watchdog timer, and the system clock. It checks program timing with the built-in watchdog, which runs on a clock independent of the CPU (R01AN7508EJ0101, Introduction and Section 1, pp. 1 and 4–5).