Using Microcontrollers for High Accuracy Analogue Measurements

Paper discusses some cost-efficient and convenient solutions for the microcontroller-based voltage measurements. Microcontrollers offer several flexible possibilities to modify the reference voltage, to switch between different amplification/attenuation coefficients or to add a necessary bias to the measured voltage. Five unconventional methods are described that have been used in scientific experimental research and/or distant learning toolkits to enhance the accuracy of the built-in analogue to digital converters of ordinary microprocessors.


I. INTRODUCTION
Microcontrollers (MCU) have become the widely used components of modern electronics due to the flexibility offered by the software.Constantly improving performance at low price makes MCUs more and more attractive for variety of applications.Most of the MCUs have the built-in analogue to digital (AD) converters (ADC) that may be used for analogue data acquiring [1]- [4].Typically those built-in ADCs have the 10-bit resolution that is sufficient for the general purposes but in some cases the higher accuracy is needed.There is always a choice to use an accurate external ADC but often simplicity, low power and cheapness [2]- [6] are required.Then a more optimal choice may be the usage of the built-in ADC with enhanced accuracy due to the versatile software and hardware-based options offered by the MCUs.Below we discuss five unconventional solutions that have been used either in scientific measurements [5], [6] or in distant learning toolkits [3], [4].The example MCU is the AVR Atmega88 [7] with 10-bit built in ADC, 8-bit data bus and 16-bit internal registers.

II. AD CONVERTER IN ATMEGA88
Typically MCUs have rather similar structure of AD conversion (Fig. 1).The AVR microcontrollers have 10-bit successive approximation ADC [7].This ADC block is connected to an 8 channel analogue multiplexer (INPUT MUX in Fig. 1) which allows 8 single-ended voltage inputs from Port C (ADC0-ADC7).Additionally a reference voltage pin AREF or a separate supply voltage pin AVCC may be used.The internal reference (1.1 V) is available as well.Thus the analogue multiplexer gives possibility to switch between 8 analogue measurement channels.

A. Adjustable reference voltage
Most of the MCUs with ADC have possibility to use external reference voltage V ref .Usually this voltage is stabilized and fixed but intentionally varied V ref may give possibility to get higher measurement precision at lower input voltages.To adjust V ref , the PWM (pulse with modulation) output possibility of MCU can be used (Fig. 2).In the present example the 16-bit output compare register OCR1A (also other registers can be used) of Atmega88 is used that gives the PWM signal (see Fig. 2).This time-dependent signal is averaged by the R0-C0 low-pass filter with characteristic frequency of 0.3 kHz range in order to get the averaged DC voltage from PWM output that is also the reference voltage of input V ref .Using currently available value of the ADC output, the OCR1A signal is adjusted by the software in such manner that the ADC output is approximately in the middle of range with the small hysteresis.
In the case of this approach the input voltage is calculated as where V cc is the supply voltage; O ADC is output value of AD converter; N is the number of bits of AD converter (presently 10 bits that yields 1024 levels); CR O is the timeaveraged value of output compare register OCR1A and N CR is the number of bits of this register (presently 16 corresponding to 65536 levels).Note that the described replacement of reference voltage is a rather simple solution to improve the accuracy of the standard inflexible measurement scheme if the reference voltage is fixed to the high value close to the supply voltage V cc .(between 2.7-5.5 V in the case of Atmega88 [7]).Due to the 16-bit basis, the accuracy of PWM signal formation is remarkably higher than the accuracy of the 10-bit ADC.The accuracy of the formed reference voltage depends thus mainly on the accuracy of the supply voltage V cc .The basic accuracy of ADC of Atmega88 is 2 LSB (last significant bits) [7], i.e.V ref /512.As the minimal accepted value of V ref is 1 V for Atmega88 [7], the described here method may improve input voltage measurement accuracy approximately 5 times compared to the inflexible measurement scheme with fixed V ref close to 5 V.

B. Input voltage shift
In some measurements [5], [6] a large constant offset bias voltage may be present.At the same time the high accuracy of measurement might be needed for the useful signal.In that case the constant bias may be subtracted from input voltage applying the operational amplifier (Fig. 3).By selecting the necessary resistor value ratios, the maximum voltage range for this kind of compensation may be quite high (>10 V).The default solution (Fig. 3) assumes the inverted input that means the negative input voltage values.To get the positive range, an additional inverter must be used.The reference voltage V ref .may be taken from PWM output or from built in 1.1 V source.
In this solution the operational amplifier summarizes the voltages according to the following formula where with notations corresponding to (3) and Fig. 3.The software tries to adjust the PWM output so that the input is in a reasonable range.Because of usage of the PWM output, the supply voltage of the MCU must be carefully stabilized.This method makes possible measurements out of the supply voltage range and gives possibility to amplify the small changes of the input voltage by the factor R3/R2.

