View previous topic :: View next topic |
Author |
Message |
seidleroni
Joined: 08 Sep 2008 Posts: 21
|
A/D (ADC) Question... |
Posted: Mon May 04, 2009 12:09 pm |
|
|
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:
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
|
|
Posted: Mon May 04, 2009 12:40 pm |
|
|
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
|
|
Posted: Mon May 04, 2009 12:47 pm |
|
|
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
|
|
Posted: Mon May 04, 2009 12:52 pm |
|
|
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
|
|
Posted: Mon May 04, 2009 8:07 pm |
|
|
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. |
|
|
|