Microcontroller Programming FAQs

Publisher:飘然出尘Latest update time:2011-08-25 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. What are the advantages and disadvantages of C language and assembly language when developing microcontrollers?
Answer: Assembly language is a symbolic language that uses text mnemonics to represent machine instructions. It is the language closest to machine code. Its main advantages are that it takes up less resources and has high program execution efficiency. However, different CPUs may have different assembly languages, so it is not easy to port.

C language is a structured high-level language. Its advantages are good readability and easy porting, and it is a widely used computer language. Its disadvantages are that it takes up more resources and its execution efficiency is not as high as assembly language.

For the 8-bit MCU with RISC architecture that is currently widely used, its internal ROM, RAM, STACK and other resources are limited. If it is written in C language, a C language instruction will become many machine codes after compilation, which may easily cause problems such as insufficient ROM space and stack overflow. In addition, some microcontroller manufacturers may not be able to provide C compilers. In assembly language, one instruction corresponds to one machine code, and it is very clear what action is performed at each step. In addition, the program size and stack call status are easy to control, and debugging is also more convenient. Therefore, in the development of microcontrollers, we still recommend the use of assembly language.

If you are interested in the C language for microcontrollers, HOLTEK's microcontrollers provide a C compiler, which can be downloaded and used for free from HOLTEK's website.

2. C or assembly language can be used for microcontrollers, can C++ be used?
Answer: In microcontroller development, assembly and C are mainly used, and C++ is not used.

3. Do I need to know C to develop single-chip microcomputers?
Answer: Assembly language is a symbolic language that uses text mnemonics to represent machine instructions. It is the language closest to machine code. Its main advantages are that it takes up less resources and has high program execution efficiency. However, different CPUs may have different assembly languages, so it is not easy to port.

For the 8-bit MCU with RISC architecture that is currently widely used, its internal ROM, RAM, STACK and other resources are limited. If it is written in C language, a C language instruction will become many machine codes after compilation, which may easily cause problems such as insufficient ROM space and stack overflow. In addition, some microcontroller manufacturers may not be able to provide C compilers. In assembly language, one instruction corresponds to one machine code, and it is clear what action is performed at each step. In addition, the program size and stack call status are easy to control, and debugging is also more convenient. Therefore, in the development of microcontrollers with fewer resources, we still recommend the use of assembly language.

C language is a compiled programming language that takes into account the characteristics of multiple high-level languages ​​and has the functions of assembly language. C language has rich library functions, fast computing speed, high compilation efficiency, good portability, and can directly control system hardware. C language is a structured programming language that supports the top-down structured programming technology widely used in current programming. In addition, C language programs have a complete module program structure, which provides a strong guarantee for the use of modular programming methods in software development. Therefore, using C language for programming has become a mainstream in software development. Using C language to write target system software will greatly shorten the development cycle, significantly increase the readability of the software, and facilitate improvement and expansion, thereby developing a larger system with more complete performance.

In summary, using C language for MCU programming is an inevitable trend in MCU development and application. Therefore, as a MCU developer who has comprehensive technology and is involved in large-scale software system development, it is best to master basic C language programming.

4. When developing a complex project with a short development time, is it better to use C or assembly?
Answer: For complex projects with a 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 language is the most common high-level language, the C language compiler systems of different MCU manufacturers are different, especially in the operation of some special function modules. If you don't understand these features, it will be troublesome to debug, and in the end it may not be as fast as using assembly.

5. 在教学中要用到8088和196芯片单片机教材,请问那里可以找到关于这方面的书或资料?
答:有关这方面的教材,大学里常用的一本是《IBM-PC汇编语言程序设计》清华大学出版社出版的,在网上以及书店都是可以找到的,另外网上还可以搜索到很多其他的教材如:《微机原理及汇编语言教程》(杨延双 张晓冬 等编著 )和《16/32 位微机原理、汇编语言及接口技术》(作者: 钟晓捷 陈涛 ,机械工业出版社 出版)等,可以在较大型的科技书店里查找或者直接从网上订购。

6. Should beginners learn C or assembly first?
Answer: For MCU beginners, they should start with assembly language. Because assembly language is the language closest to machine code, it can deepen beginners' understanding of each functional module of MCU, thus laying a solid foundation.

7. I am a third-year student of electronic science and technology at Wuhan University. I have learned electronic circuits, digital logic, assembly and interface, and C language, but I always feel confused and feel like I don't know anything. What should I do?
Answer: The university process is a theoretical process, and there are relatively few opportunities for practice, which often leads to a disconnect between theory and practice. This is a common problem in the domestic university education system, but students must not aim too high. Generally, you will start to get in touch with some professional courses from the third year of college. Electronic-related majors will offer related single-chip microcomputer application courses and simple experimental projects. You should fully grasp the opportunities of experimental classes and practice more on the actual machine operation. You can usually read more related electronic technology magazine websites to see other people's development experience, hardware design solutions and other people's software design experience. If possible, you can also participate in some electronic design competitions. Taking this opportunity, 2-3 people will work together to make a complete system, which will be more helpful. When you reach the fourth-year graduation design stage, you can also choose related topics to do some actual cases to gain experience. There is a process of accumulating experience in everything you do, step by step.

