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 on 18f2420...

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



Joined: 21 Dec 2011
Posts: 42

View user's profile Send private message

ADC on 18f2420...
PostPosted: Wed Jul 31, 2013 6:15 am     Reply with quote

Hi,

I can't read a correct value with the adc...My code is extremely basic, i don't understand...
Code:

#include <18F2420.H>
#device ADC=10

#FUSES INTRC_IO,MCLR,NOWDT,NOWRT,NOLVP
#use delay(internal=8000000)
#use rs232(baud=9600, xmit=PIN_c6,rcv=PIN_c7,parity=N,bits=8,stop=1)

//----------------------------------------------------------------

void main()
{
   int16 value;
   setup_oscillator(OSC_8MHZ);

   setup_adc(ADC_CLOCK_INTERNAL);
   setup_adc_ports(AN0|VSS_VDD);
      set_adc_channel(0);

   for(;;)
   {    
      value=read_adc();
      printf("Value : %lu\n\r",value);
      delay_ms(500);
   }
}   
//----------------------------------------------------------------



If someone see a big mistake... thanks in advance
CCS version 4.130
temtronic



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

View user's profile Send private message

PostPosted: Wed Jul 31, 2013 6:36 am     Reply with quote

here's one...

setup_adc(ADC_CLOCK_INTERNAL);


...
According to typical ADC setup specs in datasheets, 'internal' is NOT recommended any speed over 1MHZ(unless in sleep mode).
Fine the ADC section of your PIC and there should be a chart with 'adc clock vs PIC speed'.some will be highlighted meaning 'do not use'.


hth
jay
joseph20480



Joined: 21 Dec 2011
Posts: 42

View user's profile Send private message

PostPosted: Wed Jul 31, 2013 6:59 am     Reply with quote

Hi,

You have right ! (Page 229)
I have replace
Code:

setup_adc(ADC_CLOCK_INTERNAL);


by

Code:

setup_adc(ADC_CLOCK_DIV_16);


But not better...
temtronic



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

View user's profile Send private message

PostPosted: Wed Jul 31, 2013 9:13 am     Reply with quote

What's the ADC connected to ?

A basic test would be a simple voltage divider from Vss to Vdd, with a small 'filter' cap (say 1mfd), maybe giving say 2 volts input (measure with DVM).
'play' computer, do the math to see if the ADC reading is correct.

Also test at zero volts and Vss ( +5 ?).

You should read a fairly stable reading ( +-2-3 bits).

hth
jay
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