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
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
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
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- 【K210 Series】3. Core board connection
- The problem of repeated declaration of global variables in embedded C programming
- UWB can use the frequency band in China,,,,
- What should I do if I have a colleague who is nagging and incompetent?
- A feasible solution to the problem that the USB-Blaster driver cannot be successfully installed during the Quartus II 9 software installation and configuration
- The SGM42507 is a full-bridge driver designed for small motors and electromagnets.
- EEWORLD University ---- HVI Series: Design Considerations for High Power Density and High Efficiency Adapters
- MSP430Ware use notes to initialize XT1
- Open source program for automatic generation of dq current lookup table for permanent magnet synchronous motor of electric vehicle based on weak magnetic field lookup method
- What are the causes of IGBT damage in variable frequency power supply?