In the development of single-chip microcomputer applications, engineers are still troubled by code efficiency, anti-interference and reliability of single-chip microcomputers. In order to help engineers solve the problems in single-chip microcomputer design, several basic skills that should be mastered in single-chip microcomputer development are summarized based on the discussions in the forum.
1. How to improve the efficiency of C language programming code
Deng Hongjie pointed out that using C language for MCU programming is an inevitable trend in MCU development and application. "If you want to achieve the highest efficiency when programming in C, it is best to be familiar with the C compiler you are using. First test the number of assembly language statements corresponding to each C language compilation, so that you can clearly know the efficiency. When programming in the future, use the statements with the highest compilation efficiency."
He pointed out that each company's C compiler has some differences, so the compilation efficiency will also be different. The code length and execution time of an excellent embedded system C compiler are only 5-20% longer than the same functional level written in assembly language. "For complex projects with tight development time, you can use C language, but the premise is that you are very familiar with the C language and C compiler of the MCU system, and pay special attention to the data types and algorithms that the C compiler system can support.
Although C is the most common high-level language, different MCU manufacturers have different C language compiler systems, especially in the operation of some special function modules. Therefore, if you don’t understand these features, there will be many problems in debugging, which will lead to lower execution efficiency than assembly language. "
2. How to reduce bugs in programs?
Deng Hongjie gave some suggestions on how to reduce program bugs. He pointed out that the out-of-range management parameters that should be considered in system operation are:
1. Physical parameters. These parameters are mainly the input parameters of the system, including excitation parameters, operating parameters in the acquisition process, and result parameters after the process. Reasonable boundaries should be set, and parameters that exceed the boundaries should be treated as abnormal excitation or abnormal response and error handling should be performed.
2. Resource parameters. These parameters are mainly the resources of the circuits, devices, and functional units in the system, such as memory capacity, storage unit length, and stack depth. In programming, resource parameters are not allowed to be used beyond the scope.
3. Application parameters. These application parameters are often expressed as the application conditions of some single-chip microcomputers and functional units, such as the number of erase and write times and data storage time of E2PROM and other application parameter limits.
4. Process parameters: Refers to the parameters that change in an orderly manner during the operation of the system.
3. How to solve the anti-interference problem of MCU
Deng Hongjie pointed out: The most effective way to prevent interference is to remove the interference source and cut off the interference path, but it is often difficult to do so, so we can only see whether the anti-interference ability of the MCU is strong enough. The most common phenomenon of MCU interference is reset; as for the program running away, in fact, the software trap and watchdog can also be used to pull the program back to the reset state; so the most important thing for MCU software anti-interference is to handle the reset state well.
Generally, microcontrollers have some flag registers that can be used to determine the reset reason. In addition, you can also bury some flags in RAM. Every time the program is reset, by judging these flags, you can determine different reset reasons; you can also jump directly to the corresponding program according to different flags. This can make the program run continuously, and the user will not notice that the program has been reset when using it.
4. How to test the reliability of the MCU system
Some readers want to know what methods are used to test the reliability of the MCU system. Deng Hongjie pointed out: "When a MCU system is designed, there will be different test items and methods for different MCU system products, but there are some that must be tested:
1. Test the completeness of the MCU software functions. This is a test of all MCU system functions to test whether the software is written correctly and completely.
2. Power-on and power-off test. During use, users will inevitably encounter power-on and power-off situations. The power supply can be turned on and off multiple times to test the reliability of the microcontroller system.
3. Aging test. Test the reliability of the MCU system under long-term working conditions. If necessary, it can be tested in a high temperature, high voltage and strong electromagnetic interference environment.
4. Tests such as ESD and EFT. Various interference simulators can be used to test the reliability of the microcontroller system.
Previous article:How to remove the read protection of the STM8S chip that is set to read protection and re-download the program
Next article:Development process of single chip microcomputer application system
- Popular Resources
- Popular amplifiers
- Semantic Segmentation for Autonomous Driving: Model Evaluation, Dataset Generation, Viewpoint Comparison, and Real-time Performance
- ESP32 Formats and Communication Application of Communication Protocols with ESP32 Microcontroller
- Electronics Principles and Applications 9th Edition by CHARLES A.SCHULER
- ARM Cortex M4 cookbook
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- #Idle Market# Memory stick, CPU
- TI millimeter wave radar classification and technical solutions
- The SD card driver code is really difficult
- I have a question, what is the principle of the Wolman amplifier circuit, the role of the common-emitter amplifier and the common-base amplifier, and how do they amplify?
- Two-color illustration of the core knowledge and selection of electronic components
- Summary of power supply design data:
- Ended | Live broadcast [Cloud-based secure authentication | Microchip embedded security solutions]
- ST60 millimeter wave water medium data transmission test report
- Schematic diagram of a simple TWS charging box consisting of a common LTH7 charging chip + lithium battery boost and protection
- Please tell me, how to make a dual power automatic switching circuit?