1、附录 1 外文文献及中文翻译 Analog-to-Digital Conversion Utilizing the AT89CX051 Microcontrollers The Atmel AT89C1051 and AT89C2051.microcontrollers feature on-chip Flash,low pin count, wide operating voltage,range and an integral analog comparator.This application note describes two low-cost analog-to-digital c
2、onversiontechniques which utilize the analog comparato r in the AT89C1051 and AT89C2051 microcontrollers. RC Analog-to-Digital Converter This conversion method offers. An extremely low component count at the expense of accuracy and conversion time. In the example presented below,resolution is better
3、 than 50 millivolts, accuracy is somewhat less than a tenth of a Volt and conversion time is seven milliseconds or less. As shown in Figure 1, the RC analog-todigital. conversion method requires only two resistors and a capacitor in addition to the AT89CX051 microcontroller. A microcontroller output
4、 (pin 11), which swings from approximately ground to VCC, alternately charges and discharges the capacitor connected to the non-inverting input of the internal comparator (pin 12). The microcontroller measures the time required for the voltage on the capacitor to match the unknown voltage applied to
5、 the inverting input of the internal comparator (pin 13).The unknown voltage is a function of the measured time. The HP5082-7300 LED displays shown in Figure 1 are not required for the conversion, but are utilized by the software to implement a simple two-digit voltmeter.The result of the analog-to-
6、digital conversion is displayed in volts and tenths of a volt on the two displays. The voltmeter application does not utilize the full resolution of the RC conversion software,but serves to demonstrate the method as well as providing a tool for debug. The waveformfor a typical capacitor charge/disch
7、arge cycle is shown in Figure2. The discharge portion of the curve is identical to the charge portion rotated about the line VC = VCC/2. The equations and discussion below apply to the charge portion of the cycle, except where indicated. The voltage on the capacitoras a function of time is given by
8、the exponential equation: VC=VCC(1-e-t/RC) (1) where VC is the voltage on the capacitor at time t, VCC is the supply voltage and RC is the product of the values of the resistor and capacitor. Note that voltage is expressed in Volts, time in seconds, resistance in Ohms and capacitance in Farads. The
9、product RC is also known as the “time constant” of the network and affects the shape of the waveform. The waveform is steepest when capacitor charging or discharging begins and flattens with time. The first problem with the RC conversion method is the difficulty of solving the exponential equation w
10、ithout utilizing floating point calculations and transcendental functions. On a compressed time scale, the exponential curve appears straight over much of its length, suggesting that it might be approximated by a line. This scheme fails due to the continuous variation in slope over the length of the
11、 curve, which produces significant error. It also does not address the problemwhere the curve rolls off severely near the asymptote at VCC. The microcontroller need not solve the exponential equation in real time if a lookup table is used to map pre-calculated values to each sampled time interval. T
12、his scheme allows the data to be encoded and formatted as required by the application while simplifying the conversion software. Symmetries in the data may be exploited to reduce the size of the table. The second problem with the RC conversion method is the substantial error which results from varia
13、tions in component values. Figure 3 shows an exaggerated view of the variation in the voltage on the capacitor due to variations in the values of the resistor and capacitor. As shown in the figure, the variation in the voltage on the capacitor decreases as the voltage on the capacitor decreases. The
14、 symmetry of the capacitor charge/discharge cycle can be exploited to reduce the effect of variations in component values on conversion accuracy. This is done by utilizing the charge portion of the cycle to measure voltages less than VCC/2 and the discharge portion to measure voltages greater than V
15、CC/2. The worst case error is reduced to the error at VCC/2. Before component values can be assigned, the time interval at which the comparator output is to be sampled must be determined. The sample interval should be as short as possible to maximize converter resolution and minimize conversion time
16、. The sample interval is limited by the time required to execute the requisite code, which is determined by the clock rate of the microcontroller. In the voltmeter application, the microcontroller operates with a 12-MHz clock, resulting in a sample interval of five microseconds. The time constant (R
17、C) affects the shape of the capacitor charge/discharge waveform. The value of the time constant must be chosen so that the steepest parts of the waveform are resolvable to the desired resolution. The steepest part of the charge portion of the waveform occurs near the origin, while the steepest part
18、of the discharge portion occurs near VCC. Due to the symmetry of the waveform, the same time constant may be used for measurements made on either portion of the waveform. Figure 4 shows an expanded view of the relationship between voltage and sample time near the origin. In the figure, V is the desi
19、red voltage resolution of the converter and t is the sample interval determined previously. The curve labeled VC represents the voltage on the capacitor, which appears linear at this scale. In the figure, the slope of the curve is ideal, causing sampling to occur near the center of the voltage inter
20、vals. The slope of the curve may be less than shown, but may not be greater, or resolution will be lost. Note that the first sample is offset from the origin by1/2 to center the sample in the first voltage interval. To obtain the minimum value of the time constant which will produce the required slo
21、pe at the first sample, solve Equation 1 for RC: RC=-t/1n(1-VC/VCC) (2) Then set to the minimum desired resolution (0.05-volt), to the sample interval determined previously (five microseconds), and calculate RC at the first sample point, where VC = 1/2 and t = 1/2 : The product of the values of R an
22、d C must not be less than the calculated minimum time constant. Utilizing a resistor with a one percent tolerance and a capacitor with a five percent tolerance ( Rnorm-1%) (Cnorm-5%)4.99*10-4 In the voltmeter application, the selected values of R and C are 267 kilohms and 2 nanofarads, respectively,
23、 yielding a minimum time constant of approximately 5.0210-4. An additional constraint is placed on the value of R. Referring again to Figure 1, note the 5.1 kilohm pullup resistor tV tV t8 4m i n m i n( 1 / 2 ) ( 1 / 2 ) ( 5 1 0 ) 4 . 9 9 1 0l n 1 ( 1 / 2 ) / 1 ( 1 / 2 ) ( 0 . 0 5 ) /C C C CtRC V V I n V