8. As a student, how can I learn MCU well?
Answer: To learn MCU well, the most important thing is practice, and gain experience in practice. For students in school, there are indeed fewer opportunities for practice, but if there is a chance, you can choose related topics for graduation internship, so that you can get in touch with actual projects. And if the principle of MCU is a main course, I believe the school will arrange more opportunities for practice. If you have the ability, you can find some related part-time jobs, which will be more helpful. Moreover, the development and application of MCU requires the combination of software and hardware, so you can't just be satisfied with how perfect the programming skills are. You should also pay attention to the accumulation of hardware knowledge, go to electronic forum websites more often, and buy some related magazines. If possible, you can go to the electronics market to buy some small parts and build a small system to make it work.

HOTLEK's MCU is an 8-bit RISC-structured MCU, which can be widely used in household appliances, security systems, handheld games, etc. Generally speaking, it can be divided into I/O type MCU, LCD type MCU, A/D type MCU, A/D with LCD type MCU, etc.

9. How can one become a master of single-chip microcomputers?
Answer: To become a master of single-chip microcomputers, one should practice more, always pay attention to the development trend of single-chip microcomputers, and often visit some related websites, where one can find a lot of useful information.

10. Are women suitable for the MCU software programming industry?
Answer: It depends on one's own interests and patience for software programming. Both men and women are suitable for this industry.

12. How long can 8-bit machines last!

Answer: At present, the main MCU products are still in the 8-bit field, mainly used in six major markets, namely automotive applications, consumer electronics, computers and PC peripherals, telecommunications and communications, office automation, and industrial control. Among them, the automotive market is mostly in Europe and the United States, while the Asia-Pacific region is dominated by consumer electronics, and large quantities and low unit prices are the mainstream products. At present, there is still a considerable price difference between 16-bit MCUs and 8-bit products, and new application fields are still being developed. The industry predicts that 8-bit MCUs will still be the mainstream MCU products at least before 2005.

13. Is learning ARM and embedded systems more promising than learning other general single-chip microcomputers? What relevant knowledge should a beginner have?
Answer: Generally, there is a difference in the level of embedded systems between 8-bit single-chip microcomputers and ARM. ARM is suitable for advanced products with relatively complex systems, such as PDAs, mobile phones, etc. 8-bit single-chip microcomputers are suitable for general industrial control, consumer home appliances, etc. due to their simple architecture and relatively few hardware resources. For a beginner in software programming for single-chip microcomputers, HOLTEK series or 8051 and other 8-bit single-chip microcomputers should be used as introductory exercises. Beginners should have relevant knowledge of software programming. The general software programming of single-chip microcomputers is mainly based on assembly language. Each company has its own syntax, but most of them are based on the RISC MCU architecture, where RISC (Reduced Instruction Set Computer) represents all the instructions of the MCU. They are all composed of some simple instructions. Simple instructions mean that the circuit of the MCU can be optimized as much as possible, thereby increasing the execution rate. In addition, beginners must have application knowledge of the microcontroller I/O interface, which depends on the use of peripheral application circuits and various components, and must be coordinated with what they have learned in electronics and circuits.

14. What are the 80 series 8-bit MCUs that conform to 44PIN?
Answer: The 80 series 8-bit MCUs that conform to 44PIN are Z8674312FSC, Z86E2112FSC, and Z86E2116FSC.

15. Please introduce the testing methods of MCU.
Answer: There are different testing methods for each stage of MCU from production to packaging and shipment, and there are mainly two types: intermediate test and final test.

The so-called intermediate test is the test of WAFER, which includes product function verification and AC and DC tests. There are many items, and the main items are as follows, taking HOLTEK products as an example:

Continuity test: Check whether the protection diodes connected to each I/O PIN function correctly.
Functional test: Use the test data (TEST PATTERN) provided by the product designer to inject the IC and check whether the result is the same as the state during SIMULATION.
STANDBY current test: Measure whether the leakage current of each contact (PAD) when the IC is in HALT mode, that is, when each contact (PAD) remains unchanged in state 1, state 0 or state Z, meets the minimum specification.
Power consumption test: Static power consumption and dynamic power consumption of the entire IC. Input voltage test
: Measure the input voltage response characteristics of each input pin.
Output voltage test: Measure the output voltage level of each output pin.
Related frequency characteristics (AC) test is also to see whether the output matches the I/O port by injecting a certain frequency externally.
In order to ensure the long-term and stable quality of IC production, product reliability tests will also be performed. These tests include ESD test, LATCH UP test, temperature cycle test, high temperature storage test, humidity storage test, etc.

Final test is the test after the product is packaged, that is, PACKAGE test. That is, all products that have passed the intermediate test are tested after packaging. The method is mainly automatic testing of the machine, but the test items are still the same as WAFER TEST. The purpose of PACKAGE TEST is to determine whether the IC has any damage during the packaging process.

16. Can a single chip be used to detect the charging and discharging time of a mobile phone battery and the changes in voltage and current during charging and discharging, and use an I/O port to display the test results on a computer?
Answer: Most of the various types of smart chargers on the market currently use MCU to control the charging current and voltage. As for displaying on a computer, it seems not practical, and may only be used in some special battery testing instruments; for ordinary mobile phone users, who would need a computer to display when charging? To achieve the connection between a single-chip microcomputer and a computer, the simplest way is to use serial communication, but you need to add an RS-232 chip.

