51 MCU - Software Watchdog

Publisher:BlissfulJoyLatest update time:2015-10-16 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
This is the first time I write about my learning process. This is just the beginning. Of course, it is not the end.

I had nothing to do today, so I read a book on microcontrollers. Suddenly I realized that I have studied for such a long time but have never used the watchdog thing~~ I feel ashamed, (*^__^*) hehe...

Since this is my first article, let's write something simple but easy to write~~~

001. Software Watchdog

  When the program runs into a temporary infinite loop, if there is no human operation (that is, pressing the reset button [Reprint] 51 MCU - Software Watchdog - 01), the software system will be completely paralyzed. Then we need to let the MCU monitor the operation of the system by itself, which is the program operation monitoring system (WatchDog).

  To put it simply, it is like an owner who has a dog. When the owner is working normally, he always remembers to feed the dog every once in a while. The dog will be quiet after eating, so it will not affect the owner's life. But if the owner dozes off and forgets to feed the dog, then when the time comes, the dog will be hungry and find that the owner has not fed it yet, it will bark and wake up the owner. Haha, that's it. . . . . . In foreign countries, this program running monitoring system is called WatchDog. The characteristics of the watchdog are:

   1》It can work independently and basically does not rely on the CPU (it should be explained here that it mainly occupies the CPU for a few microseconds, which is to feed the dog)

   2. The CPU interacts with the system at a fixed time interval (that is, feeding the dog, as mentioned in 1) to indicate that the system is currently normal.

   3. When the CPU falls into an infinite loop, it can be detected immediately and the system can be reset

  The following is the design process of the program~~~

  When the system is stuck in an infinite loop, what kind of program can make it jump out? Only an interrupt program with a higher level than the dead program can take away the dead program's control over the CPU. To this end, we can use a timer as a watchdog, set its overflow interrupt as a high priority interrupt, and then set other interrupts in the system as low priority interrupts (here you must ensure that the interrupt you set for the watchdog must be higher than other interrupts in your program!!!) (There are many ways to set it here, but the principles just mentioned must be met!). For example, use T0 as a watchdog, the timing is about 16ms, if your system does not use INT0, then you do not need to set PTO (I will not explain it here~~you all know).

  When the watchdog is enabled, the system worker must "feed it" frequently, and the interval between each two times must not exceed 16ms (here is still the example above)

  When the program falls into an infinite loop, a T0 interrupt will be triggered within 16ms, generating a high priority interrupt, thus ending the infinite loop. At the same time, it is recommended to directly jump to the error handling program in the T0 interrupt, that is, to place an "LJMP ERROR" in the interrupt vector area (it is easier to explain here in assembly language~~)

  The following is a watchdog program written in assembly language, which includes the simulated main program, the "feed the dog" (DOG) program and the empty bullet return to 0000H (TOP) program.

      ORG       0000H

      AJMP      MAIN

      ORG       000BH

      LGMP      TOP

MAIN: MOV       SP,#06H             ; module hardware reset, these can be increased or decreased according to the system's use of resources

      MOV       PSW,#OOH

      MOV      SCON,#01H

      .

      .

      .

      MOV       IE,#00H

      MOV       IP,#00H

      MOV       TMOD,#01H

      LCALL     DOG                ​​; The time interval for calling DOG should be less than 16ms in the example

      .                           ; Here you don't need to add any programs. You can add them according to your needs. I won't waste my words.

      .

      .

DOG:   MOV       TH0,#0B1H          ; This is the dog feeding program, here is the timer counter 0

      MOV       TL0,#0E0H

      SETB      TR0

      RET

TOP:   POP       ACC                 ; Empty pop breakpoint address, that is, first take out the address you pushed, and then assign a new value

      POP       ACC                 ; Here the value is 0, you know, it means to return to the beginning of the program~~

      CLR       A                   ; Of course you don't have to do this, you can also use a call instruction here and do it yourself!

      PUSH      ACC

      PUSH      ACC

      RETI; (Here is RETI, not RET)

 

  The watchdogs here should make it clear~~~

  This is one of the methods of software anti-interference. Another method is software trap technology, which is also very simple, so I will not go into details~~

Tip: A software trap is a guide instruction that forcibly directs the captured program to a specified address, where there is a special program to handle program errors, used to make the program execute according to the established goal. A real software trap consists of three instructions:

  NOP

    NOP

    LJMP   ERROR

Reference address:51 MCU - Software Watchdog

Previous article:51 single chip microcomputer and RC500 radio frequency
Next article:Button control LED

Recommended ReadingLatest update time:2024-11-16 17:55

Lesson 2: 8051 MCU Development Program Download
Last time we analyzed the minimum hardware system of the MCU, so today we will learn about the program download process of the MCU. Let's first look at the MCU program download circuit diagram, as shown below: Figure 1. Complete circuit diagram of the single-chip minimum system       Figure 1 shows a commonly u
[Microcontroller]
5-Real-time voice acquisition system based on 51 single-chip microcomputer
Specific implementation functions The system consists of STC89C52 microcontroller + ISD4004 recording chip + LM386 amplifier module + small speaker + LCD1602 + button + indicator light + power supply. Specific implementation functions: (1) You can select the corresponding recording to play at any time by pressing
[Microcontroller]
5-Real-time voice acquisition system based on 51 single-chip microcomputer
D/A & A/D and MCU interface principle based on 51 MCU
D/A: Digital to analog is the process of converting digital information into analog quantities. The microcontroller is a digital chip, which can only be represented by 0 and 1. It cannot express an analog quantity. The voltage value analog quantity can change randomly. The digital quantity has only two changes a
[Microcontroller]
D/A & A/D and MCU interface principle based on 51 MCU
Application of 51 single chip microcomputer in portable numerical control well logging system
1 Introduction     With the rapid development of logging technology, the real-time acquisition and processing of various logging data have become indispensable in modern logging systems. The traditional communication mode between the ground data acquisition system and the host is to use PCI bus or RS-232 serial bus.
[Microcontroller]
Application of 51 single chip microcomputer in portable numerical control well logging system
Environmental noise measuring instrument based on 89C51 microcontroller
   1 Introduction      Environmental noise monitoring is an important link for humans to improve their quality of life and strengthen environmental protection. Large-scale environmental noise monitors have been erected on the streets in prosperous neighborhoods and residential areas of major cities. However, most of t
[Microcontroller]
51 MCU external interrupt 0 controls the LED on and off
Use 51 MCU external interrupt 0 to control LED on and off #include reg52.h. typedef unsigned char u8; typedef unsigned int u16;   sbit key1=P3^2; sbit LED=P2^0;   void delay(u16 i) { while(i--); }   void int0init() { IT0=1; EA=1; EX0=1; }   void main() { int0init(); { while(1) { } } }   void ini
[Microcontroller]
Design of low-cost ECG monitoring system based on 51 single-chip microcomputer
1 Introduction Virtual medical instruments make full use of the rich software and hardware resources of computers. Only a small number of special software and hardware modules are added to realize all the functions of traditional instruments and some functions that traditional instruments cannot realize, while s
[Microcontroller]
Design of low-cost ECG monitoring system based on 51 single-chip microcomputer
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号