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

ADC timing

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



Joined: 09 Nov 2007
Posts: 12

View user's profile Send private message

ADC timing
PostPosted: Sun Dec 16, 2007 5:47 pm     Reply with quote

Hi,

I am beginner in programming pic and got a question with the ADC.
How can I read an analog value
everey 0.0001s into the A/D?

Is it sufficient to write:

Code:

while(1)
{
set_adc_channel(0);
delay_ms(0.1);               
value=read_adc(); 
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Dec 16, 2007 5:54 pm     Reply with quote

Quote:
delay_ms(0.1);

You can't use a float for the parameter. Download the CCS manual:
http://www.ccsinfo.com/downloads/CReferenceManual.pdf
Look in the section on delay_ms(). It says this:
Quote:
Syntax: delay_ms (time)
Parameters: time - a variable 0-65535(int16) or a constant 0-65535


Look at the other CCS delay functions in the manual, if you want
to delay for a period of less than 1 ms.
Sebastian20000



Joined: 09 Nov 2007
Posts: 12

View user's profile Send private message

PostPosted: Mon Dec 17, 2007 12:54 pm     Reply with quote

yes you´re right. But in general the sampling would function
like this?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 17, 2007 1:10 pm     Reply with quote

The loop time won't be exactly 100 us, because it takes time to
do the A/D conversion, and also to execute the while() loop.

You could adjust the delay_us() value to make the loop time be
fairly close to 100 us.

However, if you have interrupts running, some of the loop times
will be longer than 100 us, because the PIC must go process the
interrupt.
frequentguest
Guest







PostPosted: Mon Dec 17, 2007 2:03 pm     Reply with quote

You also only have to set the ADC channel once before the loop. No need to call set_adc_channel() every time through the loop, assuming you are using the same channel every time.
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Mon Dec 17, 2007 2:41 pm     Reply with quote

The only reason you need a delay is in case you change inputs. This gives the internal capacitor time to charge to the currently selected pin's voltage level.

Ronald
Ttelmah
Guest







PostPosted: Mon Dec 17, 2007 4:48 pm     Reply with quote

Not quite true.
The internal capacitor, is disconnected from the outside world, when you take the reading. It needs the same time between successive readings (to allow it to charge to the external voltage), as when a channel is selected. If doing really fast successive readings, this must be taken into account.

Best Wishes
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Tue Dec 18, 2007 9:00 am     Reply with quote

I agree with ttelmah
Quote:
TACQ = Amplifier Settling Time + Holding Capacitor Charging Time + Temperature Coefficient
= TAMP + TC + TCOFF

This is for every sample. It says nothing about changing channels.
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