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
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.
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.
Download the library at GitHub.
The analog inputs of the SAMD21 require buffer opamps, else the ADC values are very noisy. This is because successive approximation ADCs do switch capacitances at the input during the conversion. In order to have a stable conversion, it is mandatory to use a low impedance circuit to drive their input.
The necessity of a buffer opamp depends on the required accuracy. For Arduino chips with 10bit ADCs, an input buffer is not always necessary.
Note that there are also ADCs with a buffer built in.
Input buffer for successive approximation Arduino ADC
A simple RC filter at the input of a 10bit ADC sometimes works fine without an extra buffer. But for a 12bit ADC (SAMD21) it can be problematic.
RX / CX is to prevent instability of the opamp, this is not always necessary.
The testprogram can be downloaded at GitHub .
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
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.