17. What about ARM programming?
Answer: Taking the concept of embedded systems as an example, general embedded processors can be divided into three categories: embedded microprocessors, embedded microcontrollers, and embedded DSPs (Digital Signal Processors).

An embedded microprocessor is a CPU that corresponds to a general-purpose computer microprocessor. In applications, the microprocessor is usually mounted on a specially designed circuit board, and only embedded-related functions are retained on the motherboard, which can meet the requirements of small size and low power consumption of embedded systems. Current embedded processors mainly include: PowerPC, Motorola 68000, ARM series, etc.

Embedded microcontrollers are also called single-chip microcomputers. They package CPU, memory (a small amount of RAM, ROM or both) and other interface I/O in the same integrated circuit. Common ones include HOLTEK MCU series, Microchip MCU series and 8051.

Embedded DSP is specially used to process discrete time signals very quickly, improving compilation efficiency and execution speed. In the fields of digital filtering, FFT (Fast Fourier Transform), spectrum analysis, image processing analysis, etc., DSP is entering the embedded market in large numbers.

18. When the MCU is in radio frequency control, the clock (crystal oscillator) and data line of the MCU will radiate the base frequency or the multiple of the base frequency, which will be amplified by the low noise amplifier (LNA) and enter the mixing frequency, resulting in an in-band Spur that cannot be filtered out. In addition to using layout and selecting low-radiation MCU to reduce some of the radiation, are there any other methods?
Answer: There are many things to pay attention to when designing circuit boards for high-frequency circuits, especially high-frequency circuits at the GHz level. It is even more necessary to pay attention to the impact of the length of each electronic component pad and printed pattern on the circuit characteristics. In recent years, there seems to be an increasing trend for high-frequency circuits and digital circuits to share the same circuit board to form the so-called mixed-load circuit system. Designs like this often cause the high-frequency circuit to become unstable when the digital circuit is operating. One of the reasons is that the noise generated by the digital circuit affects the normal operation of the high-frequency circuit. In order to avoid the above problems, in addition to trying to split the two circuit blocks, it is the fundamental method to fully review the design concept before designing the circuit board. Basically, the following three principles must be mastered when designing circuit boards for high-frequency circuits:

High quality.
No shortcuts.
No rushing.

Here are some suggestions for designing high-frequency circuit boards:

(1) The length of the printed pattern will affect the circuit characteristics. In particular, for transmission lines of high-speed digital circuits with transmission speeds of GHz, strip lines are usually used, and the transmission delay time is corrected by adjusting the wiring length. In fact, this also means that the location of the electronic components has an absolute influence on the circuit characteristics.
(2) Ground is better. The ground layer is set on the entire copper foil surface, and the better ground connected to the via is a common feature of high-frequency circuit boards and high-speed digital circuit boards. In addition, high-frequency circuit boards are most taboo to use narrow printed patterns to depict ground.

(2) The ground terminal of the electronic component is connected to the ground of the circuit board with the shortest length. The specific method is to set a via near the ground terminal pad of the electronic component so that the electronic component can be connected to the ground of the circuit board with the shortest length.

(3) Design the signal line to be short. Do not increase the wiring length arbitrarily and try to shorten the wiring length as much as possible.

(4) Reduce the number of connections between circuits. It is especially important to separate the circuits between the filter and amplifier input and output, which is equivalent to the cross talk countermeasure for audio circuits.

(5) MCU circuit layout considerations: The oscillator circuit should only be as close to the IC oscillator pin as possible; the oscillator circuit should be kept at a sufficient distance from VDD & VSS; when the oscillation frequency is greater than 1MHz, there is no need to add osc1 & osc2 capacitors; the power supply and ground should be as short as possible and the lines should be as equal in width and distance as possible, and ceramic capacitors such as 104/103/102 should be added at the node position.

19. What precautions should be taken when developing a system for Intel's 96 MCU 80c196KB?
Answer: The software of a real-time system consists of a real-time operating system plus an application program. The interface between the application program and the operating system is implemented through system calls. For MCUs using the 80C196KB operating system, only the internal RAM can be used as the TCB and all system memory (including various control tables) as well as the work and data units of each task. Therefore, the following points must be noted:

(1) Each task is allocated its own stacking area, which serves as both the working unit of the task and the protection unit of the task control block.

(2) The system's task control block only stores the stack pointers of each task, while the task status is stored in the task stack. When a task exits execution, its status is pushed into the stack through an interrupt, and then its stack pointer is saved in the system's TCB; then the stack pointer SP image value of the highest priority ready task is taken out and sent to SP; finally, the interrupt return instruction is executed to execute the new task.

(3) The data and work units of each task are implemented as much as possible using stacks, which allows each task to use the same subroutine. Using stacks to implement parameter passing and as work units instead of using absolute address RAM can realize reentrant subroutines. This subroutine can be called by each task and can also be called recursively.

