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

Easy ADC question, pic16f684

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








Easy ADC question, pic16f684
PostPosted: Wed Dec 16, 2009 6:39 pm     Reply with quote

I'm just wondering if my PIC will automatically set my selected ADC pins as ANALOG. The device file says the following:

Code:
// Constants used in SETUP_ADC_PORTS() are:
#define sAN0                   1         //| A0
#define sAN1                   2         //| A1
#define sAN2                   4         //| A2
#define sAN3                   8         //| A4
#define sAN4                  16         //| C0
#define sAN5                  32         //| C1
#define sAN6                  64         //| C2
#define sAN7                  128        //| C3
#define NO_ANALOGS             0         // None
#define ALL_ANALOG            255        // A0 A1 A2 A4 C0 C1 C2 C3


My code snippet is:
Code:

      setup_adc(ADC_CLOCK_INTERNAL);
      setup_adc_ports(sAN0 | sAN1 | sAN2 | sAN4 | sAN5 | sAN6 | VSS_VDD);
     
      set_adc_channel(2);
      delay_us(20);
      adc=read_adc();
      LPOT=128+adc;


I want all of my chosen adc ports to be analog instead of digital. My question is whether or not my pic will automatically set them as analog inputs? If I add "ALL_ANALOG" to the "setup_adc" line, will it set my chosen pins as ANALOG, or every adc pin on the entire pic, whether or not I choose them?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Dec 16, 2009 7:27 pm     Reply with quote

Quote:
I want all of my chosen adc ports to be analog instead of digital

Yes, you are selecting pins to be configured as analog, when you
call that function.


Quote:

If I add "ALL_ANALOG" to the "setup_adc" line, will it set my chosen pins
as ANALOG, or every adc pin on the entire pic, whether or not I choose
them?

All pins on the chip that can be analog will be made analog.
Guest








PostPosted: Wed Dec 16, 2009 7:33 pm     Reply with quote

Thanks for the prompt response PCM, I didn't want to power my pic on with 3v going into each analog pin until I was sure, I've fried chips before because of this kind of thing.

Cheers!
Guest








PostPosted: Thu Dec 17, 2009 12:18 pm     Reply with quote

I have another question reguarding the PIC16F684. I've programmed pins C3,C4,C5,A3,A4,A5 as blinking LED outputs, but I get strange results from A3 and A4. All of the other pins work perfectly. Pin A3 gives me a constant dim LED, and A4 gives me a constant BRIGHT LED. Pin A3 is also MCLR, but I've fused MCLR in my code.

Is there something I could be missing or forgetting to do? I can post the code if requested.

Thanks!
mkuang



Joined: 14 Dec 2007
Posts: 257

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

PostPosted: Thu Dec 17, 2009 1:12 pm     Reply with quote

Anonymous wrote:
I have another question reguarding the PIC16F684. I've programmed pins C3,C4,C5,A3,A4,A5 as blinking LED outputs, but I get strange results from A3 and A4. All of the other pins work perfectly. Pin A3 gives me a constant dim LED, and A4 gives me a constant BRIGHT LED. Pin A3 is also MCLR, but I've fused MCLR in my code.

Is there something I could be missing or forgetting to do? I can post the code if requested.

Thanks!

I don't have the datasheet for the 684 downloaded but you have to make sure that A3 and A4 are not open-collector outputs in which case you need a pullup resistor to Vdd to make it work.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Dec 17, 2009 1:19 pm     Reply with quote

Look in the Device Overview section of the 16F684 data sheet.
Look at this table:
Quote:
TABLE 1-1: PIC16F684 PINOUT DESCRIPTION

It lists the restrictions on the pins.
http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010214

Some pins may not be i/o. They may be listed as input only.

Other pins may have a dual use that is defined by a fuse setting.
For example, to use oscillator pins as i/o when using the internal
oscillator, you must use the INTRC_IO fuse instead of just INTRC.
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