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

18F2525 ADC problem

 
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: Mon Jun 07, 2010 11:21 am     Reply with quote

Try a more simple program that will display ADC values from 0 to 1023
based on the input voltage. Also, make sure you have a ground
connection between the device that supplies the ADC input voltage and
the PIC board's ground. You can't just have the input signal wire to
pin A0. There must also be a ground wire between the two devices,
connected to the ground on each device (or board).
Code:

#include <18F2525.h>
#device adc=10
#fuses INTRC_IO, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#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_4);
set_adc_channel(0);
delay_us(20);

while(1)
  {
   adc_value = read_adc();
   printf("%lu", adc_value);
   delay_ms(500);
  }
}
peterl



Joined: 09 Oct 2009
Posts: 13
Location: SF,BG

View user's profile Send private message

re: PIC18F2525 ADC
PostPosted: Tue Jun 08, 2010 1:12 am     Reply with quote

The problem was here:
set_adc_channel(AN0); is not correct, correct is set_adc_channel(0);
10X Very Happy
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