20. When sampling voltage on the demo board, it is unstable and the sampling result fluctuates. How to eliminate it?
Answer: Generally speaking, the simulator works in a stable voltage environment (usually 5V). If you use the A/D of the simulator, you should pay attention to whether its A/D reference voltage is given by the simulator or needs to be provided externally. A/D conversion requires a continuous clock cycle, so the single-step debugging method cannot be used during simulation, otherwise the A/D sampling value will be inaccurate. As for the unstable A/D sampling, you can add a capacitor to the A/D input port to play a filtering role; use the median filtering method during software processing.
21. In the car DVD system, how to design the electronic anti-vibration system?
Answer: In the car DVD system, it is best to choose a high-end DVD player, because high-end DVD players use an electronic anti-vibration system (ADVANCEDESP). When the reading in the memory buffer decreases, the advanced electronic anti-vibration design will use a dual-speed reading system to make a reading rate twice as fast as the normal speed to reduce noise. Even if there is continuous oscillation, it can still avoid the jumper situation. Now let's talk about what electronic anti-vibration is. Simply put: electronic shock protection is a signal storage-release process. First, the CD must read the signal in advance, that is, we see the acceleration of the machine, and then store the signal in RAM. What we hear when the shock protection is turned on is the sound passing through the RAM. This is the process. When there is no shock protection, the signal is read 1:1, so when it is impacted, there will be skipping. When the shock protection is turned on, after the machine is impacted, the sound released by the RAM makes the music play continuously, and at the same time, the optical head quickly resets and searches, and when the signal is retrieved, it is immediately supplemented, so there will be no skipping. This is roughly the situation. However, this does not meet the requirements of users. Since this method brings a short time, usually only 3 seconds, the chance of skipping is still quite high. If the RAM is increased, the cost will increase because RAM is expensive, especially good quality.

22. In the electronic anti-vibration technology, what ICs or devices are available?
Answer: In the electronic anti-vibration technology, one of the most important technologies is RAM technology. However, due to its cost, the anti-vibration time has not been increased. In other words, RAM itself has limitations. The larger the RAM capacity, the higher the cost. Many manufacturers have developed and researched how to maximize the memory time within the RAM limit.

23. How can programming reduce program bugs?
Answer: Here are some suggestions, because the actual operating parameters in the system are all within a range. The out-of-range management parameters to be considered in system operation are:

physical parameters. These parameters are mainly input parameters of the system, which include excitation parameters, operating parameters in the acquisition process, and result parameters at the end of the process. Set these boundaries reasonably, and treat the parameters that exceed the boundaries as abnormal excitation or abnormal response and handle them as errors.

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 program design, resource parameters are not allowed to be used beyond the scope.

Application parameters. These application parameters are often expressed as the application conditions of some single-chip microcomputers and functional units. For example, the number of erase and write times and data storage time of E2PROM and other application parameter limits.

Process parameters. Refers to the parameters that change in an orderly manner during the operation of the system.

For a programmer, it is necessary to develop a good habit to replace the above parameter groups with the corresponding lists of text parameters that he likes in order at the beginning of the program, and then use the text parameters that he defines to write the program. In this way, when modifying and maintaining the program, you only need to make changes at the beginning of the program, and there is no need to modify the program segments. This is easier and will not cause errors.

24. Some people think that MCU will be replaced by embedded systems with ARM and other series structures. How long will the life of MCU be?
Answer: Because of the difference in functional structure and unit price between 8-bit MCU and embedded system ARM, there is a big difference in application level. ARM is suitable for advanced products with large system complexity, such as PDA, mobile phone and other applications. 8-bit MCU is suitable for general industrial control, consumer home appliances, etc. due to its simple architecture and relatively few hardware resources. To evaluate whether MCU will be replaced by ARM in the near future, we need to observe two factors:

Chip cost
Because ARM has a high operating frequency and a large circuit, the required chip manufacturing process requires more than 0.25U, which is more expensive. The operating frequency of 8-bit microcontrollers is relatively low, and the circuit is smaller, so the required chip manufacturing process is only 0.5U, which is less expensive.

Functional positioning:
ARM has stronger functions than MCU, but the two have different positioning. Just like at this stage, no one will use ARM to make a simple industrial timer. Of course, it would be fine if the unit price of the two was the same, but the reality is that there is a big price difference.

As for the future, because the chip manufacturing cost will continue to decline, the above cost difference will have less and less impact! But I estimate that in the next 5 years, the MCU will still have a price advantage and will still survive! But will ARM streamline its architecture, reduce costs, and grab the low-end market? I think it is unlikely, ARM should develop upward. Similarly, the MCU can only develop upward, such as 16-bit, high-function... etc. The reason is that the chip manufacturing process is advancing too fast. Pressure chip design to develop towards high integration.

25. When programming in C, how can the generated code be as efficient as assembly?
Answer: If programming is done in C, it is unlikely that the generated code will be 1:1 as efficient as assembly.

In order for C language commands to be recognized and executed by hardware, they must be compiled by a compiler. Compilers are divided into front-end, middle-end, and back-end. The front-end deals with programs written in various computer languages, and the back-end is connected to the basic instruction set of the processor. Therefore, if you want to achieve the highest efficiency when using C programming, it is best to understand 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, so that you can ensure that the same function and different C programs have the highest compilation efficiency when programming the microcontroller C. However, there are certain differences between different C compilers. The code length and execution time of an excellent embedded system C compiler are only 5-20% longer than the same function written in assembly language, so the compilation efficiency of C compilers from different manufacturers will also be different.

