View previous topic :: View next topic |
Author |
Message |
caddy
Joined: 24 Jun 2007 Posts: 14
|
ADC port contradictions |
Posted: Sun Jun 24, 2007 12:54 am |
|
|
Hi
I'm using an 18F2525 with 12 ADC ports. In the datasheet it says:
Code: |
"each port pin associated with the A/D converter can be configured as an analog input, or as a digital I/O."
|
However, in the devices file packaged with CCS, it says:
Code: |
// Constants used in SETUP_ADC_PORTS() are:
#define NO_ANALOGS 0x0F // None
#define AN0_TO_AN6 0x08 // A0 A1 A2 A3 A5 F0 F1
#define AN0_TO_AN5 0x09 // A0 A1 A2 A3 A5 F0
#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
|
I'm trying to figure out how I can enable ports AN8 and AN9 while keeping the rest as digital, but there is no option for this with setup_adc_ports. Could someone help me out? Also, what are F0 and F1?
Thanks |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
|
Posted: Sun Jun 24, 2007 7:51 am |
|
|
You might read the data sheet again. The 18F2525 is a 28 pin device and has 10 ADC channels. (AN5-AN7 are not available)
Page 224 of the data sheet shows all the possible Analog port configurations. The datasheet does not show an option to configure just AN8 and AN9. The compiler is limited by what the hardware will do.
Also, which CCS version are you using? The ADC definitions in my header file (ver 4.042) differ greatly from yours. (don't get confused between A5 and AN5, one is a pin and the other is the ADC port)
// Constants used in SETUP_ADC_PORTS() are:
#define NO_ANALOGS 0x0F // None
#define ALL_ANALOG 0x00 // A0 A1 A2 A3 A5 B2 B3 B1 B4 B0
#define AN0_TO_AN11 0x03 // A0 A1 A2 A3 A5 B2 B3 B1 B4
#define AN0_TO_AN10 0x04 // A0 A1 A2 A3 A5 B2 B3 B1
#define AN0_TO_AN9 0x05 // A0 A1 A2 A3 A5 B2 B3
#define AN0_TO_AN8 0x06 // A0 A1 A2 A3 A5 B2
#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 |
|
|
Guest
|
|
Posted: Sun Jun 24, 2007 3:28 pm |
|
|
Thanks
What if I se up all ports as analog just before using the adc, and then set them back to digital when using the digital ports. As long as I leave a delay between the setup and conversion to allow it to initialise there shouldnt be a problem right?? |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
|
Posted: Sun Jun 24, 2007 4:27 pm |
|
|
Thats a good question someone here might be able to answer. I have never tried that trick. I have always just used the ports I needed starting from AN0 in the normal configurations....
After doing some more investigation it appears some unused Analog pins can be configured as digital OUTPUT only (ex: RA0 and RA1). The D/S says they cannot be configured for digital input when Analog is enabled. Again, I have never tried this. I am getting this from reading the data sheet. |
|
|
caddy
Joined: 24 Jun 2007 Posts: 14
|
|
Posted: Sun Jun 24, 2007 4:50 pm |
|
|
Well, they wouldn't need to be analog and digital simultaneously. The code I'm thinking of would be something like:
Code: |
setup_adc_ports(ALL_ANALOG);
delay_ms(X); //allow the ADC to settle
do conversions on AN8 and AN9
setup_adc_ports(NO_ANALOGS);
check digital inputs on the other pins
setup_adc_ports(ALL_ANALOG);
delay_ms(X); //allow the ADC to settle
do conversions on AN8 and AN9
|
Would this work? |
|
|
jfk1965
Joined: 21 Oct 2003 Posts: 58
|
|
Posted: Mon Jun 25, 2007 3:18 am |
|
|
why not just use A0 & A1 as Analog as the others as digital and you don't have to switch from analog to digital and back again? |
|
|
caddy
Joined: 24 Jun 2007 Posts: 14
|
|
Posted: Mon Jun 25, 2007 6:19 am |
|
|
jfk1965 wrote: | why not just use A0 & A1 as Analog as the others as digital and you don't have to switch from analog to digital and back again? |
The problem is I am using a PCB that has already been implemented by someone else so I need to use this odd set of analog ports...
So I'm wondering if the pseudocode I posted just a bit up would work?
Thanks |
|
|
|