CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC18F2520 Selecting single ADC port

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
elellilrah



Joined: 29 Aug 2007
Posts: 14

View user's profile Send private message

PIC18F2520 Selecting single ADC port
PostPosted: Fri Dec 07, 2007 1:03 am     Reply with quote

Hello,

I looked through the forums but wasn't finding the correct search term. I only want to use port RB2/AN8 on a PIC18F2520 for ADC conversion. However, in the CCS build, there is no option only to select AN8, but rather you are forced to use the following generated by CCS:

setup_adc_ports(AN0_TO_AN8|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL|ADC_TAD_MUL_0);

Is there a setup_adc_ports(xxx) option only for AN8? I don't want any of the other pins set to analog because they are doing other things.

Or, is this a case where you have to enable all of these ports and only read the AN8 port by using the command:

set_adc_channel(8);
delay_us(10);
value = read_adc();

and the processor will leave all the other ports alone to do their digital I/O? I don't yet have hardware to test this on but need to make some serious progress. Thanks!

Aaron
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Dec 07, 2007 1:56 am     Reply with quote

Download the 18F2520 data sheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/39631D.pdf
Look at this table on page 226 in the Acrobat reader:
Quote:
REGISTER 19-2: ADCON1: A/D CONTROL REGISTER 1

The CCS constants conform to the actual hardware options available
for the analog pins for this PIC.
elellilrah



Joined: 29 Aug 2007
Posts: 14

View user's profile Send private message

Little gray box
PostPosted: Fri Dec 07, 2007 11:20 am     Reply with quote

Thank you for the redirection. You are right that CCS does implement the datasheet on page 224.

An interesting problem then appears. On page 232 of the data sheet, in the little gray box, it suggests that you can just put an analog signal on any available analog port, turn on the ADC with A0, and it will convert on, say, A8.

However, will doing an INPUT() on any of the other ports still work as digital? And Note 2 suggests that doing this will cause the pin to consume high amounts of current, as it is operating in the linear region as a digital input.
Ttelmah
Guest







PostPosted: Sat Dec 08, 2007 4:02 am     Reply with quote

No. You are reading more than it says.
It says that the pin can be configured as a digital input, and still read using the ADC. You still need to select the pin for analog use, and select the channel.
What it allows you to do, is setup the chip to read pins AN0 to AN8 as analog inputs, select AN8, and then use the other pins for digital I/O. The paragraph in the data sheet, then lists the 'caveat' for doing this, which is that though the value will convert correctly, the chip may draw extra current when configured like this (typically if the input voltage sits in the indeterminate range for the input buffer).

Best Wishes
elellilrah



Joined: 29 Aug 2007
Posts: 14

View user's profile Send private message

PostPosted: Wed Dec 12, 2007 3:00 pm     Reply with quote

Thanks for the clarification. What I'll have to do is adjust the analog signals to start on the A0 line and go from there to avoid any of the other issues mentioned in the data sheet.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group