26. Which type of microcontroller is closer to an ARM microcontroller?
Answer: Strictly speaking, ARM is not a microcontroller, but an embedded real-time operating system. ARM (Advanced RISC Machines) is a well-known company in the microprocessor industry, designing a large number of high-performance, low-cost, low-energy RISC processors, related technologies and software. ARM licenses its technology to many well-known semiconductor, software and OEM manufacturers in the world, and each manufacturer gets a unique set of ARM-related technologies and services. Therefore, large companies such as Intel, IBM, LG Semiconductor, NEC, SONY, Philips and National Semiconductor have ARM series in the market. Now there is no question of which type of microcontroller is closer to an ARM microcontroller. Moreover, after purchasing the core, the manufacturer will add different plug-in function modules according to the different application directions of their own chips, so the functions provided by the same core chip are different.

27. Will it be difficult to switch from 51 to ARM?
Answer: In fact, the principles of programming are the same when switching from 51 to ARM, but it should be noted that ARM is a RISC architecture. There are many open source programs for ARM applications. If you want to improve yourself, you should read more programs from others. Linux, uc/os-II, etc. are all very good source codes.

28. I have studied the MCS51 microcontroller textbook and am very interested in it, but I lack practical experience, I don’t have any props to practice, and my funds are limited. What should I do?
Answer: If you are really interested in it and you don’t have any conditions to practice, you can download some simulation software with software simulation function to do some programming. Some of the better 51 simulation software should have this function. HOLTEK’s simulation software HT-IDE3000 also has the corresponding function. It also has LCD software simulation and peripheral circuit software simulation.

29. If you already have an algorithm implemented in C for a certain MCU, keep the framework unchanged, and use assembly to optimize the core part, are there some common principles?
Answer: Everyone has their own programming style and habits. If you want to use someone else's program and modify it, if his program is not well modularized, it is recommended not to do so, otherwise you may get twice the result with half the effort instead of twice the effort. It is of course possible to refer to other people's programs, but the first thing is to read and understand the essence of the algorithm of other people's programs, rather than patching it on its basis. As for algorithm optimization, you can buy some books on data structures, which have more detailed instructions.

30. If you want to estimate the MIPS of an algorithm, what is a good way?
Answer: The running time of an algorithm refers to the time it takes for an algorithm to run on a computer. It is roughly equal to the product of the time required for the computer to perform simple operations (such as assignment operations, comparison operations, etc.) and the number of simple operations in the algorithm. The number of simple operations contained in an algorithm is usually called the time complexity of the algorithm. It is a relative measure of the running time of an algorithm, generally given in the form of an order of magnitude. There are usually two ways to measure the execution time of a program:

One is the post-statistical method. Because many computers have internal timing functions, programs with different algorithms can be distinguished by one or several sets of the same statistical data. However, this method has two drawbacks: first, the program compiled according to the algorithm must be run first; second, the statistical value of the time obtained depends on environmental factors such as the computer's hardware and software, which sometimes easily conceals the advantages and disadvantages of the algorithm itself. Therefore, people often use another method of pre-analysis and estimation.

One is the method of pre-analysis estimation. The time a program takes to run on a computer depends on the following factors:

(1) The strategy used in the algorithm;
(2) The scale of the problem. For example, is it a prime number within 100 or within 1000?
(3) The language in which the program is written. For the same algorithm, the higher the level of the implementation language, the lower the execution efficiency;
(4) The quality of the machine code generated by the compiled program. This is related to the compiler;
(5) The speed at which the machine executes instructions.

Obviously, the same algorithm has different efficiencies when implemented in different languages, compiled with different compilers, or run on different computers. This shows that it is inappropriate to use absolute time units to measure the efficiency of an algorithm. Leaving aside these factors related to computer hardware and software, it can be considered that the size of the "running workload" of a specific algorithm depends only on the size of the problem (usually expressed as an integer n), or in other words, it is a function of the size of the problem.

An algorithm is composed of control structures (sequence, branch and loop) and primitive operations (operations of intrinsic data types), and the algorithm time depends on the combined effect of the two. In order to facilitate the comparison of different algorithms for the same problem, the usual practice is to select a primitive operation from the algorithm that is a basic operation for the problem (or algorithm type) being studied, and use the number of times the basic operation is repeated as the algorithm time measurement.

MIPS algorithms are a specialized subject, and you can refer to relevant data structure books.

31. What are the ideas and design process of remote control coding?
Answer: Generally speaking, a complete remote control code consists of four parts: header code, address code, data code and check code. The header code varies from manufacturer to manufacturer, and the address code and data code are both composed of logic "1" and logic "0". The purpose of coding is to send different code values ​​according to the coding rules. The most common code types we have are SONY, Panasonic, NEC and other manufacturer models. Remote control coding chips are most commonly used in remote controllers such as air conditioners, DVDs, and garage doors.

Designing a coding program can be divided into three parts.

The first part is the characteristics of the model. The header code and address code (also called client code) of the remote control code are fixed, and the data code and check code change according to different key values.

The second part is to calculate the code sending time. Most remote control codes are composed of logic "1" and logic "0", that is, a series of square waves with fixed duty cycle and fixed period. Usually the period of these square waves is milliseconds or even microseconds, and the time calculation needs to be more accurate. Therefore, when choosing the model of the code sending microcontroller, it is necessary to consider whether the running speed of the microcontroller is fast enough and whether the program running time is sufficient.

