{"id":617,"date":"2013-08-02T18:06:58","date_gmt":"2013-08-03T01:06:58","guid":{"rendered":"http:\/\/inkofpark.wordpress.com\/?p=617"},"modified":"2024-09-01T20:12:42","modified_gmt":"2024-09-02T02:12:42","slug":"arduino-analog-sample-rate","status":"publish","type":"post","link":"https:\/\/www.inkofpark.com\/?p=617","title":{"rendered":"Arduino Analog Sample Rate"},"content":{"rendered":"<p>The Arduino Uno is not the ultimate signal processing machine, but it can do some light duty work on burst data. I had trouble finding the maximum sample rate the Uno can support, which is totally critical for most kinds of work.<\/p>\n<p>With native prescale<\/p>\n<ul>\n<li>Samples, type casts into floats, and stores in an array at about 8929 Hz, or 112 microseconds per read-and-store<\/li>\n<li>Samples and into stores into an array of unsigned integers (16 bit) at about 8930 Hz, or 112 microseconds per read-and-store<\/li>\n<\/ul>\n<p>We can step this up quite dramatically by setting the prescale set to 16:<\/p>\n<ul>\n<li>Samples, type casts into floats, and stores in an array at about 58600 Hz, or 17 microseconds per read-and-store<\/li>\n<li>Samples and stores into an array of unsigned integers (16 bit) at about 58606 Hz, or 17 microseconds per read-and-store<\/li>\n<\/ul>\n<p>Pretty close to a 60 KHz sample rate, more than adequate for audio sampling. Of course, the Arduino doesn&#8217;t have enough memory to be a serious audio processor, but it is pretty goood.<\/p>\n<p>The <a href=\"http:\/\/forum.arduino.cc\/index.php\/topic,6549.0.html\">forums discuss this<\/a>, and arrive at a similar conclusion.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#define NSAMP 5000\n\nvoid setup(){\n  Serial.begin( 57600);\n \n  float array_float&#x5B; NSAMP]; \/\/ float\n  unsigned int array_int&#x5B; NSAMP]; \/\/ 16 bit\n  unsigned long int micsbegf, micsendf, micsbegi, micsendi;\n \n  for( int i = 0; i &amp;amp;lt; 2; i++){\n    if ( i == 1){\n       \/\/ Set prescale to 16, and retry\n      sbi(ADCSRA,ADPS2);\n      cbi(ADCSRA,ADPS1);\n      cbi(ADCSRA,ADPS0);\n    }\n    \n    \/\/ Record floats (extra time for type conversion presumably)\n    micsbegf = micros();\n    for( int i = 1; i &amp;amp;lt; NSAMP; i++){\n      array_float&#x5B; i] = (float)analogRead( A1);\n    }\n    micsendf = micros();  \n    \n    \/\/ Record floats (extra time for type conversion presumably)\n    micsbegi = micros();\n    for( int i = 1; i &amp;amp;lt; NSAMP; i++){\n      array_int&#x5B; i] = analogRead( A1);\n    }\n    micsendi = micros();  \n   \n    if( i == 1){\n     Serial.println(&amp;amp;quot;with prescale set to 16&amp;amp;quot;);\n    } \n    Serial.print(&amp;amp;quot;recorded &amp;amp;quot;);\n    Serial.print( NSAMP);\n    Serial.print(&amp;amp;quot; float samples in &amp;amp;quot;);\n    Serial.print(micsendf - micsbegf);\n    Serial.println(&amp;amp;quot; usec&amp;amp;quot;);\n    \n    Serial.print(&amp;amp;quot;recorded &amp;amp;quot;);\n    Serial.print( NSAMP);\n    Serial.print(&amp;amp;quot; unsigned integer samples in &amp;amp;quot;);\n    Serial.print(micsendi - micsbegi);\n    Serial.println(&amp;amp;quot; usec&amp;amp;quot;);\n  }\n}\n\nvoid loop(){\n  delay( 10);\n}\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Arduino Uno is not the ultimate signal processing machine, but it can do some light duty work on burst data. I had trouble finding the maximum sample rate the Uno can support, which is totally critical for most kinds of work. With native prescale Samples, type casts into floats, and stores in an array [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[17,25],"class_list":["post-617","post","type-post","status-publish","format-standard","hentry","category-making","tag-arduino","tag-electronics"],"_links":{"self":[{"href":"https:\/\/www.inkofpark.com\/index.php?rest_route=\/wp\/v2\/posts\/617","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inkofpark.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inkofpark.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inkofpark.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inkofpark.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=617"}],"version-history":[{"count":1,"href":"https:\/\/www.inkofpark.com\/index.php?rest_route=\/wp\/v2\/posts\/617\/revisions"}],"predecessor-version":[{"id":1273,"href":"https:\/\/www.inkofpark.com\/index.php?rest_route=\/wp\/v2\/posts\/617\/revisions\/1273"}],"wp:attachment":[{"href":"https:\/\/www.inkofpark.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=617"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inkofpark.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=617"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inkofpark.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=617"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}