# ADC in a micro - actual use of -Vref

#### atferrari

Joined Jan 6, 2004
4,752
Thinking of ADC in a PIC 18F micro.

I need to perform AD conversions of a single ended signal ranging between 2900 and 3700 mV. By design I know that it cannot escape from there.

To increase resolution I should bring those values down to the 0 - 800 mV range and reduce Vref as much as the micro allows (and as long it is equal or higher than 800 mV), always with -Vref to ground. For the moment, I cannot change the level of the input range, so I am left playing only with Vrefs.

Today, reading the manual of a micro, I realized the possibility of deciding on the +Vref and -Vref settings. I never had clear what is the use of -Vref , thus my questions:

a) For my range 2900-3700 mV, would it make sense to set: +Vref =5,0V and -Vref =4,2V?

b) If the above is just stupid, could anyone at least give a concrete example of what's the use of -Vref? Kind of a grey area to me.

#### JohnInTX

Joined Jun 26, 2012
4,787
Sure. The ADC divides the voltage range between Vref- and Vref+ into 1024(10bits) codes. An input voltage of Vref- reads 000h, an input voltage of Vref+ reads 3FFh. Many times the input is referred to GND so you can tie Vref- to Vss, making GND the lower limit of the conversion range. But suppose your input is 1V - 4V for example. You still could use Vref- = GND and Vref+ = Vdd but you would give up some codes on either end (because the input range is 0-5V, not 1-4V) making the ADC have fewer useful codes out of the 1024 available. By setting Vref- = 1V and Vref+=4V, you now remap the entire 1024 ADC codes over the useful input range, increasing resolution. Inputs < 1V will rail at 000 and inputs >4V will rail at 3FFh (without damaging the ADC since its input range is determined by Vss and Vdd (or AVss and Avdd if present).

Note that the minus in Vref- does not mean negative voltages, just the lower limit of the convertible input range.

EDIT: a good way to increase accuracy is to take Vref(s) back to the source of the analog that you are measuring. That way, any drift, offset due to trace resistances etc. will be taken into account by the ADC's measuring between the Vref pins. In all cases, be sure that these (or any analog) pins never exceed the absolute maximum voltages section of the datasheet. That can be an issue during power up when the digital bus is powered from a supply that comes up slower than the analog supply (seen it - PIC gets HOT!).

Have fun.

Last edited:

#### shteii01

Joined Feb 19, 2010
4,644
One for the lower reference of 2.9V or close to it.
Second for the upper reference of 3.7V or close to it.
This way, following John's explanation, you have the range of voltages fit into the ADC range of digital values.

#### atferrari

Joined Jan 6, 2004
4,752
Sure. The ADC divides the voltage range between Vref- and Vref+ into 1024(10bits) codes.
Gracias John. Now it seems simple for me. I am going to use the 18F4431 with a minimum delta Vref = 1,5V. Not the best but I have it here.