The third part is the writing of the program. After selecting the microcontroller model, start designing the program flow. Generally speaking, we can use the I/O port as the output port for sending codes. The code sending program is generally composed of several subroutines, the header code subroutine, the logic 1 subroutine, the logic 0 subroutine, and the check code algorithm subroutine. Once we get the command to send the code, we first call the header code subroutine, then call the logic 1 subroutine or the logic 0 subroutine according to the client code and key value, and finally call the check code algorithm subroutine to output the check code.

HOLTEK's HT48CA0/HT48RA0, HT48CA3/HT48RA3 and HT48CA6 are single-chip microcomputers designed for remote controllers. They have a dedicated infrared output port and can meet most code transmission requirements.

The design* process can also be divided into three parts.

The first part is to understand the characteristics of the encoding waveform. Start by analyzing the high and low pulse widths of the encoding, and understand the waveform duty cycle and period of logic "1" and logic "0". Understand the characteristics of the header code.

The second part determines the receiving method. Generally, we can use the I/O port query method or the INT port interrupt response method to receive the code. The difference between the two is that the I/O port query method consumes more of the microcontroller's running time resources, and it is necessary to continuously detect the level changes of I/O to avoid missing the valid code value; while the INT port interrupt reception method is more resource-saving. When there is an external level change, the microcontroller needs to process it and does not need to detect it all the time. However, the INT port interrupt reception method cannot distinguish the waveform characteristics of different duty cycles in the same period. When the logic "1" and logic "0" carried by the code have this characteristic, it cannot be distinguished by the INT port interrupt reception method, because the INT interrupt is only triggered at the rising edge or falling edge.

The third part stores the received code value and analyzes and executes it. By judging the width of the high and low levels (timer or delay), we can get the code value, which is what we call *. Generally, when we receive three identical complete code values ​​in succession, we confirm that the code has been sent and received successfully. When the * ends, we can judge which button is pressed based on the code value, and execute the corresponding button function.

HOLTEK's HT48 and HT49 (with LCD) series microcontrollers can meet most * tasks.

32. In the process of learning microcontrollers, how do you understand concepts such as pre-scaling, 12-clock mode (6-clock model)?
Answer: The English word for prescaler is prescaler. It divides the input frequency signal and then outputs it. HOLTEK has a most basic 8-bit I/O microcontroller HT48R05A-1. We will use this microcontroller as an example. The HT48R05A-1 has an 8-bit up-counting timer Counter. The system clock Fsys (4MHz) enters the 8-stage prescaler for frequency division, and then enters the timer counter Counter for counting. According to the software settings, the prescaler can divide Fsys by 2 to the power of n (n=1~8). For example, if the software is set to divide the prescaler by 2, then the frequency output by the prescaler is Fsys/2=2MHz, and this 2MHz signal then enters the timer counter Counter.

The 12-clock mode (6-clock model) should be in the MCS51 series, where 12 system clocks are one machine cycle, and 2 system clocks are one state, that is, one machine cycle has 6 states.

33. What are the advantages of A/D and D/A sampling rates compared to other MCUs?
Answer: HOLTEK A/D Tyep MCU has a built-in bit-by-bit approximation A/D conversion circuit with 8bit/9bit/10bit accuracy and the fastest A/D conversion time is 76us.

As for D/A, it generally refers to PWM output. HOLTEK A/D Type MCUs all have 8-bit PWM output, but the characteristic of HOLTEK PWM is that its output frequency is determined by the system frequency (that is, once the system frequency is selected, the PWM frequency is also determined), and its duty cycle is controlled by assigning values ​​to the [PWM] register, without occupying timer/counter resources.

34. When using AT89S51, the data in RAM is modified when the reset button is pressed. What is going on? Note: The data is placed outside the special register.
Answer: If it is the reset button of the RESET pin: Generally, when the MCU is reset by RESET, its special registers will be reinitialized, while the values ​​of the general registers remain unchanged.

If the reset button is a power reset: it is a power-on reset of the MCU, its special registers will be initialized, and the values ​​of the general registers are random numbers.

35. P2.7 is used to drive an NPN transistor, with a 1K resistor in series. The problem is: when I try to write '1' to P2.7, I find that the pin can only output a level of about 0.5V. Is this circuit used properly? How to use the IO function correctly?
Answer: Is this a problem encountered during simulation or after burning the chip?

You can disconnect the external circuit of P2.7 and measure whether the output voltage is normal. If the output voltage is normal after disconnection, it means that the driving ability of P2.7 is insufficient and cannot drive the NPN transistor. PNP transistor should be used instead (generally in MCU applications, PNP driving is adopted). If the output voltage is still abnormal after disconnection, it is possible that the emulator (or chip) is damaged.

36. When doing charge management, increasing the frequency of PWM often comes at the expense of accuracy. If the frequencies of AT90S4433 (avr) and 78P458 (elan) are 16kHz (8bit) and 32kHz (8bit) respectively, and you want to achieve 100kHz (above 8bit), such as atiny15. What should you do?
Answer: The PWM you mentioned controls its frequency and duty cycle through a timer/counter, so if you want to increase the frequency, the accuracy will inevitably be reduced. If you want to increase the frequency of PWM, you can only solve it by increasing the system oscillation frequency.

