Microchip Technology: Easy conversion - A look at how to implement an analogue-to-digital conversion in a low bandwidth application
Mark Pallones, Mike Gomez
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 Fig. 1.
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 10bit, 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 Fig 2.
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.
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 configured as an input pin. This yields the equivalent circuit in Fig. 4.
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 Fig. 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 Fig. 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.
Based on the circuit operation, equations are used by the microcontroller to calculate the conversion result. In Fig. 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 Fig. 5. When Vin is equal to Vmeas, the relation between the two currents is represented as Equation 2 in Fig. 5.
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 Fig. 6.
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.
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.
For a simple and low bandwidth analogue application, it usually requires a low cost yet high resolution A-D converter. By using the PIC16F5X 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.
LATEST issue 4/2019
The main topics of this year’s edition of the world’s leading trade fair for electronics development and production productronica 2019 are Smart Factory and Smart Maintenance. Mode details you can find here...
Тhis year’s edition of Europe’s trade fair for electronics design and manufacturing innovations and applications SEMICON Europa, traditionally co-located with productronica, will highlight smart technologies...