Quote Originally Posted by lerameur View Post
ok , I have a problem now:

i wrote this program below, I configured so it read porta.0, but I get 0 output when I ground it and oscillation between 890 and to 900 when i put it to Vdd.
if I leave the program as is, and just put the input wire to portA.1 theni get 0 output when i groud the wire, and 1023 when I put it to Vdd.
Why am I getting a better result to a non configured port 6, at least i am ot calling this pin ??
my ADCON0 = %10000001 i believe this is for An0 to input
I am also trying to get two input for A/d , is that possible ?

'RECEIVE PIC
INCLUDE "modedefs.bas"


DEFINE OSC 20 'use external 20mhz crystal
DEFINE LCD_DREG PORTB ' Set LCD Data port
DEFINE LCD_DBIT 4 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
'DEFINE LCD_DATAUS 250
'DEFINE CHAR_PACING 2000
pause 1000

' Define ADCIN parameters
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS

input1 var word : input2 var word

TRISA = %11111111 ' Set PORTA to all input
CMCON = 7
ANSEL = %00001100
ADCON1 = %10000010
ADCON0 = %10000001

Pause 500

loop: ADCIN porta.0, input1

Lcdout $fe, 1 ' Clear LCD
Lcdout "Value1: ", DEC input1 ' Display the decimal value
lcdout $FE,$C0, "Value2: ", dec input2
Pause 200

Goto loop
End


Also, what do you mean by : Spare pin to resistor ?


Oscillation - I get that too on most everything I do on the A/D inputs (I don't know if it's a function of crappy circuit boards or bad design, doesn't matter to me anyways). You're probably going to want to do some sort of software averaging and/or put a capacitor across the input line to smooth it out a bit.

Spare pin on resistor - instead of putting the diode direct to battery power, thru a resistor to ground, you can intermittently power that diode thru a spare PIC output pin and save that power. Every little bit helps ya know.