Anti-interference design of single chip microcomputer software system

Publisher:喜悦的38号Latest update time:2015-03-25 Source: diangonKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
  To improve the reliability of the MCU application system, we must start with the hardware and software and improve the system's own defense behavior. The following methods to improve reliability are not used alone. Only by effectively combining these methods according to the actual situation can we achieve the best anti-interference effect and make our MCU system work stably and reliably. Of course, the reliability of the MCU system operation will also be affected by other uncertain factors.


  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.

Keywords:MCU Reference address:Anti-interference design of single chip microcomputer software system

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

51 MCU Study Notes - Based on Assembly Language (2)
This blog mainly starts to talk about the assembly instructions of the 51 series microcontroller. We need the environment Keil. The version doesn't matter, they are all similar. As for how to build a project in Keil, I don't need to tell you. You can Baidu it yourself. 1. Assembly instructions 1.1 Instruction Format
[Microcontroller]
51 MCU, 18B20, 1602 thermometer + serial communication
The actual picture produced is as follows:   The simulation schematic diagram is as follows (the proteus simulation project file can be downloaded in the attachment of this post) Host computer:     Unzip the installation program to the same directory. Then run setup to install. . . . Thermometer.exe
[Microcontroller]
51 MCU, 18B20, 1602 thermometer + serial communication
51 MCU software-controlled PWM LED gradual brightening and dimming effects
#include sbit LEDR = P2 ^ 5; // A red LED is connected to the P2.0 pin sbit LEDG = P2 ^ 6; // A green LED is connected to the P2.1 pin void delay (unsigned char d){ // Delay function--the delay length is determined by d     unsigned char i;  while( d-- != 0)  {    for(i = 0; i 8; i++);  }          }
[Microcontroller]
51 single chip microcomputer 16X16 dot matrix circular scrolling display Chinese characters
1. Effect display 2. Materials used 1.16X16 dot matrix Proteus does not provide 16X16 dot matrix, we can only assemble 4 8X8 into 16X16 dot matrix by ourselves. From this we can see that 8*8 becomes 16*16 The columns need to be concatenated like this: The rows need to be connected like this: Put the four t
[Microcontroller]
51 single chip microcomputer 16X16 dot matrix circular scrolling display Chinese characters
Espressif Systems' revenue grew 9.75% in 2020, and is expected to have the largest market share in the Wi-Fi MCU field
On February 26, Espressif Systems released its 2020 annual report. The company achieved operating income of RMB 831.2865 million, an increase of 9.75% over the same period in 2019; net profit attributable to shareholders of listed companies was RMB 104.0520 million, a decrease of 34.35% over the same period in 2019.
[Mobile phone portable]
Espressif Systems' revenue grew 9.75% in 2020, and is expected to have the largest market share in the Wi-Fi MCU field
LPC1768 MCU serial port IAP upgrade example source code
LPC1768 IAP upgrade method example   Test instruction:     This experiment uses serial port 0 to upgrade the development board through IAP. This project is a boot program. Connect the USB to serial port on the development board to the computer.     Plug in the 3.2-inch color screen module, download the program to the
[Microcontroller]
Application of Hard Disk Storage on Single Chip Microcomputer
The 8031 ​​series microcontroller is a widely used CPU, but as the control field continues to become more intelligent and complex, the program and data space may be much larger than the 64K byte limit. By expanding the hard disk interface on the 8031 ​​series microcontroller, the storage capacity is only limited by the
[Microcontroller]
DIY design of using open source microcontroller to set GPS + Google map positioning
I like to travel with friends and go fishing. I made a black box for myself and would like to share it with you! Function: When you are out and about and encounter difficulties, turn it on. The hardware will access the Internet through the mobile phone card, send the personal location to a specified IP, and display it
[Power Management]
DIY design of using open source microcontroller to set GPS + Google map positioning
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号