The concept, principle, and Application of Single-chip Computer guard.

Source: Internet
Author: User

Address: http://blog.21ic.com/user1/5621/archives/2009/56755.html

Dog, also calledWatchdog timerIt is a timer circuit. Generally, there is an input, which is called a dog Feed. One output is to the MCU's rst end. When the MCU works normally, a signal is output at every end of timeDog FeedEnd, reset the wdt. If the dog is not fed after the specified time (generally when the program is running) and the wdt time exceeds, a reset signal is returned to the MCU, which is used to reset the MCU. prevents the MCU from crashing. the role of the watchdog is to prevent an endless loop of programs, or to run programs.

Working principle:After the system runs, the watchdog counter is started, and the watchdog starts to automatically count. If the watchdog is not cleared at a certain time, the watchdog counter will overflow and cause the watchdog interruption, this causes system reset. Therefore, when using a chip with a watchdog, you must clear the watchdog.
The Hardware Watchdog uses a timer to monitor the running of the main program. That is to say, during the running of the main program, we need to reset the timer before the scheduled time. If an endless loop occurs, or the PC pointer cannot return. After the scheduled time is reached, the microcontroller will be reset. Common wdt chips such as max813
, 5045, IMP 813, etc., price 4 ~ 10 yuan.

The principle of the Software Watchdog Technology is similar to this, but it is implemented using software methods. We still use the 51 series. We know that there are two timers in the 51 microcontroller, we can use these two timers to monitor the running of the main program. We can set a scheduled time for T0, assign a value to a variable when scheduled interruption occurs, and this variable has an initial value at the beginning of the main program running, here, we want to set the scheduled value to be less than the running time of the main program. In this way, we can judge the variable value at the end of the main program. If the value changes as expected, it indicates that t0 interruption is normal. If there is no change, reset the program. When T1 is used to monitor the operation of the main program, we set a certain scheduled time for T1 and reset it in the main program. If it cannot be reset within a certain period of time, the timing interruption of T1 will reset the microcontroller. Here, the scheduled time of T1 is greater than the running time of the main program, leaving some margin for the main program. The T1 interruption is normal or not, and we will monitor it by t0 scheduled interrupt subprogram. In this way, it becomes a loop. t0 monitors the main program T1 and T1, and the main program monitors t0 again to ensure the stable operation of the system.

The 51 series has a dedicated watchdog timer to calculate the system frequency. When the timer overflows, it will cause reset. The watchdog can set the overflow rate and can also be used as a timer separately.

Ling Yang 61's watchdog is relatively single, one is a single time, and the other is the function in actual use, just add the clear dog command in the loop is OK.

The c8051fxxx microcontroller also has a 21-bit system clock timer, which detects the interval between two specific write operations on its control register. If the time interval exceeds the programming limit, a wdt reset is generated.

Watch Dog Usage Note: Most 51 series single-chip microcomputer have a guard dog. When the guard dog is not timed to be cleared, it will cause reset. This prevents programs from flying. The designer must be clear about the overflow time of the watchdog to determine when appropriate. Clear the watchdog should not be too frequent or it may cause a waste of resources. When the program runs normally, the software sets the number of timers at a certain time (less than the timer overflow cycle) to prevent false reset caused by overflow interruption.

Dog application:The watchdog is an effective monitoring manager for restoring the normal operation of the system (with the function of locking the optical drive and locking any specified program, it can be used in the family to prevent children from playing games, surfing the Internet, watching videos unlimitedly) and so on.

 

System software "Watchdog" design ideas:

1. Set the watchdog timer t0. Set the T0 working mode in the initialization block, and enable the interrupt and count functions. System fosc = 12 MHz, t0 is a 16-bit counter, and the maximum count value is (16 power of 2)-1 = 65
535, t0 input counting frequency is. fosc/12, overflow cycle is (65 535 + 1)/1 = 65 536 (μs ).

 

2. Calculate the time consumed by one cycle of the master program. Considering the function modules and the number of cycles of the system, the running time of the Main Control Program of the system is about 16.6 Ms. The system sets the "Watchdog" timer T0 at 30.
MS (T0 initial value is 65 536-30 000 = 35 536 ). Each cycle of the master program will refresh the initial value of T0. If the program enters an "endless loop" and T0 has an initial value of 30
If not refreshed within ms, the "Watchdog" timer t0 will overflow and request interruption.

3. Design the interrupt service program corresponding to t0 overflow. This subroutine only requires one instruction, that is, to write the "unconditional transfer" command to the interrupt vector address (000bh) corresponding to T0, and drag the computer back to the first line of the entire program, reinitialize the microcontroller and obtain the correct execution sequence.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.