You are on page 1of 4

Embedded Microcontroller Design

Final Project Report

December 2009

Auto-Range 0-5V Voltmeter

Ibrahim Barbour

Sahand Noorizadeh
1 Introduction

The PIC4321 MCU has a 10-bit analog-to-digital converter (ADC). The high and low reference
voltages of this MCU can be set to be either the MCU’s positive and ground supply voltage VDD

and VSS or an external voltage. This reference voltage determines the ADC’s resolution. The
resolution per bit of the 10-bit AD is given by (1).


+
VREF − VREF
Resolution = (1)
210


+
To increase the resolution, VREF −VREF has to be made small but the minimum requirement for the
external reference voltages of the PIC4321 MCU is 1.8 V which sets the resolution to 1.7 mV. For
measuring small voltages less than 50 mV, this resolution will not provide accurate measurements.
One other way to increase the ADC’s resolution is amplifying the input voltage to be comparable

with the reference voltages. This can be done with a Programmable Gain Amplifier (PGA) that

is controlled by the MCU. A PGA has a predefined set of gains that are set by the data it receives

from an external controller.

In this project, Microchip’s MCP6S28, an 8-input SPI PGA, was used with PIC4321 to scan

the PGA’s output voltage with ADC to find an optimum PGA gain to measure the PGA’s input

voltage in the 0-5V range and display the voltage and its unit (V or mV ) on a LCD.

2 Implementation

2.1 Circuit Set-Up

Figure 1 shows the circuit diagram of the circuit diagram of the auto-range voletmeter implemented
with a PIC4321 MCU and a MCP6S28 PGA. Of the 8 input channels of the PGA only CH0 was
used. RB1 was used for the chip select digital signal. The input voltage was applied to CH0 and

1
Figure 1: Circuit diagram of the 0-5V auto-range voltmeter

V0UT of the PGA was connected to the analog input A0 of the PIC for AD conversion. A 2x24
Hitachi LCD which was connected to PIC to display the voltage and its unit.

2.2 Operation

MCP6S28 uses 16 bits of the SDI to either select a channel or set the gain. The first 8 bits are

the instruction bits followed by 8 bits of information. The 8-bit information are either the channel
number or the gain index depending on the instruction in the first 8-bit. The gain index chooses

gains that are predefined in MCP6S28 which are 1,2,4,5,8,10,16, or 32. Details of the timing

diagram can be found in the attached MCP6S28 datasheet.

The PIC program that was written for this project, sends an 8-bit serial data to select CH0 it

then performs the scanning and optimization routine in a non-stop loop every half a second. The

scanning and optimization routine performs the following steps:

1. starts with setting the PG’s gain to 1

2. reads the 16-bit ADRES register of the ADC

3. if the value is above 490, then it multiplies ADRES by the gain and displays the value on
the LCD. If the value is less than or equal to 490 then it increases the gain and goes back to
step 2. If the value is 1024, then it decreased the gain and goes back to 2.

2
If the gain is 32 and ADRES is below 490, then the gain will not change. The threshold value of
ADRES was chosen to be 490 (which is just below half of the maximum value of ADRES, 1024)
to provide high resolution for the MUC’s ADC.

To display the voltage, the value of the 16-bit ADRES was multiplied by the gain and the
result was stored in a 32-bit variable. A new ASCII() function was made to convert the value of
this 32-bit variable to ASCII code for up to 6 digits. DisplayV() function was used to display the
ASCII code of each digit on the LCD.

3 Results and Conclusion

All measurements made by the circuit of this project were compared in the lab with a commercial

voltmeter that displayed up to 8 decimal values. Ignoring variations in the order of 0.01 mV, all
measurements were identical. The minimum current draw of the circuit without the LCD was 1.26

mA and the maximum current draw was 2.65 mA.

The method used in this project provided an adaptive routine to effectively increased the
resolution of PIC’s ADC. For voltages above VDD , a voltage divider can used to attenuate the

input voltage and perform the same method as for the small voltages. This was tried and tested
in this project but due to variations in resistors that were available, accurate results were not

reached.

You might also like