PDA

View Full Version : 16F819 ADCIN Channel Select?



modifyit
- 27th April 2005, 02:31
If I am setting up a 16F819 chip to read only three of the analog pins on portA how do I select the Channel in (ADCIN channel, var)? In my application, see code below, I am using pins AN0,AN1,and, AN3 as analog and the rest of portA as digital.

Basically my question is does the channel increment as if every pin in portA is analog and thus AN3 would be channel 3? or would it be channel 2 in this application since AN2 is set up as digital?



trisa=%10001011

DEFINE ADC_BITS 16 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds

ADCON1 = %10000100 ' PORTA AN0,AN1,AN3 are analog
ADCIN 3, variable


Thanks for any help

mister_e
- 27th April 2005, 03:38
If you look into the PBP manual in the ADCIN section and read the example at the bottom... ADCIN 0.... will read channel 0 or AN0

look to your datasheet.. a/d converter don't gives you 16 bit results.

modifyit
- 27th April 2005, 18:22
I realized I had 16 instead of 10 bits after I posted it, but I am still confused on the ADCIN channel.

I realize ADCIN 0,variable will read the analog voltage in from pin AN0, but when I set the ADCON1 register up so that AN0, AN1, and AN3 are all analog how do I read from AN3?

Is it ADCIN 3, variable or ADCIN 2, variable. or do I need to be doing something with the ADCON0 register that I am not doing?

Thanks again

mister_e
- 27th April 2005, 18:31
ADCIN 0,VAR_0 'read channel 0...AN0
ADCIN 1,VAR_1 'read channel 1...AN1
ADCIN 3,VAR_3 'read channel 3...AN3

nothing else to modify IMO