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.
Previous article:Zhou Ligong's words to young people studying microcontrollers
Next article:Clarify the differences between the five methods of C memory allocation
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Brief Analysis of Automotive Ethernet Test Content and Test Methods
- How haptic technology can enhance driving safety
- Let’s talk about the “Three Musketeers” of radar in autonomous driving
- Why software-defined vehicles transform cars from tools into living spaces
- How Lucid is overtaking Tesla with smaller motors
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Application of Single Chip Microcomputer in Inverted Pendulum Control System
- 【XMC4800 Relax EtherCAT Kit Review】+ Getting Started with DAVE, Timer Interrupt and UART Simple Application
- 【GD32307E-START】Development practice->UART sends HELLOWORD to the world
- Electromagnetic waves and antennas
- The voltage difference of bq4050 with load is very high, almost 1V. How to solve this problem? It is two strings of batteries.
- On Unjust Death and Redress
- LED stepless color temperature adjustment solution GP9101
- How much does it cost to build a 5G base station? The total investment is staggering
- What is the difference between feedback and howling?
- Types of Motion Controllers