View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jan 24, 2010 1:32 pm |
|
|
Connect the center tap of a 5K trimpot to pin A0 on your PIC and try
a simple program like this one. The top pin of the trimpot should go to
+5v and the bottom pin to Ground.
Code: |
#include <16F877A.H>
#device adc=10
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
//============================
void main()
{
int16 adc_value;
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_DIV_32);
set_adc_channel(0);
delay_us(20);
while(1)
{
adc_value = read_adc();
printf("%lu \n\r", adc_value);
delay_ms(500);
}
}
|
This program will display the A/D result on a serial terminal window
on your PC. |
|
|
max23 Guest
|
|
Posted: Sun Jan 24, 2010 7:50 pm |
|
|
i need serial cable to connect the pic to pc right? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jan 24, 2010 8:13 pm |
|
|
Yes, and your board must have an RS232 interface chip, such as a
MAX232, etc. Also, your PC must have a COM port connector on the back. |
|
|
Guest
|
|
Posted: Sun Jan 24, 2010 9:30 pm |
|
|
What is your input source? Does your input pin require a pullup resistor? Does your input source require a buffering capacitor? If your voltage source is jumpy, that would be the first thing to fix. If you're using a DC power supply, try replacing it with either batteries, or a different power supply. Your ADC is constantly figuring the difference between ground (0V) and VREF (+V). If your voltage source, or VREF are jumpy, your result will also be. |
|
|
max23 Guest
|
|
Posted: Mon Jan 25, 2010 1:05 am |
|
|
Anonymous wrote: | Does your input pin require a pullup resistor? Does your input source require a buffering capacitor? |
how do i know this? |
|
|
|