This fast ADC is built as part of the Oscilloscope base library for the Arduino. The standard analogRead() function takes about 112us. When this is too slow, use my function analogReadFast(), which takes only 21us. The resolution will not be reduced significantly.
Here is a 2kHz sine wave measured with the fast 10-bit ADC, shown in Excel:

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

Faster ADC for the SAMD21

The library is also 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. For backward compatibility with AVR based boards, the resolution is 10bits. Although the SAMD21 can handle higher resolutions, this is not implemented.

Simple example program

The program shows the speed and ADC values of the analogReadFast() versus the standard analogRead() function.  


#include <Streaming.h>
#include "Albert.h"
const byte ADCpin = 0;
void setup() 
{ Serial.begin(9600);   
void loop() 
{ unsigned long us1 = micros();
  int adcFast4 = analogReadFast(ADCpin); // default value 4 = 20us
  unsigned long us2 = micros();
  int adcFast2 = analogReadFast(ADCpin, 2); // 2 = 12us
  unsigned long us3 = micros();
  int adcSlow = analogRead(ADCpin);
  unsigned long us4 = micros();
  Serial << "\nFast4 " << adcFast4 << " " << us2-us1 << "us Fast2 " << adcFast2 << " " << us3-us2 << "us Slow " << adcSlow << " " << us4-us3 << "us";


Serial monitor output
Note that these values are measured on an Arduino Uno R3 with a clock frequency of 16MHz:

Fast4 408 20us Fast2 408 12us Slow 409 112us


The code is part of the Albert library: 

int analogReadFast(byte ADCpin, byte prescalerBits=4) // inline library functions must be in header
{ byte ADCSRAoriginal = ADCSRA; 
  ADCSRA = (ADCSRA & B11111000) | prescalerBits; 
  int adc = analogRead(ADCpin);  
  ADCSRA = ADCSRAoriginal;
  return adc;

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.

Fast 8-bit ADC for the Arduino

In the same way I want to create a simple function for an 8-bit ADC: analogRead8bit(), which is faster. I have no time to do this, who can help me? Here is some information:


Do you have any comments? Please let me know.
Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.