Once you have mastered the skills, do you still dare to say that learning microcontrollers is difficult?

Publisher:钱老李Latest update time:2022-12-07 Source: zhihu Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

In the development of microcontroller applications, engineers are still troubled by issues such as code usage efficiency, microcontroller anti-interference and reliability. In order to help engineers solve the problems in microcontroller design, several basic skills that should be mastered in microcontroller development are summarized.


1. How to improve the efficiency of C language programming code.

Using C language to program microcontrollers is an inevitable trend in the development and application of microcontrollers. If you want to achieve maximum efficiency when programming in C, it is best to be familiar with the C compiler you are using. First test the number of lines of assembly language statements corresponding to each C language compiler, so that you can clearly know the efficiency. When programming in the future, use the statement with the highest compilation efficiency.

Each C compiler will have certain differences, so the compilation efficiency will also be different. The code length and execution time of an excellent C compiler for embedded systems are only 5-20% longer than the same function written in assembly language.

For complex projects with tight development time, C language can be used, but the prerequisite is that you are very familiar with the C language and C compiler of the MCU system. Pay special attention to the data types and algorithms supported by the C compilation system.

Although C language is the most common high-level language, different MCU manufacturers have different C language compilation systems, especially in the operation of some special function modules. Therefore, if you do not understand these features, there will be many problems during debugging, which will lead to lower execution efficiency than assembly language.
2. How to reduce bugs in the program?

Some suggestions were given on how to reduce program bugs, pointing out that the over-range management parameters that should be considered during system operation are:

1. physical parameters. These parameters are mainly the input parameters of the system, which include excitation parameters, operating parameters during acquisition processing and result parameters at the end of processing. Set these boundaries reasonably, and treat parameters beyond the boundaries as abnormal incentives or abnormal responses for error handling.

2. Resource parameters. These parameters are mainly the resources of circuits, devices, and functional units in the system, such as memory capacity, storage unit length, and stacking depth. In programming, resource parameters are not allowed to be used out of scope.

3. Application parameters. These application parameters are often represented by the application conditions of some microcontrollers and functional units. Such as E2PROM erasure and write times and data storage time and other application parameter limits.

4. process parameters. Refers to the parameters that change in an orderly manner during system operation.


3. How to solve the anti-interference problem of the microcontroller.

The most effective way to prevent interference is to remove the interference source and block the interference path, but it is often difficult to do so, so we can only see whether the anti-interference ability of the microcontroller is strong enough. The most common phenomenon of microcontroller interference is reset; as for program runaway, software traps and watchdogs can actually be used to bring the program back to the reset state; therefore, the most important thing for microcontroller software to resist interference is to handle the reset state.

Generally, microcontrollers will have some flag registers that can be used to determine the cause of reset; in addition, you can also bury some flags in RAM yourself. Each time the program is reset, different reset causes can be determined by judging these flags; you can also jump directly to the corresponding program based on different flags. This allows the program to run continuously, and the user will not notice that the program has been reset when using it.
4. How to test the reliability of a single-chip microcomputer system.

Some readers want to know what methods are used to test the reliability of the single-chip microcomputer system. "When a single-chip computer system design is completed, there will be different test items and methods for different single-chip computer system products, but there are some It is necessary to test:

1. Test the completeness of the microcontroller software function. This is a test for all microcontroller system functions.

2. The user will inevitably encounter power-on and power-off tests. The power supply can be turned on and off multiple times to test the reliability of the microcontroller system.

If necessary, the reliability of the microcontroller system can be tested under high temperature, high pressure and strong stress conditions. Test in an electromagnetic interference environment.

4. ESD and EFT tests. Various interference simulators can be used to test the reliability of the microcontroller system. For example, use an electrostatic simulator to test the anti-static ESD capability of the microcontroller system; use surge noise simulation. It can also perform fast pulse anti-interference EFT tests and so on.

It can also simulate the damage that may occur during human use, such as deliberately rubbing the contact port of the microcontroller system with a high-power electric drill. Work close to the microcontroller system to test the ability to resist electromagnetic interference.

Reference address:Once you have mastered the skills, do you still dare to say that learning microcontrollers is difficult?

Previous article:Daniel summarizes several important concepts of microcontrollers
Next article:How to "build a conversation" between different types of microcontrollers? From these examples

Latest Microcontroller Articles
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号