Posted on 09 June 2014

Easy Conversion

Free Bodo's Power Magazines!

 

 

 

A look at how to implement an analogue-to-digital conversion in a low bandwidth application

By Mark Pallones, Kristine Angelica Sumague and Mike Gomez, Microchip

Implementing an analogue-to-digital conversion in a circuit is one of the most common tasks facing designers and one that can be done in various ways. But for many simple and low bandwidth applications, such as a DC voltmeter for example, the goal is to keep the cost of the implementation low but still obtain a high resolution for the analogue-to-digital conversion.

A simplified schematic of such a circuit is shown in Figure 1.

Circuit diagram for an analogue-to-digital circuit

There are two input voltages connected one at a time to op amp U1. Vref is the fixed reference voltage used in calibration and Vmeas is the unknown voltage to be converted. Resistor R1 and capacitor C1 form a charging circuit used to convert input voltage to time. The existence of U1 in the circuit removes the logarithmic characteristic that would occur if the input voltage is directly applied to R1 and C1.

This circuit uses a PIC16F5X microcontroller from Microchip to control the U1 operation by turning the four switches (S1 to S4) on and off. Additionally, the microcontroller measures the time and calculates the digital representation of the unknown input voltage.

The circuit can also be used as a current mode A-D converter. In this case, the input voltage to the current converter is not needed and the reference current and input current are both routed via analogue switches directly into the capacitor.

The converter requires only five external components and is software and hardware configurable for conversion resolutions from 6 to 10 bit, and conversion times of 250μs or longer. The method is usable for both voltage and current conversion and uses a software calibration technique that compensates for time and temperature drift, as well as component errors.

To visualise the different stages of conversion, take a look at the U1 output voltage Vo waveform shown in Figure 2.

Operational amplifier output voltage waveform

At t0=t1, S1 and S3 are on, S2 and S4 are off and RA0 is pulled to ground by the software. This yields the equivalent circuit in Fig. 3.

Equivalent circuit during discharging

Vo is equal to Vref since Vin is equal to Vref and S3 to force unity gain feedback. C1 is discharging or is initially discharged after the reset state. In any case, this stage ensures that C1 is fully discharged before going to the next stage. At the end of t1, S1 remains on, S2 remains off, S3 is off, S4 is on and RA0 is confi gured as an input pin. This yields the equivalent circuit in Figure 4.

Equivalent circuit during measurement

As a function of Vref, Vo is started to ramp-up linearly while C1 is charging. The Vo ramp-up continues until the threshold voltage input Vth of the microcontroller trips. This generates a software calibration value equal to tref.

This calibration value is measured and used to calibrate out most circuit errors, including inaccuracies in the resistor and capacitor, changes in the Vth, and temperature variation.

After the software calibration value is measured at t2, S2 and S3 are on, S1 and S4 are off and RA0 is pulled to ground again by the software. This yields the same equivalent circuit in Figure 3. However, Vo is equal to Vmeas since Vin is equal to Vmeas and S3 to force unity feedback. C1 is discharging from t2 to t3. At the end of t3, S2 remains on, S1 remains off, S3 is off, S4 is on and RA0 is configured as an input pin. This yields the same equivalent circuit in Figure 4.

As a function of Vmeas, Vo is started to ramp-up linearly while C1 is charging. The Vo ramp-up continues until the Vth of the microcontroller trips. This generates a software Vmeas value equal to tmeas. This value is compared with the software calibration value to determine the actual digital representation of Vmeas.

Circuit equations

Based on the circuit operation, equations are used by the microcontroller to calculate the conversion result. In Figure 4, the current through R1 is equal to the current through C1. When the input voltage Vin is equal to Vref, the relation between the two currents is represented as Equation 1 in Figure 5. When Vin is equal to Vmeas, the relation between the two currents is represented as Equation 2 in Figure 5.

Analogue-to-digital conversion equations

Integrating Equations 1 and 2 yields the results shown in Equations 3 and 4. Since Vref and Vmeas have constant input, Equations 3 and 4 can be further reduced to Equations 5 and 6. At the end of each measurement, Vo of Equations 5 and 6 are both equal to Vth. Therefore, equating both equations yields Equation 7. Here, R1 and C1 can be eliminated and solved for Vmeas, the unknown input voltage.

In Equation 8, it is apparent that the measurement is independent of the value of circuit elements R1 and C1. This makes the conversion insensitive to errors in the R1 and C1 value, due to the inaccuracy or temperature variation. However, this does not mean that the values of R1 and C1 are unimportant in the design of the A-D converter. The values of R1 and C1 should be selected based upon the number of bits of resolution. Looking back at Equation 6 and solving R1C1 you get Equation 9 in Figure 6.

Calculation of R1C1 value

The actual value for R1C1 should be slightly smaller than calculated to ensure that the PIC16F5X microcontroller does not over count during the measurement. It should be noted that there will be a difference between the R1C1 value when implementing in Assembly and C because the instruction cycles per count when using C are greater than in Assembly.

Circuit performance

In actual applications, if measurement accuracy permits, it may be advantageous to use lower resolution bits and higher clock source. The maths code can be largely reduced and the measure time is reduced by the simpler code and shorter count.

The calibration value removes all first order errors (offset, gain, R and C inaccuracy, power supply voltage and temperature) except the reference voltage drift. Any change in the reference voltage, including noise, may result in measurement errors. Other error sources may be analogue switch leakage, resistor and capacitor non-linearities, input threshold uncertainty and time measurement uncertainty (plus or minus one instruction cycle time). Measured performance shows the converter to be accurate within 1% of full scale.

Conclusion

For a simple and low bandwidth analogue application, it usually requires a low cost yet high resolution A-D converter. By using the PIC16F5X (or the PIC16CFX) baseline family of microcontrollers, this article has demonstrated how to meet such requirements. The A-D converter does not only use fewer components but also has a capability to calibrate out most circuit errors.

 

VN:F [1.9.17_1161]
Rating: 6.0/6 (1 vote cast)
Easy Conversion, 6.0 out of 6 based on 1 rating

This post was written by:

- who has written 791 posts on PowerGuru – Power Electronics Information Portal.


Contact the author

Leave a Response

You must be logged in to post a comment.