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

jumpy adc value

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



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jan 24, 2010 1:32 pm     Reply with quote

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







PostPosted: Sun Jan 24, 2010 7:50 pm     Reply with quote

i need serial cable to connect the pic to pc right?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jan 24, 2010 8:13 pm     Reply with quote

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








PostPosted: Sun Jan 24, 2010 9:30 pm     Reply with quote

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







PostPosted: Mon Jan 25, 2010 1:05 am     Reply with quote

Anonymous wrote:
Does your input pin require a pullup resistor? Does your input source require a buffering capacitor?


how do i know this?
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