Go Down

Topic: increase sample time artduino uno analog (Read 149 times) previous topic - next topic

georgekasa

greetings
i have a merely question about the  arduino uno . My purpose is to have one sound sensor connected to the arduino  and get 100k samples /sec  (because the song has Fs = 44100 hz and i want the double and a little more so 100k is fine) samples per second . Data will be stored in matlab  and play it after it's completed.Could you tell me what should i  change from my code? 

thank you in advance

code
void setup()
{
Serial.begin( 9600 );
}

void loop ()
{
int sensor = analogRead(A0);
Serial.println( sensor);
}

DrAzzy

#1
Jun 21, 2015, 08:56 pm Last Edit: Jun 21, 2015, 09:05 pm by DrAzzy
Per datasheet, the '328 can do 15 k samples per second at max resolution- I think 75 at lower resolution.

If you need 100k samples per second, you must use a uC that can sample as process data that fast, or an external adc that can, and a uC fast enough (depends on how much processing you need - on a16 mhz avr, that's only 160 clock cycles per sample)
ATtiny core for 841+1634+828  http://goo.gl/6fRf8e
ATtiny core for x4/x5/x61/x7/x8 series http://goo.gl/O5Wtyu
ATtiny 841/1634/828/88/861/167 breakouts, mosfets, touch sensors and prototyping board in my store http://goo.gl/xyUN2v

georgekasa

good you explain me how i can get 15k samples per second .

thank you in advance

DrAzzy

Well, for starters, don't try to send 2 bytes down the serial line 15000 times per second when the serial line is 9600 baud and can thus only handle 1200 bytes per second. I think serial print stats blocking when the buffer fills up

You may need to fiddle with registers instead of using analog read to get the full speed, all the "easy mode" functions are inefficient.
ATtiny core for 841+1634+828  http://goo.gl/6fRf8e
ATtiny core for x4/x5/x61/x7/x8 series http://goo.gl/O5Wtyu
ATtiny 841/1634/828/88/861/167 breakouts, mosfets, touch sensors and prototyping board in my store http://goo.gl/xyUN2v

Paul__B

For this job, you use a PC.

Nick Gammon

Code: [Select]
Serial.begin( 9600 );

If you are planning to send 3-digit numbers plus carriage-return and linefeed you will be able to send 960/5 samples per second (192). That is a lot less than 100000 samples. Regardless of the ADC sensor, this is your main bottleneck.

Since you need to sample at twice the frequency of the music, you could therefore handle 96 Hz music. You might be able to sample mains hum but not much else.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Paul__B

You might be able to sample mains hum but not much else.
:smiley-lol:           :smiley-lol:           :smiley-lol:           :smiley-lol:           :smiley-lol:
As I said, it is quite simple - this is a job for a computer, not a microcontroller.  Possibly a Raspberry Pi, with an ADC (such as these but be warned, these are useless!).


Go Up