Go Down

Topic: Arduino Due analogRead time (Read 387 times) previous topic - next topic

corgib

Hi,

I have seen some previous posts/documentation online stating that the analogRead function on an Arduino Due takes 40us. I am aware it is possible to adjust the internal registers and place the ADC in free running mode to speed up the conversion time.

However, when I time how long the analogRead function takes on my Due board I am getting a conversion time of ~5.36us (printed time/number of samples). I have a simple piece of code posted below to time the conversions. Can anyone shed some light as to why I am getting results in the region of 5us instead of 40us?

Code: [Select]
#define CHANNEL A0  // sample pin A0
unsigned long microseconds;
int const samples = 1024;
double vReal[samples];

void setup() {
  Serial.begin(115200);
}

void loop() {
  int start = micros();

  for(int i=0; i<samples; i++)
  {
    vReal[i] = analogRead(CHANNEL);
  }

  Serial.println(micros() - start);
  delay(1000);

}


I tried adjusting the ADC registers on my Due board and thought that might be why the conversion time was quicker but I have now tested two Due boards (no adjustments to 2nd board) and got the same results for both. I presume the measurement would be a lot more accurate with an oscilloscope and toggle a digital pin for every conversion but I have not tested this just yet.

Any help would be greatly appreciated.

Cheers

ard_newbie


For precise ADC readings, forget analogRead(). Search in the DUE sub forum an example code for ADC conversions at a precise freqsuency thru registers direct programming.

Go Up