Application of Watchdog in 8XC552 Series MCU System

Publisher:万童洁Latest update time:2012-02-17 Source: 国外电子元器件 Keywords:Watchdog  87C552 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1 Introduction

Philips' 8XC552 microcontroller is widely used in industrial control, DCS control and intelligent instruments due to its small size, powerful functions and low price. In the process of developing the intelligent power distribution monitor, although the author has taken corresponding anti-interference measures, due to the influence of electromagnetic fields, power grid spikes, harmonics, surges and lightning radiation in the industrial field environment, there may still be out-of-control phenomena such as program dead loops and runaway. For this reason, the author uses Watchdog technology to ensure the normal operation of the system. Usually, Watchdog technology can be divided into software Watchdog and hardware Watchdog in the microcontroller application system. Philips' 8XC552, Intel's 8098, Motorala's 68C05 and Microchip's 16C5X series microcontrollers already have software Watchdog functions. Therefore, as long as the hardware connection is correct, the corresponding statement can be called in the software design to start.

2 Hardware Composition Principle

2.1 System Working Principle

Figure 1 shows the connection circuit of 87C522 single-chip microcomputer for intelligent power distribution instrument. The 87C552 in this intelligent power distribution instrument is the main control chip. In addition to three 16-bit timers T0, T1 and T2, the chip also has a T3 timer dedicated to monitoring 8-bit timer, referred to as WDT (Watchdog Timer). Because the microcontroller is sometimes affected by environmental factors such as noise and radio frequency interference and enters an erroneous operating state. The function of the watchdog timer is to reset the microcontroller within a certain time limit, so as to recover it from the erroneous state and restart normal operation. When T3 is used as a watchdog timer and the timing is started by the software, if the system has reached the set predetermined time and has not restarted the timer, an overflow signal will be generated and the timing will stop, indicating that the system is abnormal. The CPU can restart the timer, clear it, set the timing value, etc. When the system is running normally, the CPU will periodically restart the timer. Of course, its startup cycle should be less than the set value of the timer to ensure that the timer can never generate an overflow signal. When the system is not running normally, since the CPU cannot start the timer periodically, the timer will generate an overflow signal to force the CPU to resume normal operation of the system.

2.2 Internal structure principle of Watchdog

The structural principle of the watchdog timer is shown in Figure 2. Its core is an 8-bit timer, and its predecessor is an 11-bit scaler. The latter's input signal is fosc/12, that is, the scaler counts the machine cycle incrementally. In this way, the value of timer T3 increases 1000 times every 2 machine cycles. If a 16MHz or 24MHz crystal oscillator is used, the increment interval of the watchdog timer will be 1.536ms and 1.024ms respectively; the corresponding maximum overflow period is 393.216ms and 262.144ms respectively.

When the watchdog timer overflows, the system will generate an internal reset pulse to reset the 8XC552. As shown in Figure 2, when T3 overflows, the transistor inside the RST pin is turned on instantaneously due to a negative pulse on the gate, thereby outputting a reset positive pulse on the RST pin with a width of 3 machine cycles. If the RST pin is connected to an external capacitor, such a narrow output pulse may be destroyed because the capacitor does not allow the RST pin voltage to change suddenly, but this will not affect the internal reset operation.

If the pin of 8XC552 is connected to a low level, the path of the input signal to the scaler will be unobstructed, so the monitoring timer will operate normally. However, if the pin is connected to a high level, the input signal will not pass because the AND gate is blocked, and the monitoring timer is in the off state. It should be noted that once T3 is turned on, it cannot be turned off by software; at the same time, if T3 is disabled by EW, it cannot be started by software.

If = 0, the PD bit of the PCON register cannot be written, its initial value is 0, and it cannot be set to 1, that is, it cannot enter the power-down mode. Therefore, the watchdog timer and power-down mode cannot be used at the same time.


[page]

3 Common Problems in Debugging and Their Solutions

When debugging the system, there may be screen flashing, no display, or cluttered display. The solutions to these problems are introduced as follows:

(1) LCD screen flickers and the screen cannot be flipped

When I was programming with the emulator, the LCD could flip the screen and continuously display the collected three-phase power parameters, but when the emulator was off-line, the LCD could only display the first screen of data. After checking, it was found that the pin of the emulator was connected to a high level, and the pin was suspended when offline, which caused the pin to be unstable and continuously generate an internal reset signal to reset the microcontroller, resulting in the above phenomenon. Later, the pin was connected to a low level, and the above phenomenon still occurred. After the pin was connected to a high level (i.e., the Watchdog function was disabled), the LCD displayed normally. Therefore, the pin should be strictly prohibited from being suspended to avoid an unstable state, and before the Watchdog program is loaded, its pin should not be connected to a low level.

(2) LCD has no display

The capacitor at the RST end must be connected correctly, otherwise it will not be able to be added to the reset end when it is at a high level and the CPU will be unable to run the program, resulting in no LCD display.

(3) LCD display data is messy

Disorganized, data deadlock

If the pin is connected to a low level, the LCD may display chaotic data or data deadlock. The reason is that the Watchdog program is not loaded in the source program. Therefore, the Watchdog program should be added to the source program to eliminate data deadlock or chaotic display.

