PDA

View Full Version : Incorrect reading of ADCIN on 16F876A



ozarkshermit
- 30th May 2011, 13:28
For some reason the voltage I see when monitoring some analog inputs on a 16f879A is not correct.
I am using a 4 Mhz Resonator on the test board. What I am doing is building a simple Solar Tracker, using 10mm Clear lens Green LED's to sense the sun
position. (There are many variations of this concept).

The anodes of each LED are connected to A.0 and A.1 respectively. The cathodes are connected to ground. I have a .01 mfd ceramic cap across each LED
for stability. The LED's will source up to 1.5 to 1.6 volts when subjected to bright light. This is what I want to monitor.

I am using a serial LCD to read the value of the Analog inputs, however it is incorrect. The value ranges from around 200 to a little over 300 (millivolts ?) I
change it by pointing a flashlight toward the LED's, and the output changes as it should, and is stable, just not the correct value. The LED's definitely output
up to 1.5 or 1.6 volts with the flashlight on them (I checked that using a DVM, as well as a scope).

Thinking the LED's were the problem, , I connected a 1K pot between VCC and VDD, with the wiper going to A.2. I preset the pot in the center at 2.5
volts on a Fluke DVM. The value I get from the analog input is around 500. It will change as I adjust the pot, just not the correct voltage.

Here is the code - it is basically a duplicate of the ADCIN10 example from PBP samples.
I am using PBP version 2.5 with the latest upgrade


[CODE]
DEFINE OSC 4
DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50

east var word ' EAST FACING LED, CATHODE TO GROUND, ANODE TO A.0
west var word 'WEST FACING LED, CATHODE TO GROUND, ANODE TO A.1
test var word ' THIS IS A 1K POT CONNECTED VCC TO VDD, WIPER T0 A.2
Tx var PORTC.6 'TRANSMIT TO SERIAL LCD BACKPAK

ADCON1 = %10000010 ' RIGHT JUSTIFY
TRISC = %00000000
TRISA = %11111111

goto main


measure: 'READ THE ANALOG PORTS

ADCIN 0,east 'LED'S OUTPUT UP TO 1.5 VOLTS WHEN FULLY EXPOSED TO LIGHT
pause 50
adcin 1,west
pause 50
adcin 2,test ' POT SHOULD READ 2.5 VOLTS AS A TEST
pause 50
RETURN

Main:

SEROUT2 Tx,84,[254,$01] ' clears the display
pause 50

GOSUB measure

SEROUT2 Tx, 84,[254,128,"EAST: ", dec east] 'DISPLAY THE DECIMAL VALUE
serout2 Tx,84,[254,192,"WEST: ",DEC west]
serout2 Tx,84,[254,148,"TEST: ",DEC test]
PAUSE 1000

GOTO Main

end

[CODE]

Any suggestions will be most welcome

Ken

mackrackit
- 30th May 2011, 13:43
I preset the pot in the center at 2.5
volts on a Fluke DVM. The value I get from the analog input is around 500

10 bits range from 0 to 1023. With ~5 volts as a reference 2.5 volts should read
~511 on the ADC. Sounds like the ADC is correct.

ozarkshermit
- 30th May 2011, 14:09
Thanks Dave

That makes everything abundantly clear.
I can live with that.

Ken