Hallo,

I have an problem with measure two values with the 16F876.
First i measure current (stroom) with 3,50 Volt on AN3, the value
then is correct and works fine.
Then i program thereafter basic for reading the voltage of an solar panel.
(zonnepaneel)
I use now the 5 Volt as Vref (no use of AN3)
The reading of the current from the first part is now different and not correct,
it changes to about 10% to 15 % higher.......
I have inserted pauses on different places etc. but have the same problem.
What are i doing wrong ???

this is de code i wroted:


================================================
' Connect analog input to channel-0 (RA0)
' Meet de stroom.

meten: ADCON1 = %01000001 ' Set PORTA analog and LEFT justify result
' and make Vref on AN3 = 3.50 Volt.
ADCON0 = %11000001 ' Configure and turn on A/D Module RA0
ADCON0.2 = 1 ' Start conversion (bit 2 = 1)
Pause 50 ' Wait .5 second
If ADCON0.2 = 1 Then meten ' Wait for low on bit-2 of ADCON0, conversion finished
adval = ADRESH ' Move high byte of result to adval
dummy = adval * 240 ' scaling
adval = div32 100 ' scaling
st1 = abs adval ' max. waarde is 600 (600 mA)
goto display ' Display current.

' Meet de spanning van zonnepaneel.

meetpnl: ADCON1 = %01000000 ' Reset AN3 Vref. (is nu weer 5 Volt)
ADCON0 = %11001001 ' Configure and turn on A/D Module RA1
ADCON0.2 = 1 ' Start conversion (bit 2 = 1)
Pause 50 ' Wait .5 second
If ADCON0.2 = 1 Then meetpnl ' Wait for low on bit-2 of ADCON0, conversion finished
adval = ADRESH ' Move high byte of result to adval
dummy = adval * 976 ' x 400 en 32 bits result in dummy lees bldz. 33
adval = div32 1000 ' : 255 en 32 bits divide scaling 150/255
adval = abs adval ' max. waarde is 400 (40 Volt)
pnl1 = adval /10 ' eerste digit scaling
pnl2 = adval // 10 ' de rest.
goto display ' Display Solar Voltage.