{"id":529,"date":"2020-01-21T10:32:22","date_gmt":"2020-01-21T10:32:22","guid":{"rendered":"https:\/\/arduino-developer.com\/arduino\/?p=529"},"modified":"2020-01-21T11:41:04","modified_gmt":"2020-01-21T11:41:04","slug":"conversion-time","status":"publish","type":"post","link":"https:\/\/arduino-developer.com\/arduino\/programming\/analog-inputs\/conversion-time","title":{"rendered":"Conversion Time"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">ATmega32u4 <\/h4>\n\n\n\n<p>A conversion takes 13 ADC clocks.  The ADC clock needs to be set using a prescaller from the main OSC to give an acceptable ADC clock rate.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">To get the full 10 bits of resolution<\/h5>\n\n\n\n<p>The successive approximation circuitry requires an input clock frequency between 50kHz to 200kHz.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Faster with 10bit resolution<\/h5>\n\n\n\n<p>Setting the ADHSM bit in ADCSRB allows an increased ADC clock frequency at the expense of higher power consumption.   Setting it to 1 enables the ADC High Speed mode.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Faster with less resolution<\/h5>\n\n\n\n<p>If a lower resolution than 10 bits is needed, the input clock frequency to the ADC can be higher than 200kHz to get a higher sample rate.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Arduino default ADC clock rate<\/h5>\n\n\n\n<p>16 MHz divided by a prescale factor of 128 <\/p>\n\n\n\n<p>16MHz \/ 128 = 125kHz ADC clock x 13 clocks = 104uS  per conversion = 9615Hz<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Faster analog reads using Arduino<\/h5>\n\n\n\n<p>The Arduino digital and anlog read\/write abstractions that make the platform so easy to use reduce the execution time over what could be achieved if using low level code to directly access the analog input peripheral.<\/p>\n\n\n\n<p>A simple change is to alter the prescale setting which will cause analogRead() to return faster, but potentially with a loss of resolution.  For more refined control you&#8217;ll need to access other AtoD register directly.<\/p>\n\n\n\n<p>The ATmega32u4 is specified as offering: 65 &#8211; 260\u03bcs Conversion Time and ADC clock frequency between 50kHz to 200kHz to get maximum resolution.  13 ADC clocks per conversion at 200kHz = 65uS.<\/p>\n\n\n\n<p>The Arduino uses a 16MHz oscillator to give 16MHz clock speed.<\/p>\n\n\n\n<p>Prescaling is set by the ADPS bits in ADCSRA.  Available division factors are: 2, 4, 8, 16, 32, 64, 128,<\/p>\n\n\n\n<p>The conversion time for the standard Arduino implementation:<\/p>\n\n\n\n<p>16MHz \/ 128 = 125kHz ADC clock x 13 = 104uS  per conversion<\/p>\n\n\n\n<p>Changing the prescaler to 64 would give:<\/p>\n\n\n\n<p>16MHz \/ 64 = 250kHz  ADC clock x 13 = 52uS  per conversion <\/p>\n\n\n\n<p>This is too fast for 10 bit resolution, which is why 128 is used.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>ATmega32u4 A conversion takes 13 ADC clocks. The ADC clock needs to be set using a prescaller from the main OSC to give an acceptable ADC clock rate. To get the full 10 bits of resolution The successive approximation circuitry requires an input clock frequency between 50kHz to 200kHz. Faster with 10bit resolution Setting the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"class_list":["post-529","post","type-post","status-publish","format-standard","hentry","category-analog-inputs"],"_links":{"self":[{"href":"https:\/\/arduino-developer.com\/arduino\/wp-json\/wp\/v2\/posts\/529","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/arduino-developer.com\/arduino\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/arduino-developer.com\/arduino\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/arduino-developer.com\/arduino\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/arduino-developer.com\/arduino\/wp-json\/wp\/v2\/comments?post=529"}],"version-history":[{"count":5,"href":"https:\/\/arduino-developer.com\/arduino\/wp-json\/wp\/v2\/posts\/529\/revisions"}],"predecessor-version":[{"id":541,"href":"https:\/\/arduino-developer.com\/arduino\/wp-json\/wp\/v2\/posts\/529\/revisions\/541"}],"wp:attachment":[{"href":"https:\/\/arduino-developer.com\/arduino\/wp-json\/wp\/v2\/media?parent=529"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/arduino-developer.com\/arduino\/wp-json\/wp\/v2\/categories?post=529"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/arduino-developer.com\/arduino\/wp-json\/wp\/v2\/tags?post=529"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}