View previous topic :: View next topic |
Author |
Message |
Sebastian20000
Joined: 09 Nov 2007 Posts: 12
|
ADC timing |
Posted: Sun Dec 16, 2007 5:47 pm |
|
|
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
|
|
Posted: Sun Dec 16, 2007 5:54 pm |
|
|
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
|
|
Posted: Mon Dec 17, 2007 12:54 pm |
|
|
yes you´re right. But in general the sampling would function
like this? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Dec 17, 2007 1:10 pm |
|
|
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
|
|
Posted: Mon Dec 17, 2007 2:03 pm |
|
|
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
|
|
Posted: Mon Dec 17, 2007 2:41 pm |
|
|
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
|
|
Posted: Mon Dec 17, 2007 4:48 pm |
|
|
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
|
|
Posted: Tue Dec 18, 2007 9:00 am |
|
|
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. |
|
|
|