Go Down

Topic: Arduino Due sampling speed (Read 708 times) previous topic - next topic

hamvil

Hi,

I'm using an Arduino Due for a data acquisition project (from an hall sensor). At the release of this device I remember that one big point (for me) was that the sampling rate increased from 15k sample/s to about 1000k sample/s.

However If I run the following sketch:

Code: [Select]
void setup() {
  Serial.begin(9600);
}

void loop() {
  long count = 10000;
  long start = millis();
  for (int i = 0; i < count; i++) {
    analogRead(A0);           
  }
  long tot = float(count * 1000) / float(millis() - start);
  Serial.println(tot);
}


I get a sampling rate of about 25k sample/s.

Am I doing something wrong?
R,

Collin80

What you're doing wrong is using the built-in analogRead function. It's slow as dirt. The hardware of the Due is capable of 1M samples per second but this has limits. You might get limited accuracy if the signal is quickly changing. You only get 1M samples per second if you only read one port. If you start changing which ADC you are reading you will get delays.

If you need very fast data acquisition then you should be setting up the DMA controller to take ADC readings and directly store them to RAM behind the processor's back and then read them once the sample buffer is full.

You can get more information here:
http://forum.arduino.cc/index.php?topic=137635.0

Go Up