Generally speaking, microcontrollers with internal A/D converters are relatively expensive, and generally only have 8 to 10-bit resolution, which is obviously not suitable for occasions requiring high resolution; and ordinary microcontrollers do not have A/D converters at all. With the development of modern electronic technology, some small-sized microcontrollers with built-in analog comparators have emerged, such as ATMAL's AT89C2051, ZILOG's Z86E04, MICROCHIP's PIC16C620, etc. When these microcontrollers are used, the ports connected to the comparators are generally used only as ordinary I/O, and the built-in analog comparators are rarely used. Taking AT89C2051 as an example, the following discusses a new method of using the built-in analog comparator of a microcontroller to form an A/D converter.
1 Hardware conversion circuit
AT89C2051 is one of the MCS51 microcontrollers. Although it has only 20 pins, it integrates the standard core of the 51 series microcontrollers, including 2k program memory, 128 bytes of data memory, 2 16-bit timer counters, a standard full-duplex UART and an accurate analog comparator, which is not available in previous products. Figure 1 is a circuit diagram of a dual-integral A/D converter using the analog comparator of AT89C2051. Among them: the structure of the built-in analog comparator is shown in the dotted line enclosed part in the figure. The positive and negative input terminals of the comparator are connected to P1.0 and P1.1 respectively. These are the output and input ports of two open-drain and pull-up resistors. When "1" is written to P1.0 and P1.1, M1 and M2 are cut off, which is equivalent to the digital part of P1.0 and P1.1 being suspended. At this time, the input of the comparator is not affected by the output of the microcontroller port; because P1.0 and P1.1 have strong current sinking capability, when "0" is written, P1.0 and P1.1 can absorb 20mA of current sinking, and the saturation voltage of M1 and M2 is very low. This feature can be used to completely discharge the integral capacitor. The comparator output terminal is connected to P3.6 inside the microcontroller, and the output result of the comparator can be obtained by reading P3.6. Therefore, the built-in comparator of AT89C2051 and a small number of peripheral devices can be used to form a dual-integral A/D converter. In Figure 1, I0 is a constant current source with a current of approximately 0.5 to 2 mA. Cf is an integrating capacitor. The selection of Cf and I0 depends on the number of bits of the A/D conversion. Vref is a reference voltage, which is generally half of the maximum value of the analog input voltage. U2 is an analog switch, in which channel 0 is connected to the reference voltage and channels 1 to 7 are connected to the analog input. That is, the A/D converter has 7 input channels.
2 Conversion process
When the constant current source integrates the capacitor, the voltage on the integral capacitor is linearly proportional to the time. In this way, the internal timing counter of the microcontroller can be used to measure the integration time of the reference voltage and the analog input voltage, and then the conversion result can be obtained through the CPU calculation. The ports P1.2 to P1.4 of the microcontroller can be used to output the analog switch channel selection address, and the timing counter T0 can be set to mode 1, 16-bit timing state, to determine the integration time. The conversion process can be divided into 5 steps:
The first step is to discharge the integrating capacitor, mainly by writing "0" to P1.1, using its large current sink to discharge Cf, and at the same time clearing the timing counter T0.
The second step is the reference voltage integration, that is, the analog switch selects channel 0, which is equivalent to connecting Vref to the positive input of the comparator, and writing "1" to P1.1, and starting the timing counter at the same time, so that I0 starts to integrate Cf; the program reads the P3.6 state in a loop to detect the output result of the comparator. When the integral voltage on the integral capacitor is slightly greater than (because the comparator has an extremely high gain, it can be approximately regarded as equal to) the reference voltage, the output of the comparator is reversed, and P3.6 jumps from high to low. After the program detects this jump, it stops the timing counter and saves the timing counter result Tref at this time. At this time, the relationship between the constant current source and the capacitor integration can be obtained: Vref = (I0 Tref) / Cf
The third step is to discharge the integrating capacitor, that is, repeat the first step to discharge Cf and clear the timing counter T0.
The fourth step is input voltage integration. At this time, the analog switch can select one of channels 1 to 7, which is equivalent to connecting the analog input voltage Vx to the positive input of the comparator. Repeat the second step to integrate the input voltage, and the integration time Tx can be obtained. Therefore, Vx = (I0Tx) / Cf
The integrated voltage waveform on the integrating capacitor Cf in the above four steps is shown in FIG2 .
The fifth step is to obtain the result of A/D conversion through CPU calculation. By dividing the result of the second step by the result of the fourth step, we can get:
Vref/Vx=Tref/Tx
After transformation:
Vx=(VrefTx)/Tref
The above formula is the result of A/D conversion.
From the above formula, we can see that the A/D conversion result Vx is only related to Vref, Tx, Tref, but not to I0 and Cf. This is very important. Because it means that the error caused by the temperature drift of the constant current source and the integral capacitor is suppressed during the conversion process, thereby ensuring the stability of the A/D converter, which is also the advantage of the integral A/D converter. In theory, the accuracy of the A/D converter depends only on the stability of the reference voltage and the accuracy of the microcontroller timing counter, and both of these points are relatively easy to guarantee. Of course, this refers to the case where the constant current source is an ideal constant current source. In fact, the characteristics of the constant current source determine the nonlinear error of the A/D converter. Therefore, in situations with higher requirements, a constant current source integrated circuit with good linearity, such as LM334, should be selected. In the case of low requirements, the constant current source circuit composed of discrete components shown in Figure 3 can be used to realize A/D conversion. At this time, the integral capacitor can choose a polyester capacitor with a small temperature coefficient. [page]
It should be noted that since the microcontroller uses the port query method to detect the output result of the comparator, the MCS51 series microcontroller port query command takes 2 machine cycles, and the timer counter needs to add 1 in each machine cycle. Therefore, when using it, it is possible that when the output of the comparator is reversed, the program cannot stop the timer counter immediately, but waits until the next machine cycle runs to the CLRTR0 statement before stopping. In this way, the value of the timer counter is always an even number. If this problem is not processed in the program, it will cause errors. The solution is to increase the integration time of I0 and Cf, that is, double the integration time, and then divide the reading of the timer counter, that is, Tref and Tx, by 2, so that the error of the timer counter adding 1 can be removed and the correct result can be obtained. In other words, if you want to get a 12-bit resolution, you need a 13-bit timer counter reading. Although this algorithm sacrifices the 1-bit resolution of the timer counter and lengthens the conversion cycle, it ensures the accuracy of the measurement result. For microcontrollers with analog comparator output jump interrupts, such as Z86E08, the above process is simpler to handle. The program can be used to set the interrupt when the comparator output reverses, and the timing counter can be stopped at the beginning of the interrupt subroutine. The reading minus the number of machine cycles from the comparator interrupt to the execution of the interrupt subroutine is the actual integration time.
Since the timing counter of AT89C2051 is 16 bits, the resolution of the A/D converter can actually reach 15 bits. The resolution of the A/D converter can be changed by adjusting the values of I0 and Cf. The relationship between the values of I0 and Cf and the resolution and the clock frequency of the microcontroller should satisfy the following formula:
Where Vmax is the maximum analog input voltage, N is the number of bits of resolution, and f0 is the clock frequency of the microcontroller. According to the above formula, a sufficiently long integration time should be ensured during design to ensure the resolution requirement. At the same time, it should also be ensured that the integration time does not exceed the maximum timing value of the microcontroller to avoid causing the timing counter to overflow.
3 Software Programming
The main procedures of the whole working process are as follows (the program is written in MCS51 assembly language). The division subroutine and the 20μs delay subroutine are:
(1) Initialize the main program:
4 Conclusion
As mentioned above, by using a single-chip microcomputer with an internal analog comparator and a small amount of foreign components, and slightly processing the program, a new A/D converter can be constructed. This method can save a large amount of I/O occupied by expanding the A/D, and this A/D converter can achieve very high resolution and accuracy, and has strong anti-interference ability and the resolution can be adjusted by the program, thereby increasing the application range and flexibility of the single-chip microcomputer, and at the same time the design of the application system is also concise and efficient.
References
1.AT89 series microcontroller. Ideal Electronics Co., Ltd.
2.Discrete Z8 Microcontrollers Databook.Zilong,Inc
Previous article:SM2965 microcontroller and its ISP application technology
Next article:Interface between DTMF circuit HT9200A and microcontroller
Recommended ReadingLatest update time:2024-11-16 19:38
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Electronic Engineers from Entry to Mastery
- Will low power consumption of small UWB modules be an inevitable development in the future?
- 【AT-START-F425 Review】No.07 8x8 Dual Color Dot Matrix Screen Carousel
- The meaning of Mosfet's capacitance coer and cotr
- [ESK32-360 Review] + DHT22 and single bus detection of temperature and humidity
- [TI recommended course] #Zero-based entry: Hand-in-hand teaching you how to quickly develop MSP430? Project#
- [Free Trial] Submit your application here and have a chance to win an Infineon drone~~
- About TL431: Questions about TL431 and TL432
- Who knows this digital tube?
- Comparison of UWB and its related technologies