1. Instruction redundancy
The CPU fetches instructions by first fetching the opcode and then the operand. Artificially inserting some single-byte instructions in the key places of the program, or rewriting the valid single-byte instructions is called instruction redundancy. Usually, two or more NOP instructions are inserted after the double-byte instructions and three-byte instructions. In this way, even if the program runs away and flies to the double-byte instructions and three-byte instruction operands. Due to the existence of the narrow operation instruction NOP, the subsequent instructions are prevented from being executed incorrectly, preparing for the program to be put on the right track. In addition, instructions that play an important role in the system flow, such as RET, RETI, LCALI., LJMP, JC, etc., can insert two NOP instructions after these instructions, which can put the runaway program on the right track to ensure the execution of these important instructions. Instruction redundancy can only prevent the CPU from mistakenly executing the operand as the opcode, but it cannot actively reverse the wrong execution direction of the program. To correct the wrong execution direction of the program, the following technology is required.
2. Design software "traps"
usually fill the unused EPROM space in the program memory with narrow operation instructions NOP, and finally fill in a jump instruction to jump to the runaway processing program, or directly fill in the instruction LJMP 0000H. When the runaway program falls into this area, it can return to the normal track after executing a period of empty operations. If the unused EPROM space is relatively large, you can evenly fill in several empty operation instructions and jump instructions. This structure of several empty operation instructions plus a jump instruction is called a "software trap". The
general structure of the software trap is:
NOP
NOP
LJMP FLY
FLY is the runaway processing subroutine. If the program is executed normally, the software trap part will never be executed. Only when the program runs into the trap, the software trap will immediately jump the program to the normal track. Even if the program does not run into the trap, it can encounter a software trap after the program executes a period of erroneous operation, thus returning to the normal track. In addition to the blank area of the program memory, a software trap should also be set at the end of the program's data table. If the data table is relatively large, a software trap should also be set in the middle of the data table to ensure that the program can be put back on track in time when it runs away to the data area. In addition, if the space of the program memory is large enough, a software trap can be set between every two subroutines. When the interrupt used is opened due to interference, a software trap is set in the corresponding interrupt service program to capture the wrong interrupt in time. The number of software traps should be determined according to the actual interference situation and the capacity of the program memory. If there are too few, effective runaway interception cannot be performed, and if there are too many, a large amount of program memory space will be occupied.
3. Software "watchdog" technology
After executing some wrong operations, the runaway program often enters a "dead loop", which is often called "freeze". Usually, the "software watchdog" technology is used to get the program out of the "dead loop". The principle of the software "watchdog" technology is to continuously detect the program loop running time. If it is found that the program loop time exceeds the maximum loop running time, it is considered that the system is trapped in a "dead loop" and error handling is required. In practical applications, the timing interrupt service program is usually used to regularly check the operation of the main program. For example, a byte is selected in the RAM area as the software watchdog register. The main program adds 1 to the register every time it loops, and the interrupt service program of the timer TO decrements the register and checks it once every time it interrupts. If the program executes normally. The watchdog register will not change or change slightly. If the watchdog register changes or changes significantly, it means that the system is trapped in a "dead loop" and error handling is required. In industrial applications, serious interference sometimes destroys the interrupt mode control word, turns off the interrupt, and causes the watchdog to fail. At this time, a ring interrupt monitoring system can be used. Use timer TO to monitor timer Tl, use timer Tl to monitor the main program, and the main program to monitor timer T0.
The software "watchdog" using this ring structure has good anti-interference performance and greatly improves the system reliability. For the measurement and control system that needs to frequently use the Tl timer for serial communication, the timer Tl cannot be interrupted, and can be monitored by the serial port interrupt instead. Of course, the maximum cycle of the main program, the timer T0 and the Tl timing cycle should be considered reasonably in the whole. The software "watchdog" technology requires the use of timers, and in most control programs, timers are scarce resources. This limits the practical application of the "software watchdog" technology. We can take some tricks to reuse the same timer for the software "watchdog" program and other timing programs, so that both the timing function and the software "watchdog" function can be completed.
4. Check the RAM area flag data to find serious interference in time
This method is to select several fixed units in the RAM area and set them to fixed data in the initialization program. As long as the program runs normally, the contents of these units will not change. If the data of any of these RAM units changes due to program "runaway" or other interference, it means that the microcontroller system has been seriously interfered and cannot run reliably. We can check the contents of these RAM units in a timely manner during the execution of the program. Once the data is found to have changed, the LJMP 0000 H statement is immediately executed to force the microcontroller to reset.
5. Refresh output port
Eliminate serious interference. When the MCU system is seriously interfered, the state of the output port may also change due to interference. During the execution of the program, timely refresh the output port according to the calculation results of the relevant program modules to eliminate the influence of interference on the state of the output port, so that the wrong output state can be corrected in time.
6. Perform multiple input sampling
Avoid serious interference. Strong interference will affect the input signal of the MCU, causing errors or misreading of the instantaneous sampling of the input signal. To avoid the influence of interference, repeated sampling and weighted averaging are usually adopted.
Previous article:The difference between microcontroller and plc
Next article:Single chip microcomputer principle and application test questions
Recommended ReadingLatest update time:2024-11-16 21:28
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
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
- EEWORLD University ----TI EV/HEV 48V and Motor Drive Solutions
- Paper cups, paper diapers, even paper airplanes, why can’t we have paper batteries?
- [GD32L233C-START Review] 6. Fingerprint Management System (2) - Added brightness adjustment
- [Sipeed LicheeRV 86 Panel Review] 15. lvgl calendar control and weather display
- Can RTthread be ported to nrf51822?
- A bug solution for CH548/CH549 ADC routine
- [Project source code] BMP2mif file software, convenient for using ROM to store image data and display
- I want to control the on and off of NMOS through a 3.3V microcontroller
- Domestic FPGA brand Anlu
- The load is a 3000W heating plate, controlled by two 16A relays