Contents[Show]

analogReadFast()

This fast ADC library is built as part of the Oscilloscope base library for the Arduino. The standard analogRead() function takes about 112us for the AVR and 425us for the SAMD21, this is very slow. The new function analogReadFast() takes just 21us. The resolution will not be reduced significantly.
Here is a 2kHz sine wave measured with analogReadFast, shown in Excel:

Fast 10-bit ADC for the Arduino
Fast 10-bit ADC for the Arduino

analogReadFast at the AVR

The library is compatible with Arduino boards that use the AVR chips: Arduino Uno, Nano, Mega, Leonardo, etc.
The analogReadFast function is much faster than the original analogRead: 20us instead of 112us.

analogReadFast at the SAMD21

The library is compatible with Arduino boards that use the SAMD21: Arduino Zero, SAM 15x15, etc. 
The analogReadFast function is much faster than the original analogRead: 21us instead of 435us.
The resolution for analogReadFast must be set with analogReadResolution(10) or analogReadResolution(12), just as with analogRead.

Library download

Download the library at GitHub.

Test program

The testprogram can be downloaded at GitHub

  • AnalogRead is tested with 6 variations: slow / fast, 10 / 12bit, with / without ravg filter.
  • For each test, 100 test values are stored in their own buffer.
  • For these buffers, the RunningAverage library is used, because it has a handy standardDeviation function.
  • AnalogReadFast is quite noisy, so we need filtering. In the test program we create the filter with the RunningAverage library.
  • To do the ADC measurements at full speed, printing to the serial moniotor is done at the end.
  • The values can be copied directly to Excel. That makes it easy to do accuracy and noise tests. 
  • The noise is tested on the SAM15x15 board with extra capacitors at the power supplies: 10uF at 3.3VA and 47uF at 3.3VD.
  • The ADC input voltage is 0.1V, created with a resistor divider of 10Ω and 330Ω to 3.3V.

Arduino noise measurement analogRead and analogReadFast 10/12bit with or without filter
Arduino noise measurement analogRead and analogReadFast 10/12bit with or without filter

In this figure, we can see that the running average size n=16 reduces the standard deviation from 1.3 to 0.25 for analogReadFast 12bit:

Arduino analogReadFast standard deviation vs size n
Arduino analogReadFast standard deviation vs size n

Standard deviation / noise with 10/12bit analogRead() and analogReadFast()

analogRead 10bit SD = 0.5
analogReadFast 10bit SD = 0.5
analogRead 12bit SD = 1.5
analogReadFast 12bit SD = 1.3
analogReadFast 12bit with ravg(16) SD = 0.25

Note: It is remarkeable that the noise with analogReadFast is smaller than with the slow analogRead.

This is what ATMEL says about the ADC: For optimum performance, the ADC clock should not exceed 200 kHz. However, frequencies up to 1 MHz do not reduce the ADC resolution significantly.

Wanted

Maybe the library can be improved, who has time to look into this?

Do you have any comments about the website or problems with shopping? Please let me know.
Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.