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 support@ccsinfo.com

Setup ADC on PIC18F4685

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



Joined: 07 Feb 2008
Posts: 17
Location: Canada

View user's profile Send private message

Setup ADC on PIC18F4685
PostPosted: Thu Apr 17, 2008 1:08 pm     Reply with quote

I need to use ADC channels AN0 to AN5 and AN8. I will be sampling between VSS(GND) and VDD(5V). The other "pins" need to stay digital. How would my setup_adc_ports() look like?

Thanks. Wink
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 17, 2008 1:14 pm     Reply with quote

Look in the .H file for your PIC. Near the end of the file, it gives the
allowable settings for that function. Look in this directory:
Quote:
c:\program files\picc\devices\18f4685.h
RageOfFury



Joined: 07 Feb 2008
Posts: 17
Location: Canada

View user's profile Send private message

PostPosted: Thu Apr 17, 2008 1:38 pm     Reply with quote

Quote:
// Constants used in SETUP_ADC_PORTS() are:
#define NO_ANALOGS 0x0F // None
#define ALL_ANALOG 0x00 // A0 A1 A2 A3 A5 E0 E1 E2 B1 B4 B0
#define AN0_TO_AN9 0x05 // A0 A1 A2 A3 A5 E0 E1 E2 B1 B4
#define AN0_TO_AN8 0x06 // A0 A1 A2 A3 A5 E0 E1 E2 B1
#define AN0_TO_AN7 0x07 // A0 A1 A2 A3 A5 E0 E1 E2
#define AN0_TO_AN6 0x08 // A0 A1 A2 A3 A5 E0 E1
#define AN0_TO_AN5 0x09 // A0 A1 A2 A3 A5 E0
#define AN0_TO_AN4 0x0A // A0 A1 A2 A3 A5
#define AN0_TO_AN3 0x0B // A0 A1 A2 A3
#define AN0_TO_AN2 0x0C // A0 A1 A2
#define AN0_TO_AN1 0x0D // A0 A1
#define AN0 0x0E // A0
#define AN0_TO_AN12_ANALOG 0x02 //!old only provided for compatibility
#define AN0_TO_AN11_ANALOG 0x03 //!old only provided for compatibility
#define AN0_TO_AN10_ANALOG 0x04 //!old only provided for compatibility
#define AN0_TO_AN9_ANALOG 0x05 //!old only provided for compatibility
#define AN0_TO_AN8_ANALOG 0x06 //!old only provided for compatibility
#define AN0_TO_AN4_ANALOG 0x0A //!old only provided for compatibility
#define AN0_TO_AN3_ANALOG 0x0B //!old only provided for compatibility
#define AN0_TO_AN2_ANALOG 0x0C //!old only provided for compatibility
#define AN0_TO_AN1_ANALOG 0x0D //!old only provided for compatibility
#define AN0_ANALOG 0x0E //!old only provided for compatibility

// The following may be OR'ed in with the above using |
#define VSS_VDD 0x00 // Range 0-Vdd
#define VREF_VREF 0x30 // Range VrefL-VrefH
#define VREF_VDD 0x20 // Range VrefL-Vdd
#define VSS_VREF 0x10 // Range 0-VrefH


Here's what is available...is there anyway to add a custom entry that would fit my needs?
rberek



Joined: 10 Jan 2005
Posts: 207
Location: Ottawa, Canada

View user's profile Send private message

PostPosted: Thu Apr 17, 2008 1:40 pm     Reply with quote

The limitation is inherent in the design of the microcontroller itself. You simply can't change that, short of designing a new device.

r.b.
mskala



Joined: 06 Mar 2007
Posts: 100
Location: Massachusetts, USA

View user's profile Send private message

PostPosted: Thu Apr 17, 2008 1:41 pm     Reply with quote

CCS provides these setups because they are what the chip is able to do. You can look in the datasheet, but at least older PICs do not have any way to set a bunch of random ones to A/D.
RageOfFury



Joined: 07 Feb 2008
Posts: 17
Location: Canada

View user's profile Send private message

PostPosted: Thu Apr 17, 2008 1:51 pm     Reply with quote

Alright then...

if I use this:

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

can I still use ports between AN5 and AN8 for let's a LCD or are they locked in ADC mode?
Ttelmah
Guest







PostPosted: Thu Apr 17, 2008 2:37 pm     Reply with quote

Look _carefully_ at the data sheet. In general you will find that if you configure them as digital outputs they will be OK. Also you need to be aware, that using them as I/O, _will_ increase noise on the other pins used for analog.
Generally, if you only use them as outputs, and only change them, when you are not performing ADC readings, they will be OK.
They will also function as digital inputs, but because data on them can then change asynchronously to the ADC operation, it can lead to noise problems.
You also ned to be very careful, _not_ to read any of the pins connected to an analog source, using the digital input buffer, or unexpected power consumption can result...
In the case of your chip, if you look at table 10-1 (and 10-3) in the data sheet, you will see that for each pin, they only function as analog pins, if the TRIS is set to 1. However it would also be much better to rethink your design, and try to move the pins to want to be used for analog onto the low pins of port A, and disable the analog multiplexer on the other pins.

Best Wishes
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