Arduino ADC clock with delay

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
samerhameed
 
Posts: 18
Joined: Wed Aug 21, 2013 7:17 am

Arduino ADC clock with delay

Post by samerhameed »

Hi,
I want to confirm one issue, if we have Arduino ADC clock (200KHz) then one clock period is (1/200000)=5 microsecond ??
then the conversion time will be 13*5=65 microsecond ??

if I use the below code

void loop ()
{

Sample=analogread(0);
delay(1);
}

That's mean i have read each 1.065 milisecond instead of each 65 microsecond ?? and finally i will get ~1KHz sample/second instead of ~15KHz sample /second .

Thanks

User avatar
adafruit_support_bill
 
Posts: 88088
Joined: Sat Feb 07, 2009 10:11 am

Re: Arduino ADC clock with delay

Post by adafruit_support_bill »

That's mean i have read each 1.065 milisecond instead of each 65 microsecond ??
The read is not synchronous with the conversion cycle, so that assumption is false. However, there is some overhead in the analogRead function, so you are correct in that the read-time is non-zero.
and finally i will get ~1KHz sample/second instead of ~15KHz sample /second .
If you have a 1 ms delay, your sample interval must be > 1 ms so your sample rate will be < 1KHz. If you want a more precise sample rate, you should use timers and perform the analogRead in the timer interrupt service routine. Here is a good tutorial on using timers. http://letsmakerobots.com/node/28278

samerhameed
 
Posts: 18
Joined: Wed Aug 21, 2013 7:17 am

Re: Arduino ADC clock with delay

Post by samerhameed »

I think i wasn't clear in my previous post, what i meant was when the read command executed it needs 65 microsecond conversion time, then the loop will start again after a very small duration to read another sample and convert it, but when i use delay the duration between each read will increase ,finally i will get less number of samples and that's what i want. in other words the ADC will read data each 1milisecond .

User avatar
adafruit_support_bill
 
Posts: 88088
Joined: Sat Feb 07, 2009 10:11 am

Re: Arduino ADC clock with delay

Post by adafruit_support_bill »

when the read command executed it needs 65 microsecond conversion time
The ADC on the Arduino is configured for continuous conversions and the read time is not synchronous to the conversion. The Arduino analogRead function takes about 100 microseconds. http://arduino.cc/en/Reference/analogRead
when i use delay the duration between each read will increase ,finally i will get less number of samples and that's what i want. in other words the ADC will read data each 1milisecond .
Those two statements are contradictory. If you add the 1 ms delay to the analogRead time, the analogRead interval will be > 1 millisecond.

samerhameed
 
Posts: 18
Joined: Wed Aug 21, 2013 7:17 am

Re: Arduino ADC clock with delay

Post by samerhameed »

Sir i have input signal with 150 Hz, and the Fs should be >=300Hz, but the less sampling ratio for the ADC is 62500/13=4800 sample/second

usually the ADC read input signal and then convert it, so we will pass through two steps
1- read input signal
2- convert input
read data is not sync with ADC conversion,but each input read needs 65 micsecond to be converted, what i want to do is decrements the input read by increasing reading interval so we will have less than 1K input read/second .

void loop ()
{
Sample=analogread(0);
delay(1);
}

User avatar
adafruit_support_bill
 
Posts: 88088
Joined: Sat Feb 07, 2009 10:11 am

Re: Arduino ADC clock with delay

Post by adafruit_support_bill »

so we will have less than 1K input read/second
Yes, that code should give you a sample rate of about 909Hz.

samerhameed
 
Posts: 18
Joined: Wed Aug 21, 2013 7:17 am

Re: Arduino ADC clock with delay

Post by samerhameed »

Thank you sir, that's what i was looking for

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”