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 and 18F2550

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



Joined: 30 Jan 2012
Posts: 219

View user's profile Send private message

ADC and 18F2550
PostPosted: Tue Oct 30, 2012 2:30 am     Reply with quote

Hi everybody !

I'm trying to use ADC on my 18F2550 with PCWHD 4.065.
the goal is to read ADC on pin A0, other pins A1 to A5 are used as logic output.

my code :

Code:
#include <18F2550.h>
#device adc=10
 
#fuses INTRC_IO,NOWDT,NOMCLR,NOPROTECT,NOLVP,NODEBUG,PLL1,CPUDIV1,NOBROWNOUT
#use delay(clock=8000000,restart_wdt)

#define PICKIT_UART
#define rs232_pickit2_rx PIN_B6
#define rs232_pickit2_tx PIN_B7
#use rs232(baud=9600,parity=N,xmit=rs232_pickit2_tx,rcv=rs232_pickit2_rx,bits=8,TIMEOUT=500,STREAM=rs232_pickit2)

void main()

   int16 an=0;

   setup_adc_ports(AN0|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_spi(FALSE);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
   setup_oscillator(OSC_8MHZ);
   
   while(true){
      set_adc_channel(0);
      delay_us(50);
      an = read_adc();  // 0 à 1024
      fprintf(rs232_pickit2,"AN %lu\r\n",an);
      delay_ms(500);
   }
}



but I don't understand why it does not work :
I just receive "AN 16384".
do you have any idea about my problem?

thanks for your reply

Spilz
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Tue Oct 30, 2012 2:43 am     Reply with quote

What does your code do?
What does it not do?
Can you do a LED flasher?
Are you working with real hardware and not simulation?

Mike
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Tue Oct 30, 2012 2:49 am     Reply with quote

Er.....
What do you think:

setup_adc(ADC_OFF);
Does?.....

You are turning off the clock that operates the ADC. Saves power, but it can't then work....

setup_adc(ADC_CLOCK_DIV_8);

Is correct for your chip at 8MHz.

Best Wishes
spilz



Joined: 30 Jan 2012
Posts: 219

View user's profile Send private message

PostPosted: Tue Oct 30, 2012 2:50 am     Reply with quote

Hi,
thanks for your interrest Smile

I'm using a developing board (real one), with adj resistor connect on pin_a0.
My code do more stuff like read I2C EEPROM, print on LCD modul. These parts works well.
So now I try just to read ADC, and it does not work...
I check with oscilloscop, the tension change on the pin_A0 when I turn the Adj resistor.
Any idea?

I already used ADC on 12F675, and it worked well...
spilz



Joined: 30 Jan 2012
Posts: 219

View user's profile Send private message

PostPosted: Tue Oct 30, 2012 2:58 am     Reply with quote

thank Ttelmah,

changing
Code:
setup_adc(ADC_OFF);

by
Code:
setup_adc(ADC_CLOCK_DIV_8);

seems to be the solution : it work well now Smile

so, problem solved, the solution is :

don't forget to configure ADC clock
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