37. Are MCUs used in automotive electronics mostly 8-bit or 32-bit? How do you view the prospects of MCUs in the automotive electronics market?
Answer: Today, automobile manufacturing is also a rapidly advancing industry, especially the application of electronics in automobiles, which enables a variety of new functions to be realized.

Generally speaking, automotive electronics applications are divided into three parts.

Automobile engine control: speed limit control, turbocharging, fuel injection control, etc.
Automobile comfort devices: remote anti-theft system, automatic air conditioning system, audio and video playback system, satellite navigation system, etc.
Automobile control and braking: anti-lock braking system (ABS), traction control system (TCS), anti-skid system (ASR), electronic stability program (ESP), etc.

There are many systems in the car, and they are changing with each passing day. Therefore, the type of microcontroller used depends on the specifications of each system, and the requirements are different. However, one thing is certain: the microcontroller must meet industrial specifications to withstand the harsh environment, high temperature, power supply interference, and reliability requirements of automotive applications. The functional configurations of different grades of cars are relatively different. Therefore, there should be room for 8-bit microcontrollers in lower-level systems such as mechanical control and remote anti-theft, but high-level systems such as audio and video, navigation, and future unmanned driving are not something that ordinary microcontrollers can achieve.

As the automobile industry is currently controlled by several large groups in Europe, the United States and Japan, the relevant automobile electronic parts groups will choose to cooperate with large microcontroller manufacturers. Therefore, the built-in electronic systems of automobiles are also controlled by large microcontroller manufacturers. Only external systems such as remote control anti-theft and audio and video navigation are left in the market for small manufacturers to develop.

38. When using Samsung's s3c72n4, I feel that its time/counter is not enough. Now I need to use 3 counters at the same time, what should I do?
Answer: Do you need three external counters or three timers? If it is three timer flags, you can take the most basic time base of these three timings as the basic count of the timer, and then use this time base to calculate the flags of the three required counting flags. In the program, you only need to check whether the flag has arrived and then take action.

If you want to count 3 external pulses, this is somewhat difficult. If the external pulses are not very frequent, you can consider using external interrupts. However, this method must ensure that the frequency of the external pulses is an order of magnitude different from the MCU execution speed. Otherwise, the MCU may not be able to handle other programs and will always be processing external interrupts.

39. With the increasing progress of chip integration technology, the integration technology of single-chip microcomputers is also developing rapidly. Based on the traditional 40-pin, Philips has launched a 20-pin single-chip microcomputer series, which allows many pins to be reused. Will the use of this reuse technology affect the execution of its functions in actual applications?
Answer: Now many brands of single-chip microcomputers have pin reuse functions, not just Philips. It should be said that this method has been available for several years. In actual applications, it will not affect the execution of its functions, but it should be noted that if some MCUs use multiplexing pins, the pins will have some application restrictions, which will be described in the corresponding datasheet, so it should be paid attention to when planning the system.

40. What is the concept of Delta-Sigma software measurement?
Answer: The Delta-Sigma principle is generally used in ADC applications. Specifically, the working principle of Delta-Sigma ADC is that a modulator is composed of a differential, an integrator, and a comparator, which together form a feedback loop. The modulator runs at a rate much higher than the bandwidth of the analog input signal to provide oversampling. The analog input is differentially (delta) compared with the feedback signal (error signal). The differential output generated by this comparison is fed into the integrator (sigma). The output of the integrator is then fed into the comparator. The output of the comparator simultaneously transmits the feedback signal (error signal) to the differentiator, and itself is fed into the digital filter. The purpose of this feedback loop is to make the feedback signal (error signal) tend to zero. The result of the comparator output is a 1/0 stream. If the density of 1 is high, it means that the analog input voltage is high; conversely, if the density of 0 is high, it means that the analog input voltage is low. The 1/0 stream is then fed into a digital filter, which converts the 1/0 stream from a high-rate, low-precision bit stream to a low-rate, high-precision digital output through oversampling and decimation.


In short, Delta means differential and Sigma means integration. My understanding of Delta-Sigma software testing is to simulate the process of differential integration through software. Specifically, it detects the change of the voltage (or current) signal of the external input, and then obtains the basic situation of the external signal changing over time through software integration operation.

41. What methods are usually used to test the reliability of the MCU system?
Answer: The MCU system can be divided into two aspects: software and hardware. If we want to ensure the reliability of the MCU system, we must start from these two aspects.

First of all, when designing a microcontroller system, you should fully consider all possible external interferences and try to use all the means provided by the microcontroller to cut off or solve the impact of adverse external interference. Let's take HOLTEK's most basic I/O microcontroller HT48R05A-1 as an example. It provides a watchdog timer WDT to prevent the microcontroller's internal program from running wildly and making mistakes; it provides a low voltage reset system LVR. When the voltage is lower than a certain allowable value, the microcontroller will automatically RESET to prevent the chip from being locked; HOLTEK also provides the best peripheral circuit connection solution to minimize the impact of external interference on the chip.

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:

Test the completeness of the MCU software functions. This is a test for all MCU system functions to test whether the software is written correctly and completely.
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 MCU system.

Aging test. Test the reliability of the microcontroller system under long-term working conditions. If necessary, it can be tested in an environment of high temperature, high voltage and strong electromagnetic interference.

