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

ADC is not working in PIC18F2431

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



Joined: 05 Dec 2009
Posts: 40

View user's profile Send private message

ADC is not working in PIC18F2431
PostPosted: Sat Sep 03, 2011 8:43 am     Reply with quote

hey guy ADC is not working in PIC18F2431 plzz help me

Code:

#include<18F2431.h>
#device adc=10

#fuses NOWDT, NOPROTECT, NOBROWNOUT, PUT, NOLVP
#use delay(clock=20MHz , crystal)

#define LED PIN_B7
unsigned int16 adc(void);
unsigned int16 adc_value;
 
void main()
{
 set_tris_a (0xFF);
 set_tris_b (0x00);
 
 setup_adc(ADC_CLOCK_INTERNAL);
 setup_adc_ports(sAN0);

while(TRUE)
 {
  set_adc_channel(0);   
  delay_us(20);
  adc_value = adc();
  if(adc_value > 512)
   output_high(LED);
  else
   output_low(LED);
  delay_ms(100);
 }
}

unsigned int16 adc()
 {
  read_adc(ADC_START_ONLY);
  while(!adc_done());
  return read_adc(ADC_READ_ONLY);
 }
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Sep 03, 2011 1:12 pm     Reply with quote

Try a simple program that just calls read_adc(), instead of breaking it up
into several calls to minor adc functions. Here is an example:
http://www.ccsinfo.com/forum/viewtopic.php?t=42952&start=1

Also post your compiler version.
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Sun Sep 04, 2011 8:18 am     Reply with quote

Also, have you verified that the rest of the circuit is working. A simple one second delay, light the LED, one second delay, turn off the LED, and loop?. Things that could stop the code from apparently working include:
1) LED without a current limiting resistor - chip resets each time it is turned on, result it apparently doesn't work.
2) No pullup on MCLR.
3) Oscillator not actually working.
etc. etc..

Best Wishes
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Sep 04, 2011 10:25 am     Reply with quote

Also is this a REAL circuit and NOT a Proteus 'simulation'?

Show the schematic of the real layout might help as well.
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