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 support@ccsinfo.com

A/D (ADC) Question...

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



Joined: 08 Sep 2008
Posts: 21

View user's profile Send private message

A/D (ADC) Question...
PostPosted: Mon May 04, 2009 12:09 pm     Reply with quote

When I set up my ADC, I just do this:

Code:
   setup_adc_ports( AN0_TO_AN4 | VSS_VREF );
   setup_adc(ADC_CLOCK_DIV_32);
   set_adc_channel(0);


My first question is: For the "setup_adc(...)", should I be including a statement to include a delay like "ADC_TAD_MUL_4"? What does the time select bits do? Is it necessary for an accurate read? I haven't found much info (even in PIC datasheet) about what to use for it.

Also, if I use code like:
Code:
value=read_adc()

Do I need to use delay_us(...) in between ADC reads to get accurate measurements or is that done automatically in in the "read_adc()" function from CCS?
Gerhard



Joined: 30 Aug 2007
Posts: 144
Location: South Africa

View user's profile Send private message Send e-mail

PostPosted: Mon May 04, 2009 12:40 pm     Reply with quote

Yes you have to allow the cap of the adc conversion to charge and this data is given in the data sheet depending on the type of pic and speed at which you are converting a/d. I do not know which pic you are using but I always allow a minimum delay time of 20us.

Regarding your first question I have always done it the way you do it without problems even when sending 2 sound waves between two pics that is aquired from adc sampling. So i would not mess too much with the time select bits unless it is for further understanding which I hope one of the experts would be able to clear up
seidleroni



Joined: 08 Sep 2008
Posts: 21

View user's profile Send private message

PostPosted: Mon May 04, 2009 12:47 pm     Reply with quote

Yes, but do I have to do that delay manually? I would have thought thats done automatically in the read_adc() function (as long as its returning a paremeter).

Also, what should the TAD value be set to?
Gerhard



Joined: 30 Aug 2007
Posts: 144
Location: South Africa

View user's profile Send private message Send e-mail

PostPosted: Mon May 04, 2009 12:52 pm     Reply with quote

Firstly as I have stated it depends on what pic you are using and what your sample rate is.

You have to set that manually with a statement such as
Code:
set_adc_channel(0);
delay_us(20);
ch0=read_adc();


You basically tell the pic in step one to go to chan 0 then wait 20us for cap to charge then read the adc value. This is not done auto by the pic.

What pic, oscilater and conversion rate are you using?
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Mon May 04, 2009 8:07 pm     Reply with quote

If you are going to keep the A/D connected to channel 0 all the time you don't need the 20us cap charging time before each conversion. That is just when you switch the mux between differing voltage levels, or you switch the analog signal source on and off.

As long as you meet the source impedance and Nyquist sampling criteria you can just loop on the read_adc() function as the A/D will track changes in the analog input as they occur.
_________________
The search for better is endless. Instead simply find very good and get the job done.
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