4. Software Design

4.1 Software Design

When writing software to run the watchdog timer, the programmer should first determine the time the system can support in an error state, which is the basis for setting the overflow cycle. For example, if it can maintain 16ms, the initial value of T3 is set to 10. In this way, in the case of a 16MHz crystal oscillator, the overflow cycle is 15.36ms. At this time, the programmer can divide his software to determine where to insert the instruction to rewrite the T3 value so that the interval between two adjacent rewrite operations does not exceed the overflow cycle of the watchdog timer to ensure that T3 does not overflow during normal operation. Therefore, the programmer should understand the execution time of all software modules, and also consider the impact of factors such as conditional jumps, subroutines, and internal and external interrupts. For those program sections whose execution time is difficult to estimate, the worst case should be estimated. To prevent miswriting, the rewriting of the watchdog timer value can be carried out in two steps. First, set PCON.4 (watchdog timer load enable bit WLE) to 1 to allow writing to T3; the second step is to write a new value to T3. As shown in Figure 2, the write signal to T3 is also added to the clear terminal of WLE, so whenever a new value is written to T3, the WLE bit is automatically reset. Therefore, when the value is 00H, the overflow interval is the largest; and the FFH value corresponds to the minimum overflow period. If a 12MHz crystal oscillator is used, these two values ​​are 524ms and 2ms respectively. The calculation formulas for the maximum and minimum overflow periods are:

Since the watchdog timer runs normally in idle mode, this mode is contradictory to the power-down mode, because the former requires a clock, while the latter freezes the clock. Therefore, when = 0 and T3 is turned on, the 8XC552 will not be able to enter the power-down mode. At this time, the operation of writing 1 to PCON. 1 is invalid, so it will remain 0. In the early stage of software development and debugging, the pin can be connected to a high level to turn off the watchdog timer, and then connected to a low level to complete the debugging process in the later stage.

4.2 Setting the timing interval and access time

Data acquisition and processing are the key parts of the program and the key to determining the accuracy of the instrument. This instrument uses voltage, current, frequency, and phase as the main acquisition parameters, and these parameters are continuously changing. Therefore, the sampling time should not be set too long, otherwise it will affect the accuracy of the instrument. The author sets the sampling time of current and voltage to 5ms, and the acquisition time of frequency and phase to 20ms. In this way, the timing interval of Watchdog is set better, as shown in Figure 3. In Figure 3, Watchdog completes the monitoring of the acquisition frequency data within the WDT1 time, and is responsible for the monitoring of voltage, current, and phase data acquisition in WDT2, WDT3, and WDT4. When designing the program, it is generally taken as 1.1Ts<Tw<2Ts, where Ts is the sampling period, Tw is the timing time of Watchdog, Ts is the size of T1, T2, T3, and T4 respectively, and Tw is the size of WDT1, WDT2, WDT3, and WDT4 respectively. If Tw is set too small, the access frequency will increase and affect the efficiency of program execution; if it is set too large, it will interfere with the normal operation of the program and it will take a long time to resume operation, and the acquisition or control object may have deviated too much at this step. Therefore, in principle, the CPU access time can be less than Tw. To prevent inaccurate time estimation, it is better to design it smaller, so as to prevent the system from being abnormal and being in an endless loop that starts every Tw time.

4.3 Software Program

This intelligent monitoring instrument is programmed in C language and uses a 12MHz crystal oscillator. Its overflow time should be set to 6ms, 20ms, 524ms, etc. Therefore, the Watchdog programs that should be added to the source program in due time are as follows:

5 Conclusion

After adding Watchdog to the source program of the intelligent power distribution instrument, the operation of the entire system will be more stable and reliable, thus effectively overcoming various interferences from industrial power consumption sites.

References

1. Li Xun, Liu Yuan. Practical Tutorial of Single Chip Microcomputer [M]. Beijing: Beijing University of Aeronautics and Astronautics Press, 2000. 131-132
2. Liang Yongming, Gan Minliang. Development of a New Intelligent Load Monitor for Distribution and Transformation [C]. Nanjing, Jiangsu: Proceedings of the Fourth Postgraduate Academic Conference of Nanjing University of Aeronautics and Astronautics, 2002. 9-15
3. Liang Yongming, Gan Minliang. Application of MGLS12864 LCD in 87C552 Single Chip Microcomputer System. Beijing: Modern Display, 2002, 32-35
Keywords:Watchdog  87C552 Reference address:Application of Watchdog in 8XC552 Series MCU System

Previous article:Design of decoder based on AT89C2051
Next article:Design of Data Acquisition System Based on USB Bus and 89C51 Single Chip Microcomputer

Recommended ReadingLatest update time:2024-11-16 15:50

S3C6410 WATCHDOG TIMER (watchdog timer) driver under Linux (2)
In the previous article, we looked at the overall architecture of the watchdog driver implementation in Linux, which exists as a hybrid device and a platform device. Now let's look at the probe function corresponding to the platform device. static struct platform_driver s3c2410wdt_driver = { .probe = s3c2410wdt_prob
[Microcontroller]
S3C6410 WATCHDOG TIMER (watchdog timer) driver under Linux (2)
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号