C. Bipolar input measurements
Typically the ADC converters of the MCU are designed for unipolar measurements, e.g. from 0 V to +5 V. Usually the MCUs include the analogue multiplexer, which allows to switch between multiple inputs.The idea of bipolar measurement is to try one multiplexer channel for positive voltage and the second channel for negative voltage (converted to positive with inverter (Fig. 4)).
The result is summarized simply as where O ADC1 and O ADC1 are output values of AD converter in the case of channels 1 and 2. At that is important that the negative input voltage at the MCU pins is restricted by protection diodes inside of MCU and the ADC conversion block yields zero output in the case of negative input.
Fig. 4. Using the internal multiplexer, the bipolar measurement can be performed.Input ADC1 is non-inverted and input ADC2 is inverted (preamplification coefficients +1 and -1 respectively).
The resistors R' and R'' in Fig. 4 limit the useless current through protection diodes.Thus for measurement of the DC input voltage of unknown polarity two measurements from different inputs may be performed and the results summarized as the wrong polarity gives zero influence.Here for reference voltage both the PWM output or the built-in 1.1 V standard source may be used.

D. Selection of input amplifier
Besides the selection between voltage polarity, the analogue multiplexer input gives possibility to apply different preamplifiers to switch between different sensitivity ranges (Fig. 5).Fig. 5.By using the multiple input amplifiers, the measurement range can be extended.Preamplification coefficient for channel 2 is (R1+R2)/R1.
The resistors R' and R'' serve for current limiting purposes, either for the cases if the output voltage of amplifier exceeds supply voltage or if this amplifier output may become negative and the protective diodes inside the MCU should survive the input current.
Considering the Fig. 5, the input voltage for nonamplified input ADC1 may be calculated simply as and for amplified input ADC2 as This method makes possible to improve the absolute accuracy of the measurement of the small input voltages by the factor (R1+R2)/R2.

E. Input attenuation using Z-state of MCU
Majority of the MCU pins can be configured for input or for output purposes by the software.Internally those input/output pins are realized via MOSFET switches that may have different resistance states.If the pin mode is "input" then impedance of this pin is high (>10 MΩ).This may be called the z-state.If pin mode is switched to "output" then the pin is connected to "ground" (state 0) or connected to "V cc ."(state 1, not used here).Software-controlled switching between high and zero impedance states may be used to realize different combinations of input attenuation resistors (Fig. 6).The output port B pins can be used simultaneously to adjust attenuation.Also usage of R2R network is possible.For example, if only Port B pin 1 is in low impedance state as shown in Fig. 6, the input voltage can be calculated as

III. PRACTICAL EXAMPLE
The combined usage of the above described approaches may be illustrated by the circuit (Fig. 7) that has been used in the portable capillary electrophoresis measurement instrument [5], [6].The principle of this type of detector is explained in [8].
Note that Fig. 7 presents only a simplified circuit as the communication and other digital control circuits have been removed.Also signal generator (frequency range of from 100 to 1000 kHz and in the voltage range of from 10 to 100 V p-p.) is not shown.Output of the generator is connected to contactless conductivity detector.The output voltage of the detector depends on conductivity and solvent's concentration.The range of the output (the baseline) is from hundreds of µV to hundreds of mV.The signal from the detector cell is amplified using the operational amplifier IC5A, and rectified using IC5B.After passing low pass filter, the signal (the baseline bias that must be compensated) can be coarsely measured with the MCU (input ADC1).The software analyses the signal level and, if necessary, amplification and generator parameters (voltage, frequency) can be adjusted.The signal is amplified (approx.50 times) for the main measurement and the bias is compensated with two signals from separate PWM output (registers OC0A and OC0B, like Fig 3).One output is used for coarse and the other for fine compensation.The signal is measured using the MCUs 10 bit ADC.The device is connected to computer using USB to TTL converter FT232R (not shown in circuit).The MCU has powered from separate voltage stabilizers for digital and analogue circuits.

IV. CONCLUSIONS
In this paper we demonstrated several example approaches how the accuracy and flexibility of the voltage measurements may be improved via the use of microprocessors.The discussed five solutions may be applied separately or in the combined mode.Those solutions have all been practically tested in several projects were the cost efficiency was one of the main demands.It must be noted that the flexible forming of reference voltage via the pulse width modulation output needs a power supply of enough high quality.

Fig. 2 .
Fig. 2. Increasing the input voltage measurement accuracy by the reference voltage adjustment.The software-controlled PWM output is used to obtain the flexible control over the input reference voltage value.

Fig. 3 .
Fig.3.Using an operational amplifier for adding a shifting voltage to the input.Note that the present circuit operates with the negative voltage in the input, another operational amplifier inverter must be added for positive voltage range.

Fig. 6 .
Fig.6.The software-controlled switching between zero and high impedance states of I/O pins allows to obtain the necessary attenuation coefficient for the measured input voltage.

Fig. 7 .
Fig.7.Example of signal processing used in portable capillary electrophoresis measurement instrument[5],[6].Port C pins 0 and 1 are used for voltage measurement, pin C2 only for battery check.Pulse width modulation output to perform the subtraction (compensation) of DC bias is taken from the Port D pin 5 or pin 6. Actual subtracting of bias from input signal is performed by the operational amplifier IC3B.