View previous topic :: View next topic |
Author |
Message |
elellilrah
Joined: 29 Aug 2007 Posts: 14
|
PIC18F2520 Selecting single ADC port |
Posted: Fri Dec 07, 2007 1:03 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Dec 07, 2007 1:56 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
elellilrah
Joined: 29 Aug 2007 Posts: 14
|
Little gray box |
Posted: Fri Dec 07, 2007 11:20 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Sat Dec 08, 2007 4:02 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
elellilrah
Joined: 29 Aug 2007 Posts: 14
|
|
Posted: Wed Dec 12, 2007 3:00 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
|