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

Analog input connection for 16F876A [Help Please]

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



Joined: 04 Mar 2010
Posts: 27
Location: Caribbean

View user's profile Send private message

Analog input connection for 16F876A [Help Please]
PostPosted: Thu Jun 10, 2010 7:32 pm     Reply with quote

Hi,

I'm using a 16F876A and I'm just trying to read an analog value from AN0.
I used this setup code
Code:

setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_INTERNAL );
set_adc_channel(0);

I just wanted to know where exactly to connect the variable resistor. It's a three wire potentiometer.

I tried one side to the 5V supply, the other side to ground and the slider to AN0 but no result seen...
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Thu Jun 10, 2010 9:28 pm     Reply with quote

you need to post your full code -- include the compiler version.

If you have a schematic (or intended schematic), that's good too.

What you have there can't be all that you're running -- so now that we know you have more code than that, we need to see it.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jun 11, 2010 12:19 pm     Reply with quote

Use this test program. Change the #include line for the PIC to 16F876A.h:
http://www.ccsinfo.com/forum/viewtopic.php?t=32168&start=1


Look at the schematic on page 25 of the PicDem2-Plus board:
http://ww1.microchip.com/downloads/en/DeviceDoc/51275d.pdf
On the left side, you'll see a circuit of a trimpot (R16) going through
a series resistor (R2), to pin A0 of the PIC. That's how you want to
connect it.

You don't strictly need the series resistor (R2), but it's there for safety
reasons. If you accidently configured pin A0 as a digital output pin, and
the trimpot was set to +5v and pin A0 was set to a low level, then high
current would flow and it could burn up the PIC pin. Also, if you set
pin A0 as a digital input pin, and turned the trimpot to mid-range, then
high current could also flow and maybe damage the PIC pin. So maybe
it's a good idea for you to put in R2 (470 ohms).
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