# Getting different values while connecting LM35 with PIC16F877A

I am getting different values while giving LM35 output as input to ADC (Pin RA0/AN0) PIC16F877A.

I am not providing any Reference voltage to the microcontroller. I want to make sure that is the reason for different values.

Also want to know why we need to give reference voltage Vref + & Vref -and how the circuit should me made for reference voltage?

In the datasheet, it was provided only like this,

• Welcome to EE.SE. (1) "I am getting different values ..." How different? How frequently? (2) Add a link to the datasheet and give a page number. Put all the information in your question - not in the comments. – Transistor Nov 12 '17 at 11:18

Figure 1. The ADC voltage reference selection.

The conversion of an analog input signal results in a corresponding 10-bit digital number.

That part, I presume you understand. The ADC converts the analog input to a 10-bit binary value.

The A/D module has high and low-voltage reference input that is software selectable to some combination of VDD, VSS, RA2 or RA3.

If you continue on in section 11 of the datasheet you find Figure 11-1 which gives a diagram of the arrangement.

Many simple ADCs allow you to measure analog inputs between 0 V and some positive value - typically +5 V. As the +5 V is generally the positive supply the accuracy of the conversion depends on the accuracy and stability of the supply voltage which might not be that good. In the case of your chip the datasheet says that it works from 2.0 to 5.5 V supply voltages. Clearly, if battery powered, for example, the ADC result will vary with battery voltage.

To get around this problem the ADC can use an external positive reference voltage. This is done by connecting the $V_{REF+}$ input to RA3 and applying the reference to that pin.

For some applications, and I suspect your LM35 circuit may be one of them, the input signal will never go to 0 V and may only vary between, say, 2.6 V and 3.2 V instead of 0 V and 5 V. We can improve your ADC resolution by connecting the $V_{REF+}$ to a 3.3 V reference and the $V_{REF-}$ to a 2.5 V source at the expense of giving up two ADC inputs.

The reference voltage configuration is done using Register 11-2 PCFG3:PCFG0: A/D Port Configuration Control bits. See page 130.