MCU Programming Solution

Publisher:温柔阳光Latest update time:2013-01-18 Source: 21IC Keywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

  What are the advantages and disadvantages of language and assembly language when developing microcontrollers?

  Answer: Assembly language is a symbolic language that uses 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.

  The 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 that of assembly.

  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.

  Or assembly language can be used for microcontrollers, can C++?

  Answer: In microcontroller development, assembly and C are mainly used, and C++ is not used.

  Is it necessary to know C to develop microcontrollers?

  Answer: Assembly language is a symbolic language that uses 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.

  When developing a complex project with a short development time, is it better to use C or assembly?

  A: For complex projects with tight development time, you can use C language, but the prerequisite 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, different MCU manufacturers have different C language compiler systems, 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.

  I need to use 8088 and 196 chip microcontroller teaching materials in teaching. Where can I find books or materials on this subject?

  Answer: Regarding the textbooks on this subject, a commonly used one in universities is "IBM-PC Assembly Language Programming" published by Tsinghua University Press, which can be found on the Internet and in bookstores. In addition, many other textbooks can be searched on the Internet, such as: "Microcomputer Principles and Assembly Language Tutorial" (edited by Yang Yanshuang, Zhang Xiaodong, etc.) and "16/32-bit Microcomputer Principles, Assembly Language and Interface Technology" (author: Zhong Xiaojie and Chen Tao, published by Machinery Industry Press), etc. You can find them in larger science and technology bookstores or order them directly from the Internet.

  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, which can deepen the beginners' understanding of each functional module of MCU and lay a solid foundation.

  I am a third-year student majoring in 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 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 causes 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 must 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 senior year graduation design stage, you can also choose related topics to do some actual cases to increase your experience. There is a process of accumulating experience in everything you do, step by step.

  As a student, how can I learn microcontrollers well?

  Answer: The most important thing to learn MCU is practice, and to gain experience in practice. For students in school, there are indeed fewer opportunities for practice, but if there is an opportunity, 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.

  The MCU is an 8-bit MCU with RISC structure, 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 and so on.

  How can one become a master of microcontrollers?

  Answer: To become a microcontroller expert, you should practice more, always pay attention to the development trends of microcontrollers, and often visit related websites, where you can find a lot of useful information.

  Are women suitable for the microcontroller software programming industry?

  Answer: It depends on your interests and your patience for software programming. Both men and women are suitable for this industry.

  How long can the machine 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.

  Is learning ARM and embedded systems more promising than learning other general microcontrollers? What relevant knowledge should a beginner have?

  Answer: Generally, there is a difference in the level of embedded systems between 8-bit MCU and ARM. ARM is suitable for advanced products with greater system complexity, such as PDA, mobile phones 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. For a beginner in software programming of MCU, HOLTEK series or 8051 and other 8-bit MCUs should be used for introductory exercises. Beginners should have relevant knowledge of software programming. The general software programming of MCU is based on assembly language. Each company has its own syntax, but most of them are based on RISC MCU architecture, in which RISC (Reduced Instruction Set Computer) represents all instructions of MCU. They are all composed of some simple instructions. Simple instructions represent that the circuit of MCU can be optimized as much as possible to improve the execution rate. In addition, beginners should have application knowledge of MCU I/O interface, which depends on the use of peripheral application circuits and various components, and must be combined with the electronics and circuits they have learned.

  What are the 80 series 8-bit MCUs that conform to 44PIN?

  Answer: The 80 series 8-bit microcontrollers that conform to 44PIN are Z8674312FSC, Z86E2112FSC, and Z86E2116FSC.

  Please introduce the testing method of MCU.

  Answer: There are different testing methods for each different stage of MCU from production to packaging and shipment, among which 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 diode connected to each I/O pin is functioning properly.

  Functional test: Fill the IC with the test data (TEST PATTERN) provided by the product designer to check whether the result is the same as the status during simulation.

  Current test: Measure whether the leakage current of each contact (PAD) when the IC is in HALT mode, that is, when it 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: Measures the input voltage response characteristics of each input pin.

  Output voltage test: Measure the output voltage level of each output pin.

  The relevant frequency characteristic (AC) test is also carried out by externally inputting a certain frequency and checking whether the output from the I/O port matches it.

  In order to ensure the long-term and stable quality of IC production, product reliability tests will also be performed. These tests include ESD testing, LATCH UP testing, temperature cycle testing, high temperature storage testing, humidity storage testing, 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.

  Can a single chip be used to detect the charge and discharge time of a mobile phone battery and the changes in voltage and current during charge and discharge, and use an I/O port to display the test results on a computer?

  A: Most of the various smart chargers on the market use MCU to control 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 the microcontroller and the computer, the simplest way is to use serial communication, but you need to add an RS-232 chip.

 

  What about in 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. [page]

  During RF control, the MCU's clock (crystal oscillator) and data lines will radiate the base frequency or multiples of the base frequency, which will be amplified by the low-noise amplifier (LNA) and enter the mixing frequency, resulting in in-band Spurs that cannot be filtered out. In addition to using layout and choosing low-radiation MCUs to reduce this, are there any other methods?

  A: There are many things to pay attention to when designing PCBs for high-frequency circuits, especially for GHz-level high-frequency circuits. It is even more important 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 of high-frequency circuits and digital circuits sharing the same PCB to form the so-called mixed circuit system. Such designs often cause the high-frequency circuit to become unstable when the digital circuit is in operation. 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 PCB. Basically, the following three principles must be mastered when designing PCBs for high-frequency circuits:

  High texture.

  Don't take shortcuts.

  Don't rush the time.

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

  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.

  The ground layer is set on the copper foil surface as a whole, 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 printing patterns to depict ground.

  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.

  The signal line is designed to be short. Do not increase the wiring length arbitrarily and try to shorten the wiring length.

  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 the audio circuit.

  Loop 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 at the shortest position and the lines of equal width and distance should be drawn as much as possible, and ceramic capacitors such as 104/103/102 should be added at the node position.

  What are the precautions when developing a system for the 80c196KB series 96 microcontroller?

  A: 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 an MCU 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 unit of each task. Therefore, it is important to pay attention to the following points:

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

  The system's task control block only stores the stack pointers of each task, and 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.

  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.

  When sampling voltage on the demo board, it is unstable and the sampling results fluctuate. How to eliminate it?

  A: Generally speaking, simulators work in a voltage-regulated environment (usually 5V). If you use the simulator's A/D, you should pay attention to whether the A/D reference voltage is provided by the simulator itself or needs to be provided externally. A/D conversion requires a continuous clock cycle, so you cannot use the single-step debugging method during simulation, otherwise the A/D sampling value will be inaccurate. As for the instability of 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.

  How to design an electronic anti-vibration system in a car DVD system?

  Answer: For the car DVD system, it is best to choose a high-end DVD player, because high-end DVD players all use electronic anti-vibration system (ADVANCEDESP). When the reading in the memory buffer is reduced, the advanced electronic anti-vibration design will use a dual-speed reading system to make the reading rate twice as fast as the normal speed to reduce noise. Even if there is continuous vibration, it can still avoid the jump line. Now let's talk about what electronic anti-vibration is. Simply put: electronic anti-vibration 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 we turn on the anti-vibration is the sound passing through RAM. This is its process. When there is no anti-vibration, it is because the signal is read 1:1, so when it is impacted, there will be skipping. When the anti-vibration 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 still does not meet the requirements of users, because the time brought by this method is very short, usually only 3 seconds, so the chance of sound skipping is still quite high. Increasing the RAM will also increase the cost because RAM is expensive, especially good quality ones.

  In electronic anti-vibration technology, what ICs or devices are available?

  A: In 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 a limit. The larger the RAM capacity, the higher the cost. Many manufacturers have developed research on how to maximize the memory time within the RAM limit.

  How can programming reduce program bugs?

  A: Here are some suggestions, because the actual operating parameters in the system are within a range. The out-of-range management parameters to be considered in system operation are:

  Physical parameters. These parameters are mainly the input parameters of the system, including excitation parameters, operating parameters in the acquisition process, and result parameters at the end of the process. These boundaries should be set reasonably, and any parameters beyond the boundaries should be treated as abnormal excitation or abnormal response and handled 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.

  Some people believe that MCU will be replaced by embedded systems with ARM and other series structures. How long will the life of MCU last?

  Answer: Because of the difference in functional structure and unit price between 8-bit microcontrollers and embedded system ARM, there is a big difference in the application level. ARM is suitable for advanced products with relatively complex systems, such as PDAs, mobile phones, etc. 8-bit microcontrollers are suitable for general industrial control, consumer home appliances, etc. due to their simple architecture and relatively few hardware resources. To evaluate whether microcontrollers will be replaced by ARM in the near future, we need to observe two factors:

  The chip cost is higher because the ARM operating frequency is higher and the circuit is larger, the required chip manufacturing process requires more than 0.25U, and the cost is higher. The 8-bit microcontroller has a relatively low operating frequency and a smaller circuit, and the required chip manufacturing process is only 0.5U, which is lower in cost.

  The function positioning is stronger than that of the single-chip microcomputer, but the positioning of the two is different. Just like at this stage, no one will use ARM to make a simple industrial timer switch. 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.

  When programming in C for a microcontroller, how can we make the generated code as efficient as assembly?

  Answer: If you are programming in C language, it is unlikely that the generated code will have the same efficiency as assembly language 1:1.

  In order for 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 programming in C, 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.

  Which type of core microcontroller is closer to this microcontroller?

  Answer: Strictly speaking, ARM is not a single-chip microcomputer, but an embedded real-time operating system. ARM (Advanced RISC Machines) is a well-known company in the microprocessor industry. It has designed 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 ARM single-chip microcomputer is closer to which core single-chip microcomputer. 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 chips with the same core are different.

 

  Will it be difficult to switch from 51 to ARM?

  Answer: When switching from 51 to ARM, the principles of programming are actually the same, but you should note 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.

  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 with, and my funds are limited. What should I do?

  A: If you are really interested in practicing without any conditions, you can download some simulation software with software simulation function to do some programming. Some well-made 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.

  If you already have an algorithm implemented in C for a certain MCU, are there some general principles for keeping the framework unchanged and optimizing the core part using assembly?

  A: Everyone has his 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 end up with 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 on their basis. As for algorithm optimization, you can buy some books on data structures, which have more detailed instructions.

  If you want to estimate the MIPS of an algorithm, what is a good approach?

  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 a computer to perform simple operations (such as assignment operations, comparison operations, etc.) and the number of simple operations performed 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:

  The strategy to be chosen based on the algorithm; the scale of the problem. For example, to find prime numbers within 100 or within 1000; 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; the quality of the machine code generated by the compiled program. This is related to the compiler; 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.

  What are the programming ideas and design process of remote control?

  A: 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. 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 coding rules. Our most common code types 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.

  The company's HT48CA0/HT48RA0, HT48CA3/HT48RA3 and HT48CA6 are microcontrollers designed specifically for remote controls. 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.

  The company's HT48 and HT49 (with LCD) series of MCUs can meet most * tasks.

  In the process of learning microcontrollers, how do you understand concepts such as pre-scaling, 12-clock mode (6-clock model)?

  A: 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 take 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. [page]

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

  ,What are the advantages of D/A sampling rate compared with other microcontrollers?

  Answer: HOLTEK A/D Tyep MCU has a built-in bit-by-bit approximation A/D conversion circuit with an accuracy of 8bit/9bit/10bit and a fastest A/D conversion time of 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.

  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.

  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?

  A: 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.

  When doing charge management, increasing the PWM frequency often comes at the expense of accuracy. If the frequencies of AT90S4433 (avr) and 78P458 (elan) used are 16kHz (8bit) and 32kHz (8bit) respectively, and you want to achieve 100kHz (above 8bit), such as atiny15. What should you do?

  A: The PWM you are talking about controls its frequency and duty cycle through a timer/counter, so if you want to increase the frequency, the accuracy will inevitably decrease. If you want to increase the PWM frequency, you can only do so by increasing the system oscillation frequency.

  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.

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

  Automobile engine control: speed limit control, turbocharging, fuel injection control, etc.

  Car comfort devices: remote control anti-theft system, automatic air conditioning system, audio and video playback system, satellite navigation system, etc.

  Vehicle 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.

  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?

  A: 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.

  As chip integration technology continues to advance, the integration technology of microcontrollers is also developing rapidly. Based on the traditional 40-pin microcontroller series, Philips has launched a 20-pin microcontroller series, which allows many pins to be reused. Will the use of this multiplexing technology affect the execution of its functions in actual applications?

  A: Many brands of microcontrollers now have pin multiplexing 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 you must pay attention to it when planning the system.

 

  What is the concept of software measurement?

  A: The Delta-Sigma principle is generally used in ADC applications. Specifically, the working principle of Delta-Sigma ADC is that the 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 the digital filter, which converts the 1/0 stream from a high-speed, low-precision bit stream into a low-speed, high-precision digital output through oversampling and sampling.

  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.

  What methods are usually used to test the reliability of microcontroller systems?

  Answer: The microcontroller system can be divided into two aspects: software and hardware. If we want to ensure the reliability of the microcontroller 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 of 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 microcontroller system.

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

  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 test, 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.

  When developing a microcontroller system, what are the specific standards for measuring the stability of the system?

  A: From an industrial perspective, there are many standards for measuring system stability, and they vary for different products. Below we briefly introduce the most commonly used standards for microcontroller systems.

  Electrical test reference standards:

  The purpose of this test is to test the extent to which the specimen can withstand the electrostatic discharge effects directly from the operator and the relative object.

  Reference standards for space radiation tolerance test:

  This test is to verify the tolerance of the test piece to the noise scattered by the RF generator through space.

  Test frequency:

  Fast pulse immunity test reference standard:

  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 reference standard:

  This test is to determine the tolerance of the specimen to the surges caused by switching or lightning strikes when the specimen is in operation.

  Conducted immunity tolerance reference standard:

  This test is to verify the tolerance of the test piece to the noise transmitted by the RF generator through the power line.

  Test frequency range:

  A test of the immunity to interference by injecting pulses into the power line or control line through coupling.

  When designing software, most microcontrollers are equipped with a watchdog. It is necessary to feed the watchdog at an 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 (WDT) function 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.

  We are a professional manufacturer of 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, watchdog and digital filtering, 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 hardware checks have not found the cause, so the reliability of the software is very doubtful. What should I do?

  A: 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, you can actually use software traps and watchdogs 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, 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.

