# ADC with external VREF+ getting abnormal results - PIC micro 18F2321 (solved?)

#### atferrari

Joined Jan 6, 2004
4,425
PIC micro 18F2321

For several applications with ADC conversions I selected VREF- = Vss and VREF+ = Vdd, this last being 4,91V

Voltages to convert : 3,43V and 2,90V in AN0 and AN1 respectively. Conversion results were always correct:
For 3,43V I get 714
For 2,90V I get 604

Yesterday, changed to the option VREF+ = input in AN3. The actual external input is 3,69 V

Now, conversion results make no sense:
For 3,43V I get 1023
For 2,90V I get 1023

The input in AN3, is generated as shown in the image below. Calculated initially as 3,71V it is actually 3,69V

What am I doing wrong? Completely at lost here.

------------------------------------------------------------

Code:
;                        0.......       XX
;                        .0......       XX
;                        ..0.....       channel
;                        ...0....       selection
;                        ....0...       while in
;                        .....0..       operation
;                        ......0.       don't GO yet - patience!
;                        ..... .1       ADC converter up and running

;                       0.......        XX
;                       .0......        XX
;                       ..0.....        =0 VREF- = Vss / =1 VREF- = input in AN2
;                       ...1....        =0 VREF+ = Vdd / =1 VREF+ = input in AN3
;                       ....1...        =1 enable
;                       .....0..        =0 channels
;                       ......1.        =1 0, 1, 2 & 3
;                       .......1        =1 as analog

;                       1.......        =1 right justified
;                       .0......        XX
;                       ..0.....        =0 Tacq equal
;                       ...1....        =1 to
;                       ......0.        =0 to
;                       .......0        =0 4 Tosc

;We set the four ADC pins as inputs

#### ericgibbs

Joined Jan 29, 2010
13,639
hi at,
Those 1023 counts suggest that AN3 has not been set for Analog.??
E

#### Attachments

• 43.4 KB Views: 3

#### ericgibbs

Joined Jan 29, 2010
13,639
hola at.
Check this out.
E

#### Attachments

• 71.1 KB Views: 7

#### atferrari

Joined Jan 6, 2004
4,425
hi at,
Those 1023 counts suggest that AN3 has not been set for Analog.??
E
Hola Eric,

I feel that you hit the nail with that. For every conversion using VREF+ = AN3, I've been selecting just channel 0 or 1 but not channel 3.

Pity I cannot check it now; our area is in black out for more than 24 hrs already.

Will revert with the outcome asap.

Gracias.

Last edited:

#### atferrari

Joined Jan 6, 2004
4,425
Hola Eric,

I feel that you hit the nail with that. For every conversion using VREF+ = AN3, I've been selecting just channel 0 or 1 but not channel 3.

Pity I cannot check it now; our area is in black out for more than 24 hrs already.

Will revert with the outcome asap.

Gracias.
@ericgibbs

Eric, sorry but I was wrong.

This step

selects already the four channels A0:3 as analog

The command involving ADCON0 selects just the channel whose input should be converted next (in my case 0 or 1)

Have to keep looking for the cause of a failing conversion.

Could you brief me how to estimate / calculate the impedance of my V ref source?

Gracias.

#### click_here

Joined Sep 22, 2020
400
>Could you brief me how to estimate / calculate the impedance of my V ref source?

Measure the voltage with nothing connected to it, and then put a resistor on it and measure the voltage. From the change in voltage you can calculate the impedance

Example
Vopen=5V

4.95V/100R = 49.5mA

(5V-4.95V)/49.5mA = (approx) 1R

#### atferrari

Joined Jan 6, 2004
4,425
>Could you brief me how to estimate / calculate the impedance of my V ref source?

Measure the voltage with nothing connected to it, and then put a resistor on it and measure the voltage. From the change in voltage you can calculate the impedance

Example
Vopen=5V

4.95V/100R = 49.5mA

(5V-4.95V)/49.5mA = (approx) 1R
Gracias ch