ESD and EFT tests. Various interference simulators can be used to test the reliability of the MCU system. For example, an electrostatic simulator is used to test the anti-static ESD capability of the MCU system; a surge noise simulator is used to perform fast pulse anti-interference EFT tests, etc.

Of course, if there are no such conditions, you can simulate the damage that may occur during human use. For example, deliberately rub the contact port of the MCU system with the human body or clothing fabric to test the anti-static ability. Use a high-power electric drill to work close to the MCU system to test the anti-electromagnetic interference ability, etc.

42. When developing a microcontroller system, what are the specific standards for measuring the stability of the system?
Answer: From an industrial perspective, there are many standards for measuring system stability, and the standards are different for different products. Below we will briefly introduce the most commonly used standards for microcontroller systems.

Electrostatic discharge test (ESD)
reference standard: IEC 61000-4-2
The purpose of this test is to test the degree to which the test piece can withstand the electrostatic discharge effect directly from the operator and the relative object.

Space Radiation Susceptibility Test (RS)
Reference Standard: IEC 61000-4-3
This test is to verify the test piece's tolerance to noise scattered by the RF generator through space.
Test frequency: 80 MHz~1000 MHz

Fast pulse immunity test (EFT/B)
Reference standard: IEC 61000-4-4
The purpose of this test is to verify the tolerance of the power line and signal line (control line) of the test piece when subjected to repeated fast transient bursts.

Lightning test (Surge)
reference standard: IEC 61000-4-5
This test is to determine the tolerance of the specimen to the surge caused by switching or lightning when it is in operation.

Conducted Immunity (CS)
Reference Standard: IEC 61000-4-6
This test verifies the test piece's tolerance to noise conducted by the RF generator through the power line.
Test frequency range: 150 kHz~80 MHz

Impulse
pulse is injected into the power line or control line through coupling to perform interference immunity test.

43. When designing software, most microcontrollers have a watchdog. You need to feed the watchdog at the appropriate location in the software to prevent the software from resetting and entering an infinite loop. How to feed the watchdog appropriately, that is, how to accurately determine the running time of the software?
Answer: Most microcontrollers have a watchdog timer function (WDT) to prevent program errors. HOLTEK has a basic I/O type microcontroller - HT48R05A-1. Let's take it as an example to explain.

First, let's understand the basic structure of WDT. It is actually a timer. The so-called feeding the dog means clearing this timer. There are two ways to feed the dog: software and hardware. Software feeding the dog means using instructions to clear the WDT, namely CLR WDT; hardware feeding the dog means hardware reset RESET. When the timer overflows, it will cause the WDT to reset, which is what we often call the watchdog. When the program is executed normally, we do not want the WDT to reset, so we need to use software instructions to feed the dog before the watchdog overflows, that is, to calculate how long it takes for the WDT to overflow. The calculation formula for the WDT overflow time of the HT48R05A-1 is: 256*Div*Tclock. Among them, Div refers to the wdt pre-division number 1~128, and Tclock refers to the clock source period. If the internal RC oscillator is used as the clock source of the WDT (the RC clock period is 65us/5V), the maximum WDT overflow time is 2.1 seconds.

After we get the WDT overflow time Twdt, we usually choose to feed the dog at around Twdt/2 to ensure that the watchdog does not overflow and the number of times the dog is fed is not too many.

The software running time is determined by different running routes. If the software running route can be predicted, the software running time can be calculated according to T=n*T1. n refers to the number of machine cycles running, and T1 refers to the machine cycle. HOLTEK microcontrollers are RISC structures, and most instructions consist of one machine cycle. You only need to know how many instructions the software runs to calculate the running time. There is a tool for calculating the running time in HOLTEK's compilation software HT-IDE3000. However, for CISC-structured microcontrollers, an instruction can consist of several machine cycles, so it is necessary to calculate based on the specific instructions executed.

44. We are a professional factory that develops CNC systems. We have developed many products using various single-chip microcomputers and CPUs. We have also adopted many common anti-interference technologies in software development, such as software traps, instruction margin, watchdogs and digital filters, etc. However, they are still very unreliable in actual use, such as frequent inexplicable crashes, program jumps, I/O data errors, etc., and the repeatability of the faults is very uncertain, and they are not repeated periodically. Often, users encounter faults during use, but they cannot be reproduced, which is a headache. Repeated inspections of the hardware have not found the cause, so the reliability of the software is very doubtful. What should I do?
Answer: 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 single-chip microcomputer's anti-interference ability is strong enough. The most common phenomenon of single-chip microcomputer interference is reset; as for the program running away, in fact, software traps and watchdogs can also be used to pull the program back to the reset state; so the most important thing for single-chip microcomputer 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, you can determine the different reset reasons by judging these flags. 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.

You can set some registers to accumulate in the timer interrupt, and then add to the preset value (a relatively long time), SET flags, and these actions are all in the interrupt program. The main program only needs to query the flags, but remember to clear the flags after use, and also remember to clear the time base accumulator in the interrupt after use.

Reference address:Microcontroller Programming FAQs

Previous article:AVR single chip passive infrared alarm experiment
Next article:Design of LED Color Light Controller Using AVR Microcontroller

Latest Industrial Control 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号