@end 文章内容 心情
Keywords:MCU Reference address:MCU Programming Solution

Previous article:Detailed explanation of the concepts and important parts of learning and application of single chip microcomputers
Next article:What are the differences between C language and assembly language in developing microcontrollers?

Recommended ReadingLatest update time:2024-11-17 00:20

NXP Launches New MCX N Microcontrollers to Lead the Way into a New Era of Intelligent and Efficient Edge Processing
NXP’s new MCX N microcontrollers are the first to integrate NXP’s dedicated neural processing unit (NPU) to enable high-performance, low-power secure intelligence at the edge Shanghai, China - November 9, 2022 - NXP Semiconductors NV (NXP Semiconductors NV) announced the launch of the firs
[Embedded]
NXP Launches New MCX N Microcontrollers to Lead the Way into a New Era of Intelligent and Efficient Edge Processing
MCU serial communication source code
This test program uses the STC12C4052AD microcontroller, uses the internal crystal oscillator 6M to start the oscillation, and the transmission baud rate is 2400bps. The test was passed on November 17, 2012. Use STC-ISP, V488 version to flash the machine, and use its own serial port assistant program to test. The sourc
[Microcontroller]
Power-off protection of microcontroller memory information
  In a computer system, whether using dynamic RAM or static RAM, its biggest disadvantage is that the information stored in it will disappear after the power is turned off. Even a momentary power outage will cause all the information stored to be lost. If the computer is in the process of running, its original data and
