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

Publisher:快乐的舞蹈Latest update time:2018-01-25 Source: eefocusKeywords:AT89C1051 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.


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

Previous article:51 Assembly equal-cycle pulse width modulation pwm subroutine
Next article:Idea and Principle of Intelligent Gas Meter Designed with AT89C2051

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号