PDA

View Full Version : ADCON1 settings 18F4620



earltyso
- 8th February 2008, 21:07
Hello,
I want to set up 4 of the 13 availiable A2D converter pins on my 18F4620. Can someone clarrify for me......

If I want to set up AN0, AN1, AN4 & AN12 (8 bit resolution only) and leave every other pin on PORTA & B as digital input/ouputs.....

will this do the trick?


ADCON1.0=0
ADCON1.1=0
ADCON1.4=0
ADCON1.12=0

'tristates will already be defined above

skimask
- 8th February 2008, 21:21
Hello,
I want to set up 4 of the 13 availiable A2D converter pins on my 18F4620. Can someone clarrify for me......
If I want to set up AN0, AN1, AN4 & AN12 (8 bit resolution only) and leave every other pin on PORTA & B as digital input/ouputs.....
will this do the trick?
ADCON1.0=0
ADCON1.1=0
ADCON1.4=0
ADCON1.12=0
'tristates will already be defined above

Nope, doesn't work that way.
You can only have the analog ports the way the datasheet for the 18F4620 shows in DS39626B, page 224, under the heading Register 19-2.
As you'll see, ADCON only has 8 bits. ADCON1.12...not enough bits in ADCON for that.
Basically, you have to start at AN0 and add AN1, then AN2, then AN3, and so on until you get enough analog ports.

earltyso
- 8th February 2008, 21:41
Thanks for the help, I have read the data sheet for using ADCON1, ADCON2 registers and I am still confused on how to use the table on page 226. Can you lend a hand.
I think I need to use ADCON2 to enable AN12.

Something like....
ADCON2.4 = 0 '????????

skimask
- 8th February 2008, 21:44
Thanks for the help, I have read the data sheet for using ADCON1, ADCON2 registers and I am still confused on how to use the table on page 226. Can you lend a hand.
I think I need to use ADCON2 to enable AN12.

Something like....
ADCON2.4 = 0 '????????

Re-READ my post again...
Then Read the A/D chapter in the datasheet.
The ADCON registers don't work that way.
Question for you...
What does ADCON0 do?
What does ADCON1 do?
What does ADCON2 do?

Table on page 226? Which version of the datasheet do you have?

earltyso
- 8th February 2008, 21:53
ADCON0 controls operation of A/D module
ADCON1 configs functions of port pins
ADCON2 configs A/D clock source

this is page 224 DS39626, page 226 in pdf view

earltyso
- 8th February 2008, 21:59
OK, here is what I do understand,

for ADCON1 control register.....I need...

bit 7 = 0
bit 6 = 0
bit 5 = 1 'I am using Vref- AN2
bit 4 = 1 ' I am using Vref+ AN3

what I still don't understand....from page 224

bit 3 = ?
bit 2 = ?
bit 1 = ?
bit 0 = ?

BigWumpus
- 8th February 2008, 23:20
Some trick:

If there are analog signals on inputs, they can drive the current through the inputs to an high level, if they are digital inputs !

So,
you can declare all the inputs as analog and switch them to digital in the case of reading a digital input and switch them back to analog after (ADCON1).

You can switch all the AN3... to digital and see what happens ;-)
You can read the analog value without problems!

You can arrange the analog inputs on the first AN-channels !!!!!!

earltyso
- 9th February 2008, 00:00
Duh,
Got It!
I cannot pick and choose around which inputs I want I have to start with AN0 and work my way up or not at all.
thanks for the blunt yet helpful comments!
Just had to figure out how to read the table....had to look at the big picture.

skimask
- 9th February 2008, 06:56
Duh,
Got It!

Great! And believe it or not, that one little table and the way it is written and works, ties into soooo much other PIC stuff...so you didn't learn one thing...you learned a hundred things...just not all at once...YET...
Problem is...now you'll be up until all hours of the morning trying to figure out what to do next with all that new knowledge...