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:

================================================
' 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
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
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
pnl1 = adval /10 ' eerste digit scaling
pnl2 = adval // 10 ' de rest.
goto display ' Display Solar Voltage.

2. ## It is now working......

Originally Posted by Douwe
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:

================================================
' 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
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
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
pnl1 = adval /10 ' eerste digit scaling
pnl2 = adval // 10 ' de rest.
goto display ' Display Solar Voltage.

In the program i checked the ADCON0.2 bit for low and if it is not low, jump to
label meten: thats the problem.
label meten: starts with initialize the AD converter again etc. thats no good, i can't explane why, but now i jump to ADCON0.2 = 1 (start conversion) and it works fine.

------------------------------------------------------------------------
summary, wrong code:

Pause 50
If ADCON0.2 = 1 Then meten
etc.
etc.

Now, with good results:

Pause 50
If ADCON0.2 = 1 Then again
etc.
etc.
----------------------------------------------------------------------

Douwe (The Netherlands)

3. It would be better like so...

Code:
```meten:
ADCON0=%01000001		' Set Fosc, Select Channel, Turn-On A/D
Pauseus 50			' Wait for channel to setup
ADCON0.2 = 1			' Start conversion
While ADCON0.2=1:Wend		' Wait for conversion```

4. ## thats right

Originally Posted by Melanie
It would be better like so...

Code:
```meten:
ADCON0=%01000001		' Set Fosc, Select Channel, Turn-On A/D
Pauseus 50			' Wait for channel to setup
ADCON0.2 = 1			' Start conversion
While ADCON0.2=1:Wend		' Wait for conversion```
O.K. Melanie,
nice programming, and it works o.k. thanks for the tip.

Douwe.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts