In the design process of low-cost intelligent instruments, the priority is cost. As the core component, the single-chip microcomputer is usually a low-end 8-bit or 4-bit machine. As far as the current situation is concerned, low-end single-chip microcomputers with built-in A/D conversion are expensive. When data acquisition is required, external A/D conversion devices are often used, which greatly increases the cost of the system. For example, the current retail price of the AT89C2051 single-chip microcomputer is only 7 to 8 yuan, while the price of medium-speed A/D conversion devices is mostly above 20 yuan. The low-cost A/D conversion method introduced in this article uses only two general-purpose, inexpensive devices to achieve medium-speed A/D conversion speed and conversion resolution below 16 bits.
1 Principle
There is a sawtooth wave signal with good linearity, the maximum amplitude is Vmax, the scanning time of the positive process (0~Vmax) is t2 (such as the straight line OB in Figure 1), and the voltage Vt corresponding to a certain moment t during the positive process scanning is Vmax (t/t2). Curve CD in Figure 1 is an analog signal to be measured. The two signals intersect at point A, and the time is t1. It is not difficult to understand that the amplitude of the linear sawtooth wave at point A is the size of the analog signal to be measured, and its value Vt1 can be expressed as: Vt1=Vmax(t1/t2). That is to say, a method can be used to compare the analog signal to be measured with the linear sawtooth wave. When the amplitude of the linear sawtooth wave at a certain moment exceeds the amplitude of the analog signal to be measured, it will cause the comparator output state to change. Therefore, by measuring the time when the comparator output state flips, the size of the analog signal to be measured can be calculated.
2 Circuit and A/D conversion process
Figure 2 shows an A/D conversion circuit with 8-bit resolution. In the figure, IC 1 is an AT89C2051 microcontroller. Its P1.0 and P1.1, in addition to the functions of general I/O lines, are also the in- phase input and inverting input of the internal analog comparator. The comparator output is internally connected to P3.6. IC2 and IC3 are linear sawtooth wave generation circuits, and the moment when the positive scan starts is controlled by P3.7 of the microcontroller. IC3 is a dual-input NAND gate buffer driver, which is equivalent to a switch here. When P3.7=0, the switch is disconnected, C1 is charged through R1 and W1, and the linear sawtooth wave starts the positive scan. At the same time, the internal timer 0 of the microcontroller starts counting, and the counting pulse is the internal clock of the microcontroller. The analog signal to be measured is input from P1.1. Since the linear sawtooth wave voltage increases linearly from 0, P3.6 is 0 at the beginning of the forward scan. When the sawtooth wave voltage increases linearly to exceed the voltage of the analog signal to be measured, the output of the comparator flips, and P3.6 is 1. At this time, the value of timer 0 is the result of A/D conversion, which is t1 shown in Figure 1. The value of the analog voltage to be measured can be obtained through the previous formula. Its program flowchart is shown in Figure 3.
3 Determination of linear sawtooth wave circuit parameters
The timer 0 of the AT89C2051 microcontroller is a 16-bit counter, so the highest resolution that this method can achieve is 16 bits. At the highest clock frequency (24 MHz ), the longest time to complete an A/D conversion is about 33 ms. In actual applications, such a high resolution may not be used. At an 8-bit resolution, the longest time to complete an A/D conversion is 128 μs. The following takes 8-bit resolution as an example to introduce the method of determining the parameters of the sawtooth wave circuit.
For the circuit in Figure 2, when the output of P3.7 is low, the sawtooth wave positive scan begins, C1 is charged through R1 and W1, and its voltage Vc1 is:
V c1 =V CC ×(1-e-(t/τ))
Where τ = (R1 + Rw1) C1
If op amp IC2:B amplifies V c1 by 10 times, its output is:
Vo1=[1+(R 3 /R 2 )]V c1
=10V cc (1-e-(t/τ))
Because the output of IC2:B is not a linear sawtooth wave, an additional IC2:A is used for nonlinear compensation. Its output voltage Vo2 can be expressed as:
Vo2 =V i2 =(V o1 +V c3 )/2
=[10V cc (1-e-(t/τ))+V o2 (1-e-(t/η)12)]/2
Where: Vcc = 5V; η = (R5 + Rw2) C3
After rearranging the above formula, we can get:
V o2 =50(1-e-(t/τ))/(1+e-(t/η))
The above formula is the theoretical expression of the linear sawtooth wave. By reasonably selecting the values of τ and η, a sawtooth wave with good linearity can be obtained.
In actual design, we can use a C language program to first theoretically obtain the optimal values of τ and η according to the above formula, and then adjust them according to the experimental results. The program is as follows:
#include
#include
int main(void)
{
int τ=640, η=610; /*preset τ, η values*/
double result,result-bak=0;
double t,x,y;
system("cls"); /*Clear screen*/
for(t=0;t<=127;t+=0.5)/*When the resolution is 8 bits, the positive path of the sawtooth wave is 128 microseconds*/
{
x=-t/τ;
y=-t/η;
result=50*(-exp(x))/(1+exp(y));
printf("%4 FM V",(result-result-bak) 1000);/*Voltage (mv) increasing every 0.5 microseconds*/
result-bak=result;
}
}
When τ=640μs and η=610μs, the above programming process can make the sawtooth wave very close to linear, and the linear error of each μs is within 0.1mV, which can fully meet the requirements of 8-bit resolution A/D conversion.
4 Error analysis and compensation
There are two main sources of error in A/D conversion using this method. The first is the error caused by the nonlinearity of the sawtooth wave. According to the above description, the nonlinearity of the sawtooth wave basically has no effect on the result of A/D conversion. The second is caused by the single-chip microcomputer in the process of controlling A/D conversion, which includes three aspects: First, the single-chip microcomputer cannot complete the two actions of "turning on the conversion switch" and "starting the timer to count" at the same time; second, the process of the single-chip microcomputer judging the flip of the analog comparator on the chip requires two machine cycles , and the minimum counting unit of the counter is 1 machine cycle; the third reason is that the single-chip microcomputer confirms that the analog comparator output state flips and turns off the timer. It is impossible to complete it at the same time. For the errors caused by the first and third situations, since it is indeed caused by the execution of instructions, the value of the error depends on the time of instruction execution, so at the end of the conversion, the value of timer 0 is subtracted from this time; while the error caused by the second situation cannot be compensated.
5 Conclusion
The data acquisition system designed by the method described in this article has low cost, simple interface and high performance-price ratio. It should be pointed out that in order to ensure the long-term stability of the system, highly stable integrating capacitors ( C1, C3) should be used.
Previous article:51 Assembly equal-cycle pulse width modulation pwm subroutine
Next article:Idea and Principle of Intelligent Gas Meter Designed with AT89C2051
- Popular Resources
- Popular amplifiers
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
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- The impact of high temperature on LED display
- [Gizwits Gokit 3 Review] Part 4: Temperature and humidity monitoring and computer power on and off
- Basic knowledge of inductance
- When installing AltiumDesigner20, the Unable download extension IPC Footprint Ge...
- 2. ESP32-S2-Kaluga-1 development environment ESP-IDF construction
- Hikvision overseas version ball camera can not be used
- Today afternoon 14:00 live broadcast [Latest TI C2000 real-time control chip - F28003X]
- SPI slave returns data to the host in dislocation
- SensorTile.box V335 Firmware
- SensorTile.box IoT-related application supplementary content