I am trying to test the ADC sampling rate of Arduino Portenta H7. Using this basic code I can get 250 KSample / sec
// ARDUINO H7 ADC TEST
// test adc reading sampling rate on a floating pin
/* DEFINE */
// how many samples to combine
#define SAMPLES (1000)
/* INIT */
int analogPin = A0;
long val = 0;
long dataSum = 0;
long dataAvg = 0;
long timeStart = 0;
long timeElapsed = 0;
int nn = 0;
/* SETUP */
void setup(){
Serial.begin(115200);
// set analog read resolution
analogReadResolution(12);
Serial.println(" Test Arduino Portenta H7 ADC samplig rate ");
}
/* LOOP */
void loop(){
// record time start
timeStart = millis();
// averaging samples
for (int i = 0; i < SAMPLES; i++){
val = analogRead(analogPin);
dataSum += val;
nn++;
}
// time elapsed in msec
timeElapsed = millis() - timeStart;
// data average
dataAvg = dataSum / nn;
// print sampling rate
Serial.print(" # KSamples/sec: ");
Serial.print(nn/timeElapsed);
// print time elapsed
Serial.print(" Time elapsed msec: ");
Serial.print(timeElapsed);
// print adc data average
Serial.print( " ADC data average: ");
Serial.println(dataAvg);
// reset counter
nn = 0;
dataSum = 0;
delay(2000);
}
But Arduino Portenta ADC tech specs shows:
ADC: 3× ADCs with 16-bit max. resolution up to 36 channels, up to 3.6 MSPS
which is defintely higher than the one I have obtained
How can I improve the ADC sampling rate ?