Good day to all at the forum.
I am going to set up the AN_0 to read a voltage of around 3.5 VDC and so I plan to use the Vref + connected to 5vdc an Vref - Connected to +2.5Vdc.
The PIC used is the 18F452 running at 40 Mhz clock.
I did the wiring in this way:
> AN0 pin_2 connected to the signal input ( 3.5 Vdc )
> AN3 ( Vref + ) pin_5 connected to 5Vdc
> AN2 ( Vref - ) pin_4 connected to a resistor divider that gives 2.5 Vdc.
I suppose that the ADresult will be "0" count at 2.5 Vdc input ( pin_2 )
and the ADresult has to be "1023" counts at 5.0 Vdc input at pin_2.
I wrote a small picbasic program but it seems to me that Vref - is not taken into account. It does not work !
Thanks for any help .
regards
Ambrogio
Here is the program:

' AD converter set_up.

' analog input on AN_0 pin_2
' Vref+ AN_3 on pin_5
' Vref - AN_2 on pin_4

TRISA = %11111111 ' port A set to all INPUT

ADCON1.3 = 1 ' PORTA.0 - ANALOG , AN2 - VREF(-) , AN3 - VREF(+) PCFG= 1111
ADCON1.2 = 1 ' PORTA.0 - ANALOG , AN2 - VREF(-) , AN3 - VREF(+)
ADCON1.1 = 1 ' PORTA.0 - ANALOG , AN2 - VREF(-) , AN3 - VREF(+)
ADCON1.0 = 1 ' PORTA.0 - ANALOG , AN2 - VREF(-) , AN3 - VREF(+)

ADCON0.0=1 ' ad = ON

'CLOCK CONVERSION

ADCON1.6=1 'ADCS2
ADCON0.7=1 'ADCS1
ADCON0.6=1 'ADCS0

' ANALOG INPUT SELECTION an_0

ADCON1.5=0
ADCON1.4=0
ADCON1.3=0

'RIGHT JUSTIFIED

ADCON1.7 = 1 ' Right justified.

'DEFINE ADC_BITS 10 ' ADCIN resolution (Bits)
'DEFINE ADC_CLOCK 3 ' ADC clock source
'DEFINE ADC_SAMPLEUS 50 ' ADC sampling time (uSec)

ADVAL VAR WORD
P VAR WORD
ADC_FLAG VAR BIT

MAIN: '------------------------------------------------------------


GOSUB RD_CLOCK_CALEN ' LETTURA CLOCK CALENDAR:
IF SEC <> SEC_OLD then ' EVERY SECOND...
GOSUB DISPLAY_CLOCK_CALEN
ADCON0.0=1
ADCON0.2=1 ' START CONVERSION > GO/_DONE
ADC_FLAG=1 '
ENDIF

IF ADC_FLAG=1 THEN
IF ADCON0.2=0 THEN ' WAIT FOR ADC_DONE

DEBUG DEC ADRESH," " , DEC ADRESL,13,10
ADVAL=ADRESL+(256*ADRESH)
P=ADVAL*5432
P=DIV32 1000
P=P+6611
DEBUG 13,10,"adval=",dec adval," P=",DEC P/10,".",DEC1 P//10," mBar",13,10
ADC_FLAG=0
ENDIF
ENDIF
GOTO MAIN