Single chip microcomputer realizes low cost A/D conversion

Publisher:冷漠之心Latest update time:2013-05-13 Source: 21ICKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

In the previous article, two methods of realizing low-cost A/D conversion using ordinary single-chip microcomputers were introduced. In both methods, a comparator is used outside the single-chip microcomputer. In this article, we will continue to introduce a method of low-cost A/D conversion, but this method is less expensive and does not require an external comparator. The A/D conversion accuracy of this method is not high, only 6 to 7 bits, and the measured voltage range is relatively limited, but it is also very practical in some occasions where the accuracy requirements are not high and the measured voltage value does not change much, such as temperature measurement.

The circuit is shown in Figure 1:

 

Its working principle is described as follows:

1. Hardware Description:

In Figure 1, R1, R2 and C1 form an RC charging circuit. The measured value charges C1 through R1 and R2. N1 is a single-chip microcomputer. This circuit uses MICROCHIP's PIC12C508A as an example. C2 is a filter circuit for power supply, and VD1 is a protective voltage-stabilizing diode to prevent the input voltage from being too high and damaging the single-chip microcomputer.

2. A/D conversion process:

First, GP5 outputs a low level to completely discharge the charge on capacitor C1. Then GP5 changes to the input state. At this time, the microcontroller starts timing. The measured voltage charges capacitor C1 through resistors R1 and R2. The voltage on capacitor C1 gradually increases. The voltage U on C1 satisfies the following formula:

 

 

Where U is the voltage on capacitor C1, E is the input voltage (to be measured), T=(R1+R2)*C1, and t is the time.

When the voltage U on C1 reaches the gate voltage of the MCU I/O pin, the GP5 of the MCU changes from a low level state to a high level state. The time t from the start of charging to this point is recorded.

From the above formula, we can see that when the gate voltage of the microcontroller I/O pin, R1, R2, and C1 values ​​are fixed, the measured voltage value E and time t have a one-to-one correspondence.

Therefore, by measuring the time it takes for the input voltage to charge the C1 capacitor to the gate embedded voltage and performing a table lookup calculation, the measured voltage value can be obtained, thereby realizing A/D conversion.

3. A/D conversion error analysis and solutions:

The error of A/D conversion is mainly determined by the following aspects, which are explained as follows:

(1) MCU power supply voltage VDD: In the A/D conversion, a large change in the VDD voltage may cause the gate voltage of the I/O port to change, but the impact is small.

(2) The measurement deviation of the voltage rise time on the C1 capacitor by the timer inside the microcontroller: This measurement deviation is the main factor of A/D conversion error. [page]

(3) Errors caused by unstable resistance and capacitance: When the value of resistors R1, R2 or capacitor C1 changes, the time it takes for the voltage of capacitor C1 to rise to the gate voltage will also change, which will also affect the A/D conversion result.

(4) Input impedance of the microcontroller I/O pin: If the input impedance of the microcontroller I/O pin is low, it is equivalent to changing the RC value, which will also affect the A/D conversion result.

(5) MCU gate voltage: For different MCUs, their gate voltages may be slightly different, which can also lead to measurement errors.

Solution to A/D conversion error:

(1) The error caused by VDD can only be solved by improving the VDD voltage accuracy. The VDD voltage should be stabilized within 2%. The ordinary 7805 has a 2% voltage regulation accuracy.

(2) For the error generated by the timer inside the microcontroller, the RC value can be increased to prolong the voltage rise time on the C1 capacitor, so that the value measured by the counter is larger and the error is smaller. However, if the R value is too large, it will be greatly affected by the input impedance of the I/O port.

(3) R1 and C1 can be made of resistors and capacitors with higher precision and greater stability, or a fine-tuning resistor can be added to solve the problem.

(4) If the input impedance of the microcontroller I/O pin is low, the problem can be solved by reducing the resistance of R1 and R2 and increasing the capacitance of C1.

4. A/D conversion speed and ways to improve it:

Since the A/D conversion is to obtain the A/D conversion value by charging the capacitor through a resistor so that the voltage reaches the gate voltage and then measuring the charging time, its A/D conversion speed is relatively slow. It is suitable for products that do not require high A/D conversion speed. Its A/D conversion speed depends on the following aspects:

(1) RC value: When the RC value is too large, the measurement speed will be slow. Reducing the RC value can increase the A/D conversion speed, but due to the shorter counting time, the measurement error will increase.

(2) The magnitude of the measured voltage value: Since the voltage U on C1 increases gradually from small to large, when the measured voltage value is small, the time it takes for the voltage U to rise to the gate value is longer, and the speed of completing the A/D conversion is slower. On the contrary, the higher the measured voltage is, the faster the measurement speed is.

As mentioned above, the speed of A/D conversion can be increased by reducing the RC value. If the microcontroller has an external level conversion interrupt, the accuracy of A/D conversion can be further improved.

5. Input voltage measurement range:

The input voltage measurement range of the A/D conversion is from the MCU gate voltage to the MCU power supply voltage (VDD). If the measured voltage range needs to be increased, the input voltage can be measured after being divided by a resistor, but the error of the A/D conversion will be affected by the voltage divider resistor.

6. Application examples of A/D conversion of single chip microcomputer:

The following figure shows an application example of using PIC12C508 to implement A/D conversion. In the figure, 4 LEDs are used to indicate the corresponding voltage range. The voltage measurement range is 1.4V to 2.55V, and the measurement accuracy is 10mV.

The application example and the original program can be found in MICROCHIP's microcontroller application notes, which can be downloaded from the MICROCHIP website.

 

 

Keywords:MCU Reference address:Single chip microcomputer realizes low cost A/D conversion

Previous article:Zhou Ligong's words to young people studying microcontrollers
Next article:Clarify the differences between the five methods of C memory allocation

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号