I have used a very simple code to find sampling rate of the ADC at 16 bit resolution and at different hardware average count (1 to 32).
Code:
#define RES 16
// change HARDWARE AVG to 1, 2, 4, 8, 16, 32
#define AVG 2
#define CNT 160000 / AVG
void setup() {
Serial.begin(115200);
analogReadResolution(RES);
analogReadAveraging(AVG);
analogReference(0);
}
void loop() {
int t = micros();
int a0;
for(int i = 0; i < CNT ; i++){
a0 = analogRead(A0); // read data
}
t = micros() - t;
Serial.print("ADC sampling rate (AVG "); Serial.print(AVG); Serial.print(") = ");
Serial.print(160000000 / t); Serial.println(" kSPS");
}
The output for hardware average count (1, 2, 4, 8, 16 and 32) is as below
Code:
ADC sampling rate (AVG 1) = 215 kSPS
ADC sampling rate (AVG 2) = 159 kSPS
ADC sampling rate (AVG 4) = 319 kSPS
ADC sampling rate (AVG 8) = 353 kSPS
ADC sampling rate (AVG 16) = 368 kSPS
ADC sampling rate (AVG 32) = 377 kSPS
Surprisingly, with hardware average of 2, the ADC works slow. The sampling rate should be more if the ADC is configured at free-running mode. But I do not know, what registers to use for this configuration. After this I would like to use DMA and free-running mode. Can anyone help in this line?