Hi, everybody. I am using the 16F88 pic for my first time and I want to read a voltage generated by four infrared leds as sensors into inputs (RA0-RA3). I have read somewhere that these analogs pins are limited to 240 mvolts and I don’t know if it’s true. I setup the hardware and ran a test program and after solving some initial problems I have the circuit working but not as I expected it to work. When I grounded (1k resistor) all four inputs I should have nothing as readings and I got something (about 45 to 5 mvolts) very erratic. Here is the test program for you to evaluate. Please, help me find where I am wrong.Thanks.
OSCCON = $68 'Sets the internal oscillator to 4 Mhz
ANSEL = %00001111 'set RA0-RA3 as analog inputs
DEFINE adc_sampling 50 'Set sampling time IN micro sec.
TRISB = 0 'TURN PORT B as outputs
TRISA = 255 'TURN PORT A as inputs
ti var BYTE
ti = 50 '50 MILLISECONDS DELAY
A VAR WORD
B VAR WORD
C VAR WORD
D VAR WORD
READCDS:
PAUSE 1000 ' One second delay
ADCIN PORTA.0, a ' Reads portA pin 0 into A variable.
PAUSE 50 '50 Milliseconds delay
ADCIN PORTA.1, b ' Reads portA pin 1 into B variable.
PAUSE 50 '50 Milliseconds delay
ADCIN PORTA.2, c ' Reads portA pin 2 into C variable.
PAUSE 50 '50 Milliseconds delay
ADCIN PORTA.3, d ' Reads portA pin 3 into D variable.
'* * * * * * * * * Display Serially the sensor readings * * * * * * * *
PAUSE 100
Serout PORTB.1, 0, [254,1] 'Clear display
Serout PORTB.1, 0, [254,2] 'Send cursor home
PAUSE 20 'Pause 20 mseconds delay
Serout PORTB.1, 0, ["A= " , #(A)] 'Print A on mvolts
PAUSE 20
Serout PORTB.1, 0, [" B= " , #(B)] 'Print B on mvolts
PAUSE 20
SEROUT PORTB.1, 0, [$FE,$C0] 'Jump to second line
PAUSE 20
Serout PORTB.1, 0, ["C= " , #(C)] 'Print C on mvolts
PAUSE 210
Serout PORTB.1, 0, [" D= " , #(D)] 'Print D on mvolts
GOTO READCDS '********** Provisional loop Sensors test ***********
END
Bookmarks