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

Delay when using the ADC

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



Joined: 07 May 2004
Posts: 263

View user's profile Send private message

Delay when using the ADC
PostPosted: Tue Nov 24, 2009 10:51 am     Reply with quote

I'm using a pic18f2221.
I'm declaring the ADC like this
Code:

setup_adc_ports(AN0_TO_AN9_ANALOG);
setup_adc( ADC_CLOCK_DIV_16 );

A long time ago I discovered you must delay between switching ADC channels and reading the ADC like this.
Code:

set_adc_channel(9);
delay_ms(1);
ADC_Return_Value = Read_ADC();

I picked 1ms and it worked ok and I've stuck with it ever since. My question is if this is still necessary, and if so how do I know how long to wait. I see the equations in the Pic Datasheet but it uses things like "Charge Holding Cap" value, source impedance, etc. I'm not sure exactly which of these variables are related to the structure of the pic and what are related to the external circuit I'm trying to measure (a photo-transistor). In the example they come up with 2.4us, would it be safe to assume that if I use a value of 10X that then I should be covered, or is there a standard value that everyone uses?
Also, does the setup_adc( ADC_CLOCK_DIV_16 ) statement affect the delay time at all?



Thanks
Ringo
_________________
Ringo Davis
Ttelmah
Guest







PostPosted: Tue Nov 24, 2009 11:25 am     Reply with quote

Read the chip's data sheet.
Section 19.1
No, it is not affected by the clock rate of the ADC. It depends purely on the time needed to charge the internal capacitor in the ADC, to the external voltage through the resistance of the internal multiplexor, and gate.
It also depends on how close you need the voltage to get (you can use a shorter time if you only want 8bit accuracy).
In your case, if your source meets the specified impedance (<2.5KR), then you need just 2.4uSec.
On this chip, you can program the chip to automatically allow this time for you, using the ADC_TAD_MUL_ settings. Again read the data sheet. These allow you to program the chip to automatically wait for a number of cycles of the selected ADC clock, before starting the conversion.

Best Wishes
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