View previous topic :: View next topic |
Author |
Message |
Sal
Joined: 04 Mar 2010 Posts: 27 Location: Caribbean
|
Analog input connection for 16F876A [Help Please] |
Posted: Thu Jun 10, 2010 7:32 pm |
|
|
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: 1615 Location: Central Illinois, USA
|
|
Posted: Thu Jun 10, 2010 9:28 pm |
|
|
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
|
|
Posted: Fri Jun 11, 2010 12:19 pm |
|
|
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). |
|
|
|