1. What is a Watchdog?What is a Watchdog? Is it this? ⬇
No, no, no. Today we are talking about the watchdog in embedded systems, formally known as the Watchdog Timer (WDT). It is a mechanism used to detect system failures (such as software crashes or hardware faults). It can automatically restart the application or even reset the entire system when the program encounters an unrecoverable error, thus bringing the system out of a crash state and restoring normal business operations. This is extremely important for applications involving personal and property safety.2. Working Principle of the WatchdogThe working principle of the watchdog is based on a simple concept: regular feeding. When the system is operating normally, the watchdog regularly receives a feeding signal (i.e., resets the counter to its initial value); otherwise, the watchdog assumes that a fault or anomaly has occurred in the system and takes appropriate actions, such as resetting the system or other specific handling.
3. Classification of Watchdogs1. Hardware WatchdogThe advantage of a hardware watchdog is its high reliability, but the downside is that it requires additional hardware circuit design or relatively more expensive processor chips, making the cost relatively high.①. Independent Hardware Watchdog ChipWorking PrincipleIt operates independently of the embedded processor and has its own internal counter. It needs to receive a trigger signal (commonly referred to as the “feeding” signal) from the processor within a specified time to reset the counter. If the “feeding” signal is not received within the timeout period, the watchdog chip assumes that the system is running abnormally and actively resets the processor or the entire system, allowing the system to restart and return to normal operation.Characteristics and Application ScenariosHigh Reliability: Independent of the processor, it is not affected by internal software faults or operational states of the processor, and can reliably perform reset operations when the processor experiences severe faults (such as runaway programs, infinite loops, etc.).Simple and Stable: Its function is relatively simple and specialized, the circuit design is mature and stable, and it is relatively easy to use, requiring only basic hardware connections and simple configurations to operate.Commonly used in fields that require extremely high system reliability, such as industrial control, aerospace, and medical devices.Common chips include MAX706, 5045, SP706, etc.Taking the SP706 chip as an example, its hardware circuit is as follows:
②. Processor Built-in Hardware WatchdogWorking PrincipleIntegrated within the embedded processor, its basic principle is similar to that of an independent hardware watchdog chip. It also uses a counter to time and waits for the processor’s “feeding” signal. If the signal is not received within the timeout period, it triggers the processor reset and other operations. However, it is somewhat related to the processor’s internal clock, bus, and other resources, and its configuration and control are usually done through the processor’s related registers.Characteristics and Application ScenariosHigh Integration: No need for an additional independent chip, saving circuit board space, reducing hardware costs and design complexity.Close Collaboration with the Processor: It can better work in coordination with other functional modules within the processor, for example, it can flexibly adjust the watchdog’s timeout period and reset methods based on the processor’s different operating modes or states.Suitable for embedded applications that are sensitive to cost and size but have certain reliability requirements, such as consumer electronics and smart home devices.Commonly found in STM32, TI, AVR, and even 51 microcontrollers, which generally come with built-in watchdogs.2. Software WatchdogThe advantage of a software watchdog is that it does not require additional hardware support, making it cost-effective, but the downside is that if the software itself encounters issues, it may lead to the watchdog function failing.①. Timer Interrupt-based Software WatchdogWorking PrincipleIt is implemented by setting a timer interrupt in the embedded software. During normal operation, the main program or specific tasks will update a flag variable or perform a specific “feeding” operation before the timer interrupt is triggered. The timer interrupt service routine checks whether the flag variable or “feeding” operation was executed on time; if not, it determines that a system fault has occurred and executes corresponding recovery operations in the interrupt service routine, such as resetting related hardware modules, reinitializing the system, or jumping to an error handling routine.Characteristics and Application ScenariosHigh Flexibility: The timer’s timing can be flexibly adjusted based on the specific conditions of software operation, such as the execution cycles of different tasks and the different operational phases of the system.Dependent on Software Operating Environment: Its operation relies on the normal scheduling and execution of software. If the software itself encounters severe issues that prevent the timer interrupt from being triggered or the “feeding” operation from being executed (such as interrupts being accidentally disabled, or the program entering a deadlock state), the software watchdog may fail.Suitable for embedded systems where the software logic is relatively complex, has specific recovery needs, and lacks hardware resources to use a hardware watchdog.②. Operating System-based Software WatchdogWorking PrincipleIn embedded systems with an operating system (such as embedded Linux, uC/OS, etc.), the operating system can utilize its own task management and timer mechanisms to implement software watchdog functionality. The operating system creates a dedicated watchdog task that checks the running status of monitored tasks or processes at certain intervals. It obtains their “heartbeat” signals or status information through communication mechanisms (such as shared memory, message queues, etc.). If it finds that the monitored object has not responded for a long time or is in an abnormal state, it takes appropriate actions, such as restarting the monitored task, process, or even the entire system.Characteristics and Application ScenariosStrong System-level Monitoring Capability: It can monitor the running status of multiple tasks and processes as well as the usage of system resources from the operating system level.Highly Influenced by the Operating System: Its functionality and effectiveness depend on the stability and normal operation of the operating system. If the operating system kernel encounters faults (such as kernel crashes, memory management errors, etc.), the software watchdog task itself may not run normally, thus losing its monitoring and recovery capabilities.Suitable for embedded applications that require concurrent execution of multiple tasks, complex system resource management, and high overall stability and reliability, such as network communication devices and upper-level machines in industrial automation control systems.4. Steps to Implement a Watchdog1. InitializationAt system startup, initialize the watchdog timer settings, including timing duration, interrupt priority, etc.2. Start the TimerStart the watchdog timer and begin timing.3. Monitor Program ExecutionThe system’s main program or monitoring program begins to run and periodically resets the watchdog timer during normal operation (before the timer overflows). This is usually achieved by inserting specific watchdog reset instructions in the program, i.e., “feeding the dog”.4. Timer Interrupt HandlingIf the watchdog timer overflows (i.e., reaches the preset timing duration without being reset), it triggers a timer interrupt. In the interrupt service routine, execute the predetermined recovery operations, such as system reset, jumping to an error handling routine, etc.5. Applications of the WatchdogIn embedded systems, the application of watchdogs is very extensive. Through programming, we can control and manage the watchdog to improve the reliability and stability of the system. Especially in critical applications, such as medical devices, aerospace systems, and applications involving personal and property safety, the watchdog is an important means to enhance system reliability and safety.Since this fault recovery mechanism is so effective, why is it called a watchdog? Is it a bit disrespectful? I think it might be voluntary.

Understanding Common Black Box Testing Methods in Software TestingUnderstanding Common White Box Testing Methods in Software TestingUnderstanding the Definitions, Applications, and Differences of SPI, UART, and I2C CommunicationUnderstanding the Differences Between CAN, CANFD, CANXL, LIN, FlexRay, MOST, and In-Vehicle EthernetUnderstanding the Differences Between CPU, MCU, MPU, SOC, DSP, ECU, GPU, and FPGAUnderstanding the Differences Between SRAM, DRAM, SDRAM, ROM, EPROM, EEPROM, and FLASHUnderstanding Code Coverage in Software White Box Testing: Statement, Decision, Condition, MCDC, etc.Those Little-Known Details in C Language: static, const, volatile, arrays, macrosThose Little-Known Details in C Language: typedef, infinite loops, bit shifts, memory accessHow Should Software Code Review Be Conducted? A First Experience of Code Review, Including a Sample Code Review ChecklistReviewing Scenarios in C Language That May Cause Program CrashesWhere Can IT Professionals Find Side Jobs and Part-Time Work?



Use your little hand to click below: Follow, Like, Share, and View