A low-cost A/D conversion method based on AT89C1051/2051

Publisher:keiss2018Latest update time:2006-05-07 Source: 国外电子元器件 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

    Abstract: This article introduces a low-cost A/D conversion circuit and method based on AT89C1051/2051. This circuit uses general-purpose, cheap devices, uses linear sawtooth waves and the timer inside the microcontroller to obtain the A/D conversion results, and has a simple interface with the microcontroller. In addition to achieving a faster conversion speed using this method, the conversion resolution can also be set flexibly, which has certain practical value.

    In the design process of low-cost intelligent instruments, the priority is the cost issue. As the core component, the single-chip computer usually uses a low-end 8-bit computer or a 4-bit computer. As far as the current situation is concerned, low-end single computers with built-in A/D conversion are expensive, and when data collection 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 AT89C2051 microcontroller is only 7 to 8 yuan, while the price of medium-speed A/D conversion devices is mostly more than 20 yuan. The low-cost A/D conversion method introduced in this article can achieve medium-speed A/D conversion speed and less than 16-bit conversion resolution using only two general-purpose, cheap devices.

1 Principle

    There is a sawtooth wave signal with good linearity, the maximum amplitude is Vmax, the scanning time of the positive path (0 ~ Vmax) is t2 (straight line OB in Figure 1), the voltage Vt corresponding to a certain moment t during the positive scanning period is Vmax (t/t2). The 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 It is: 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 exceeds the amplitude of the analog signal to be measured at a certain moment, 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, IC1 is the AT89C2051 microcontroller. In addition to the functions of general I/O port lines, IC1 is also the non-inverting input terminal and inverting input terminal of the internal analog comparator. The output result of the comparator is internally Connect to P3.6. IC2 and IC3 are linear sawtooth wave generating circuits, and the moment when they start scanning 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 turned off, C1 is charged through R1 and W1, the linear sawtooth wave begins to scan in the normal process, and 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. Because the linear sawtooth wave voltage increases linearly from 0, P3.6 is 0 at the beginning of the normal scan. When the sawtooth wave voltage linearly increases to exceed the value to be measured When the voltage of the analog signal is simulated, 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. It can be obtained by the previous formula The value of the analog voltage to be measured. Its program block diagram is shown in Figure 3.

3. Determination of linear sawtooth wave circuit parameters

    Timer 0 of the AT89C2051 microcontroller is a 16-bit counter, so the highest resolution that this method can achieve is 16 bits, and the longest time to complete an A/D conversion at the highest clock frequency (24MHz) is about 33ms. In actual applications, such a high resolution may not necessarily be used. The longest time to complete an A/D conversion is 128 μs at 8-bit resolution. The following uses 8-bit resolution as an example to introduce the method of determining sawtooth wave circuit parameters.

    For the circuit in Figure 2, when the output of P3.7 is low, the sawtooth wave normal scan begins, C1 is charged through R1 and W1, and its voltage Vc1 is:

    V c1 =V cc ×(1-e-(t/τ))

    Where τ = (R 1 +R w1 ) C 1

    If op amp IC2:B amplifies V c1 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, a level of IC2:A is added for nonlinear compensation, and its output voltage V o2 can be expressed as:

    V o2 =V i2 =(V o1 +V c3 )/2

    =[10V cc (1-e-(t/τ))+V o2 (1-e-(t/η)12)]/2

    In the formula: Vcc=5V; η=(R5+Rw2)C3

    After sorting the above formula, we can get:

    V o2 =50(1-e-(t/τ))/(1+e-(t/η))

    The above formula is the theoretical expression of a linear sawtooth wave. By reasonably selecting the values ​​of τ and eta, a sawtooth wave with good linearity can be obtained.

    In actual design, we can use a C language program to theoretically obtain the optimal values ​​of τ and eta based on the above formula, and then adjust them based on the experimental results. The procedure is as follows:

    #include

    #include

    int main(void)

    {

    int τ=640, η=610; /*Preset the values ​​of τ and η*/

    double result,result-bak=0;

    double t,x,y;

    system("cls"); /*clear screen*/

    for(t=0;t<=127;t+=0.5)/*At 8-bit resolution, the positive path of the sawtooth wave is 128 microseconds*/

    {

    x=-t/τ;

    y=-t/η;

    result=50*(-exp(x))/(1+exp(y));

    printf(“%4fmV”,(result-result-bak) 1000);/*Increasing voltage (mv) every 0.5 microseconds*/

    result-bak=result;

    }

    }

    When τ=640μs, η=610μs, through the above programming process, the sawtooth wave can be made very close to linear, and the linear error per μ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 errors 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 does not affect the results of the A/D conversion. The second is caused by the microcontroller controlling the A/D conversion process, which includes three aspects: First, it is impossible for the microcontroller to complete the two actions of "turning on the conversion switch" and "timer starting counting" at the same time. ; The second reason is that the process of the microcontroller determining the on-chip analog comparator flipping requires two machine cycles, and the minimum counting unit of the counter is 1 machine cycle; the third reason is that the microcontroller confirms that the analog comparator output state flips and turns off the timer. Probably done at the same time. For the errors caused by the first and third situations, since they are indeed caused by instruction execution, the value of the error depends on the instruction execution time. Therefore, at the end of the conversion, this time can be subtracted from the value of timer 0. ; and the error caused by the second situation cannot be compensated.

5 Conclusion

    The data acquisition system designed using 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.

Reference address:A low-cost A/D conversion method based on AT89C1051/2051

Previous article:DC-DC converter with digital/analog conversion function
Next article:DSD/A digital-to-analog converter DSD-1700

Recommended ReadingLatest update time:2024-11-16 16:48

A low-cost A/D conversion method based on AT89C1051/2051
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 acq
[Microcontroller]
A low-cost A/D conversion method based on AT89C1051/2051
Latest Analog Electronics 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号