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

18F6720 ADC configuration problem

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



Joined: 15 Sep 2003
Posts: 75

View user's profile Send private message

18F6720 ADC configuration problem
PostPosted: Thu Feb 03, 2005 5:21 am     Reply with quote

Hi,

I am using the 18F6720 and PCWH. I would like to use the built-in ADC. However, I would like to use some pins as analog inputs and some for digital I/O’s.

Can I configure the following?
AN0 to AN2, and AN5 as analog inputs,
AN3, AN6 as digital outputs,
AN7 as digital input.

If so, what constants do I need to put into SETUP_ADC_PORTS() to make AN0 to AN2, and AN5 as analog inputs? Also, how can I configure the other AN ports as digital I/O' ports?

The following is an extract from the 18F6720.h file and it does not appear to have sufficient constants to configure the above analog inputs.

Code:
////////////////////////////////////////////////////////////////// ADC
// ADC Functions: SETUP_ADC(), SETUP_ADC_PORTS() (aka SETUP_PORT_A),
//                SET_ADC_CHANNEL(), READ_ADC()
// Constants used in SETUP_ADC_PORTS() are:
#define NO_ANALOGS             0x0F         // None
#define ALL_ANALOG             0x00         // A0 A1 A2 A3 A5 F0 F1 F2 F3 F4 F5 F6
#define ANALOG_AN0_TO_AN10     0x04         // A0 A1 A2 A3 A5 F0 F1 F2 F3 F4 F5
#define ANALOG_AN0_TO_AN9      0x05         // A0 A1 A2 A3 A5 F0 F1 F2 F3 F4
#define ANALOG_AN0_TO_AN8      0x06         // A0 A1 A2 A3 A5 F0 F1 F2 F3
#define ANALOG_AN0_TO_AN7      0x07         // A0 A1 A2 A3 A5 F0 F1 F2
#define ANALOG_AN0_TO_AN6      0x08         // A0 A1 A2 A3 A5 F0 F1
#define ANALOG_AN0_TO_AN5      0x09         // A0 A1 A2 A3 A5 F0
#define ANALOG_AN0_TO_AN4      0x0A         // A0 A1 A2 A3 A5
#define ANALOG_AN0_TO_AN3      0x0B         // A0 A1 A2 A3
#define ANALOG_AN0_TO_AN2      0x0C         // A0 A1 A2
#define ANALOG_AN0_TO_AN1      0x0D         // A0 A1
#define ANALOG_AN0             0x0E         // A0
// 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


Please help.
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Thu Feb 03, 2005 8:52 am     Reply with quote

Check the data sheet for the part. You will see the #def's match the table in the data sheet.

The short answer is you can't do exactly what you want to do. You can however set AN0 to AN5 as ADC inputs. and make AN7 a digital input and AN6 a digital output.

As to AN3, I'm a little fuzzy. I think it is OK for it to be a digital input if it is in the middle of an ADC channel range but I'm not so sure about it being a digital output.

One thing to do would be to write some code and single step it through the Microchip simulator in MPLAB and keep an eye on the port bits and their registers. Or just write some code and try it on your hardware...
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
TL



Joined: 15 Sep 2003
Posts: 75

View user's profile Send private message

PostPosted: Thu Feb 03, 2005 9:44 am     Reply with quote

Many thanks for pointing me in the right direction. Yes, I’ve checked the datasheet and it will not do what I want. You can allow to have analog inputs and digital I/O’s (inputs and outputs) on port AN but they must be configured as per datasheet. Yes, I’ll try to group them and go from there.

Thanks
Tom
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