Documente Academic
Documente Profesional
Documente Cultură
The reference voltage plays a very important role in any A/D conversion. It determines both the range and the
resolution (Volt/Count) of the A/D conversion. Besides, the accuracy of the conversion also depends upon how
stable the reference voltage is. Usually in PIC microcontrollers, the reference voltage for A/D conversion can be
selected as the supply voltage itself or provided externally through one or more I/O pins. But the new enhanced mid-
range family of 8-bit PIC microcontrollers have a built-in module that generates a stable reference voltage internally.
It is called Fixed Voltage Reference (FVR) where the output is very stable and independent of the supply voltage
(VDD). The output of the FVR can be configured to supply a reference voltage for A/D conversion internally. This
article describes how to configure the FVR module to derive the reference voltage of 2.048 V for A/D conversion in
PIC16F1827 microcontroller. The analog signal for this experiment is taken from the output of a LM34DZ
temperature sensor. After the A/D conversion, the PIC16F1827 displays the temperature on a 28 character LCD.
Theory
The LM34 series are precision integrated-circuit temperature sensors from National Semiconductors, whose
output voltage is linearly proportional to the Fahrenheit temperature. They do not require any external
calibration to provide typical accuracies of 12F at room temperature and 1.5F over a full 50 to +300F
temperature range. The LM34DZ is available in a TO-92 case and the relationship between the linear output
voltage and the temperature is 10 millivolts per F. That is, at 75F its output reads 75 * 10 mV = 750 mV.
For full range of measurement, the output of LM34DZ goes from -0.50V (-50 F) to 3.0V (300 F). We are
not using any negative voltage source in this experiment, and therefore LM34DZ wont be able to measure
temperature below 0 F. Similarly, on the upper side, the measurement could go up to 300 F or less if
the positive reference voltage for the A/D conversion process is less than 3.0 V. Find more details about
LM34 in its datasheet.
Fixed Voltage Reference (FVR) in PIC16F1827
Once the FVRCON register is configured, the choice of reference voltage for A/D conversion is made through
ADCON1 control register. By setting ADPREF<1:0> bits to 1, the positive reference voltage for A/D conversion is
derived from the internal FVR module. Clearing the ADNREF bit connects the A/D negative reference voltage pin to
the ground (VSS).
Once the reference voltage is selected, the rest of the A/D conversion process is similar to any other PIC
microcontroller.
The reason for the reference voltage to be non-integer numbers like these is to provide a precise resolution in
A/D conversion. For example, if the positive A/D reference is 2.048 V and the negative reference is 0 V,
then the resolution of 10-bit A/D conversion is 2.048 V/ 1024 = 2 mV/Count. This means, in order to get the
analog value (in mV) back from the digital count, you just need to multiply the count by 2. Similarly, the
positive reference voltage of 4.096 V gives the conversion resolution of 4 mV/Count. This makes the
calculations easier and accurate.
Circuit diagram
The circuit diagram for this experiment is simple. The LM34DZ and the microcontroller circuit are powered
with a +5V supply. The output voltage of LM34DZ sensor is fed to the AN0 ADC channel of PIC16F1827.
The microcontroller runs at 500 KHz internal clock. The LCD display is operating in 4-bit data mode. The
D4-D7 data pins are driven through RB4-RB7 port pins, respectively. The RB2 (8) and RB3 (9) I/O pins
control the RS and E signals of LCD display. A 5K potentiometer is used for adjusting the contrast of the
LCD display.
Circuit diagram for reading the analog output from LM34DZ
This circuit can be easily constructed on a solder-less breadboard. I am demonstrating this on my self-made
development board for PIC16F1827/47 microcontrollers.
Software
The use of internal reference voltage for A/D conversion requires configuration of FVRCON and ADCON1
registers. The mikroC Pro for PIC compiler provides a library for A/D conversion, but that uses the supply
voltage, VDD , by default as the positive reference for the conversion. So the built-in ADC library of mikroC
Pro for PIC is not useful for our case. The following program is written for PIC16F1827 without using the
built-in ADC library and it allows to use the stable FVR output as the positive voltage reference for A/D
conversion. We will use 2.048 V reference voltage from the FVR module for the A/D conversion. This will
limit the maximum value of the input analog signal to 2.048 V. Since we are using the LM34DZ output for
the analog signal, this limits the maximum value of the measurable temperature to 204.8F. For measuring
temperatures higher than that, the reference voltage of 4.096 may be used.
ADC Math
/*
Description: Use internal 2.048 V FVR for A/D conversion
of LM34DZ output
MCU: PIC16F1827, 500 KHz internal clock, MCLR enabled
Jul 2, 2011
*/
// Define Messages
char message1[] = "Temp.";
char *Temp = "000.0 F";
unsigned ADC_Value, Temp_F;
void main() {
// Configure ADCON1
ADCON1.ADNREF = 0; // Vref- is connected to ground
ADCON1.ADPREF0 = 1; // Vref+ is connected to internal FVR
ADCON1.ADPREF1 = 1;
ADCON1.ADCS0 = 0; // Use conversion clock, Fosc/2
ADCON1.ADCS1 = 0; // Fosc = 500 KHz
ADCON1.ADCS2 = 0;
ADCON1.ADFM = 1; // result is right Justified
// Initialize LCD
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // CLEAR display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,2,message1); // Write message1 in 1st row
do {
Conclusions
A stable reference voltage is required in A/D conversion systems for accurate and repeatable data
conversion. While this can be achieved externally by using precision voltage regulators or zener diodes, the
enhanced mid-range 8-bit PIC microcontrollers facilitate this feature internally through the FVR module,
thus avoiding the use of any external components. The use of internal FVR module also frees the external
Vref pin, which means an extra GPIO pin. The microcontrollers power supply voltage (typically +5V) itself
can be used as the reference voltage for A/D conversion. While this allows the maximum range for A/D
conversion, it could possible introduce errors in the conversion if the supply voltage is not stable (usually the
supply voltage drifts with load conditions). Besides, if the range of the analog signal is much lesser than the
supply voltage, it is always good to use a lower reference voltage for achieving higher resolution. The FVR
module inside the 8-bit PIC microcontrollers of the enhanced mid-range family provides three stable and
configurable reference voltages internally, which makes the design of data conversion systems more flexible
and easier.