ADC analogRead() sample rate

Hi!

Does the analogRead() use the maximum ADC sample rate of the microcontroller? And does anyone know how to change the sample rate for the ADC?

I have ATSAMD21G18 microcontroller on an adafruit feather M0 board, same microcontroller as the one on arduino zero.

There is no sample rate because analogRead() just takes one sample :slight_smile:

Unless you take two samples.
I guess that will take twice as long.

Question is: what do you want to sample. And how often do you need to sample.
Leo..

septillion:
There is no sample rate because analogRead() just takes one sample :slight_smile:

I see. Thanks :slight_smile:

Wawa:
Question is: what do you want to sample. And how often do you need to sample.
Leo..

Thanks for answering!
I would like to change the sample frequency somehow, for starters to about 4kHz. I have a pressure sensor that i use to set a time marker when the heel touches the ground. And i would like to try different sample frequencies to see if there is any change in the results.

Have a look at AT03243: SAM D/R Analog to Digital Converter (ADC) Driver.

Whandall:
Have a look at AT03243: SAM D/R Analog to Digital Converter (ADC) Driver.

Ok, will do! Thanks! :slight_smile:

minimoj:
I would like to change the sample frequency somehow, for starters to about 4kHz. I have a pressure sensor that i use to set a time marker when the heel touches the ground.

The heel of the someone's foot?

Why would you need to read that at 4kHz when the steps are going to be a second or so apart?

nyphot:
The heel of the someone's foot?

Why would you need to read that at 4kHz when the steps are going to be a second or so apart?

Yes, footsteps.

I want to make sure that it registers the footstep as soon as it touches the ground

minimoj:
Yes, footsteps.

I want to make sure that it registers the footstep as soon as it touches the ground

I just did a simple test (code below) and did just under 9000 analogRead()s in a second with an otherwise more or less empty loop().

//speed test

unsigned long startTime;
unsigned long runTime;
long counter = 0;

void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);
  startTime = millis();
  Serial.begin(9600);
  Serial.print("Start ");
  Serial.println(millis());
}

void loop()
{
  runTime = millis() - startTime;
  analogRead(0);
  counter++;

  if (runTime >= 1000)
  {
    digitalWrite(LED_BUILTIN, HIGH);
    Serial.print("Read pin ");
    Serial.print(counter);
    Serial.print(" times in ");
    Serial.print(runTime);
    while (1) {
    };
  }

}

Serial output:

Start 0
Read pin 8932 times in 1000

From http://www.microchip.com/wwwproducts/en/ATSAMD21G18

Max A/D Sample Rate (KSPS) 350

nyphot:
I just did a simple test (code below) and did just under 9000 analogRead()s in a second with an otherwise more or less empty loop().

Nice! But I got: Read pin 4710 times in 2000. I had to change it to 2000 to get a result..(?)