What is a watchdog?Watchdog working principle, application and design ideas

Watchdog, also called watchdog timer, is a timer circuit. Generally, there is one input, called Feeding Dog, and one output to the RST terminal of the MCU. When the MCU is working normally, it outputs a signal to the feeding terminal at every other end. Clear the WDT. If the dog is not fed within the specified time (usually when the program is running), and the WDT timing exceeds, a reset signal will be sent back to the MCU, which is a MCU reset. Prevent the MCU from crashing. The role of the watchdog is to prevent infinite loops in the program, or program runaway.

Watchdog, also called watchdog timer, is a timer circuit. Generally, there is one input, called Feeding Dog, and one output to the RST terminal of the MCU. When the MCU is working normally, it outputs a signal to the feeding terminal at every other end. Clear the WDT. If the dog is not fed within the specified time (usually when the program is running), and the WDT timing exceeds, a reset signal will be sent back to the MCU, which is a MCU reset. Prevent the MCU from crashing. The role of the watchdog is to prevent infinite loops in the program, or program runaway.

This dog is not that dog

Working principle: After the system is running, the watchdog counter is started, and the watchdog starts to count automatically. If the watchdog is not cleared after a certain period of time, the watchdog counter will overflow and cause the watchdog. The dog is interrupted, causing the system to reset. Therefore, pay attention to the watchdog when using a chip with a watchdog.

The hardware watchdog uses a timer to monitor the operation of the main program, that is to say, during the operation of the main program, we must reset the timer before the timing is up. If there is an infinite loop, or PC pointer Can’t come back. Then the microcontroller will be reset when the time is up. Commonly used WDT chips such as MAX813, 5045, IMP 813, etc., the price ranges from 4 to 10 yuan.

What is a watchdog?Watchdog working principle, application and design ideas
The principle of the software watchdog technology is similar to this, but it is realized by software. We still use the 51 series. We know that there are two timers in the 51 single-chip microcomputer. We can use these two timers. Monitor the operation of the main program. We can set a certain timing time for T0, and assign a value to a variable when a timing interrupt is generated, and this variable has an initial value at the beginning of the main program, and the timing value we want to set here should be less than The running time of the main program, so that the value of the variable is judged at the end of the main program. If the value changes as expected, it means that the T0 interrupt is normal. If there is no change, the program is reset. For T1 we use to monitor the operation of the main program, we set a certain timing time for T1 and reset it in the main program. If it cannot be reset within a certain time, the timing interrupt of T1 will cause the microcontroller Reset. Here, the timing time of T1 should be set to be greater than the running time of the main program, leaving a certain margin for the main program. And whether the interruption of T1 is normal or not, we will be monitored by the T0 timer interrupt subroutine. This is enough to become a loop, T0 monitors T1, T1 monitors the main program, and the main program monitors T0 again to ensure the stable operation of the system.

The 51 series has a special watchdog timer, which divides and counts the system frequency. When the timer overflows, it will cause a reset. The watchdog can set the overflow rate, or it can be used as a timer alone.

The watchdog of Sunplus 61 is relatively single, one is that the time is single, and the second is that the function only needs to add a clear dog instruction in the loop in actual use and it is OK.

There is also a 21-bit timer using the system clock inside the C8051Fxxx microcontroller, which detects the time interval between two specific write operations to its control register. If this time interval exceeds the programmed limit value, a WDT reset will be generated.

Watchdog usage note: Most 51 series microcontrollers have a watchdog. When the watchdog is not cleared regularly, it will cause a reset. This prevents the program from running away. The designer must know the overflow time of the watchdog to decide when it is appropriate to clear the watchdog. Do not clear the watchdog too frequently, otherwise it will cause a waste of resources. When the program is running normally, the software sets the timer every certain time (less than the overflow period of the timer) to prevent the false reset caused by the overflow interrupt.

Watchdog application: The watchdog is an effective monitoring manager for restoring the normal operation of the system (it has the function of locking the CD-ROM drive and locking any designated programs, and can be used in the family to prevent children from playing games, surfing the Internet, and watching videos indiscriminately), etc. Has very good application value.

Design Ideas of System Software “Watchdog”:

1. The setting of watchdog timer T0. Set the working mode of T0 in the initialization program block, and turn on the interrupt and count functions. System Fosc=12 MHz, T0 is a 16-bit counter, the maximum counting value is (2 to the power of 10)-1=65 535, T0 input counting frequency is .Fosc/12, overflow period is (65 535+1)/1 =65 536(μs).

2. Calculate the time consuming for the main control program to cycle once. Considering the function modules of the system and the number of cycles, the running time of the main control program of the system is about 16.6 ms. The system sets the “watchdog” timer T0 timing for 30 ms (the initial value of T0 is 65 536-30 000 = 35 536). Each cycle of the main control program will refresh the initial value of T0. If the program enters a “definite loop” and the initial value of T0 has not been refreshed within 30 ms, then the “watchdog” timer T0 will overflow and apply for interruption.

3. Design the interrupt service program corresponding to T0 overflow. This subroutine only needs one instruction, that is, write the “unconditional transfer” command in the interrupt vector address (000BH) corresponding to T0, drag the computer back to the first line of the entire program, re-initialize the microcontroller and obtain the correct execution sequence.

The Links:   QM50E1Y-H ITSX98N