【文章內(nèi)容簡介】
e is expressed in Volts, time in seconds, resistance in Ohms and capacitance in Farads. The product RC is also known as the “time constant” of t he work 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 without utilizing floating point calculations and transcendental functions. On a pressed 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 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 precalculated values to each sampled time interval. This 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 variations in ponent 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 symmetry of the capacitor charge/discharge cycle can be exploited to reduce the effect of variations in ponent 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 VCC/2. The worst case error is reduced to the error at VCC/2. Before ponent values can be assigned, the time interval at which the parator 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. 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 12MHz clock, resulting in a sample interval of five microseconds. The time constant (RC) 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 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, converter curve labeled ’V C’ repr esents 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 intervals. 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 t? to center the sample in the first voltage interval. To obtain the minimum value of the time constant which will produce the required slope at the first sample, solve Equation 1 for RC: RC = t/1n(1VC/VCC) (2) Then set V? to the minimum desired resolution (), t? to the sample interval determined previously (five microseconds), and calculate RC at the first sample point, where VC = 1/2 V? and t = 1/2 t? : 8 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? ?? ? ? ?? ? ? ?? ? ? ? The product of the values of R and 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 ( Rnorm1%) (Cnorm5%)*104 In the voltmeter application, the selected values of R and C are 267 kilohms and 2 nanofarads, respectively, yielding a minimum time constant of approximately ?104. An additional constraint is placed on the value of R. Referring again to Figure 1, note the kilohm pullup resistor connected to pin 11 of the microcontroller. This resistor is present to supplement the microcontroller’s weak internal pullup, but has the detrimental effect of changing the time constant of the RC work during the charge portion of the capacitor charge/discharge cycle. This produces an asymmetry in the charge/discharge waveform, which contributes to conversion error. To minimize the effect of differences in the capacitor charge and discharge paths, the value of R should be chosen to be much greater than the value of the pullup resistor. In the voltmeter application, the selected value of R is 267 kilohms, which exceeds the value of the pullup resistor by more than an order of magnitude. The time constant (RC), which is a function of the desired converter resolution, determines the duration of the capacitorcharge/discharge cycle. The more time required for the capacitor to charge and discharge, the greater the number of samples required in the measurement loop and the greater the number of entries in the lookup table. Figure 2. Typical Capacitor Charge/DIscharge Cycle Figure 3. Capacitor Voltage Variation as a Function of RC Variation Cto the symmetry of the capacitor charge/discharge waveform, the determined sample count may be used for measuremen