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

ADC and INPUT pin

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



Joined: 20 Nov 2008
Posts: 79
Location: white Plains, NY

View user's profile Send private message Yahoo Messenger

ADC and INPUT pin
PostPosted: Sat Jan 03, 2009 9:35 pm     Reply with quote

I'm new at this and I'm having a problem trying to make work the input pin and the ADC at the same time. Any idea why it is not working ? Here is the code. Thank you.
Code:
void main()
{
int pot_board;

  Set_Tris_A(0b111111);    //sets up port A as an input port


setup_adc( ADC_CLOCK_INTERNAL );         //sets up the adc
setup_adc_ports( ALL_ANALOG );

   while(true) {

   set_adc_channel(0);            // data from port A0 ( pot from board )
   delay_us(50);
   pot_board=read_adc();

printf("%2x", pot_board);

//controls the h-bridge
output_d(0xf6);
while(Input(PIN_B3))output_d(0xf3);
while(Input(PIN_B2))output_d(0xfc);
}
}
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Sat Jan 03, 2009 9:51 pm     Reply with quote

Please tell us which PIC you are using and what compiler version.
You should not need the Set_Tris statement unless you are doing something exotic with the ports. The compiler usually handles the TRIS registers fine itself.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Guest








PostPosted: Sat Jan 03, 2009 9:53 pm     Reply with quote

SherpaDoug wrote:
Please tell us which PIC you are using and what compiler version.
You should not need the Set_Tris statement unless you are doing something exotic with the ports. The compiler usually handles the TRIS registers fine itself.


I'm using the PICkit 2 the came with the MPlab IDE v8.10
and the pic16f887 debug board
IceMetal



Joined: 20 Nov 2008
Posts: 79
Location: white Plains, NY

View user's profile Send private message Yahoo Messenger

PostPosted: Sat Jan 03, 2009 9:55 pm     Reply with quote

Anonymous wrote:
SherpaDoug wrote:
Please tell us which PIC you are using and what compiler version.
You should not need the Set_Tris statement unless you are doing something exotic with the ports. The compiler usually handles the TRIS registers fine itself.


I'm using the PICkit 2 the came with the MPlab IDE v8.10
and the pic16f887 debug board

I forgot to say it is the CCS compiler

thanx
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jan 04, 2009 1:03 pm     Reply with quote

If you use CCS i/o functions (which you are doing), you don't need to
set the TRIS. The compiler will do it for you.

You are reading two pins on Port B. What do you have connected to
these two pins ? Describe the circuit. If it's a chip, post the
manufacturer and part number.
Guest








PostPosted: Sun Jan 04, 2009 1:14 pm     Reply with quote

PCM programmer wrote:
If you use CCS i/o functions (which you are doing), you don't need to
set the TRIS. The compiler will do it for you.

You are reading two pins on Port B. What do you have connected to
these two pins ? Describe the circuit. If it's a chip, post the
manufacturer and part number.


I'm using an LM339, that is connected to a couple of infrared sharp GP2d12 but it works fine if I ignore the ADC code and the ADC code works fine also if I ignore the input pins but they dont want to work together :(
any ideas? thanx
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jan 04, 2009 1:51 pm     Reply with quote

Quote:
void main()
{
int pot_board;

Set_Tris_A(0b111111); //sets up port A as an input port

setup_adc( ADC_CLOCK_INTERNAL ); //sets up the adc
setup_adc_ports( ALL_ANALOG );

The 16F887 data sheet shows that this PIC has analog pins on Port B
and on Port A. You have picked "All analog", which makes all "ANx"
pins be analog pins. That's why you have problems with digital input
on port B. Look in the 16F887.h file to find the constant which will enable
only AN0 as an analog pin and leave the rest of them as digital.
Look in this section:
Quote:
// Constants used in SETUP_ADC_PORTS() are:

Here's the file location:
Quote:
c:\program files\picc\devices\16f887.h
IceMetal



Joined: 20 Nov 2008
Posts: 79
Location: white Plains, NY

View user's profile Send private message Yahoo Messenger

PostPosted: Mon Jan 05, 2009 8:42 am     Reply with quote

Thank you so much PCM programmer. that works, can't belive it was thats simple, Cool
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