[Microcontroller]
Power-off protection of microcontroller memory information
Playing with MCU, you and I are both rookies (Continued 2)
The reason I use such a title is just to bring you and me closer. Don't think you are no longer a rookie. Then take a look at the following questions. If you start from a blank sheet of paper without referring to other people's programs. And you can complete these questions fluently and quickly, solder the circuit by y
[Microcontroller]
MCU controlled 28BYJ-48 stepper motor driver source code
The single chip microcomputer source program for controlling the 28BYJ-48 stepper motor driver is as follows: #include reg52.h #include intrins.h unsigned char CCW ={0x80,0xC0,0x40,0x60,0x20,0x30,0x10,0x90}; //Counter-clockwise rotation phase sequence table unsigned char CW ={0x90,0x10,0x30,0x20,0x60,0x40,0xC0,0
[Microcontroller]
Application of MPC555 microcontroller in automotive electronics
With the rapid development of the automobile industry, the requirements for automobile control, communication and networking are becoming more and more complex. The new generation of electronic control units (ECUs) with 32-bit microcontrollers and embedded real-time operating systems as basic technical features have b
[Automotive Electronics]
Pulse measuring instrument based on 51 single chip microcomputer
This article introduces a pulse measuring instrument made of a single-chip microcomputer. Just put your finger in the sensor and you can quickly and accurately measure the pulse rate per minute. The measurement result is displayed in three digits. 1. Circuit Working Principle The circuit principle is shown
[Microcontroller]
Pulse measuring instrument based on 51 single chip microcomputer
Design of three-phase combined inverter based on SA4828 and single chip microcomputer
1 Introduction Power supply equipment is a kind of electronic product with large quantity, wide application and strong versatility. Power supply is used in almost all departments such as modern communication, electronic instruments, computers, industrial automation, power engineering, national defense, etc. It is al
[Microcontroller]
Design of three-phase combined inverter based on SA4828 and single chip microcomputer
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号