Feather M0 analogread() very slow...

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
jarekdudzinski
 
Posts: 13
Joined: Mon Jul 04, 2016 5:08 pm

Feather M0 analogread() very slow...

Post by jarekdudzinski »

Hi :)
I'm trying to capture a lot of analog data over shortest possible time. Was working on standard Arduino Uno, but after testing, it's too slow - 5000 consecutive analog reads takes 560ms. Then I thought about my Feather M0 - with much faster processor speed.
I've quickly connected it, uploaded the same code I've used on Uno board and... 5000 reads is taking 2117 ms! :O

Pasting my test code - did I'm missing something, or it really is slower than Uno? :/

Code: Select all

void loop() {
  unsigned long startTime = 0;
  unsigned long endTime = 0;
  int sensorValue = 0;
  
  startTime = micros();
  for (int i=0; i<5000; i++) {
    sensorValue = analogRead(A0);
  };
  endTime = micros();

  Serial.print("Time: ");
  Serial.print( float (endTime-startTime)/1000.0 );
  Serial.print(" ms");
  Serial.print("\n");
  Serial.print("Last value: ");
  Serial.print(sensorValue);
  Serial.print("\n\n");
}

User avatar
zener
 
Posts: 4567
Joined: Sat Feb 21, 2009 2:38 am

Re: Feather M0 analogread() very slow...

Post by zener »

My initial guess is it's because the feather can produce a 14 bit result vs the Arduino 10 bit result. A 14 bit read takes longer. However, this info:

https://learn.adafruit.com/bluefruit-nr ... /nrf52-adc states that the default is 10 bits. But you might try using the analogReadResolution(...) function to set it to 10 and see if that helps. You could also set it lower and that should speed it up some.
The ADC resolution can be set to 8, 10, 12 or 14 bits using the analogReadResolution(...) function, with the default value being 10-bit:
Good luck

User avatar
jarekdudzinski
 
Posts: 13
Joined: Mon Jul 04, 2016 5:08 pm

Re: Feather M0 analogread() very slow...

Post by jarekdudzinski »

You are looking at different board than mine. I have M0 version with Bluetooth module. It’s analog output is 10bits.

User avatar
zener
 
Posts: 4567
Joined: Sat Feb 21, 2009 2:38 am

Re: Feather M0 analogread() very slow...

Post by zener »

If it is the D21 processor it can do 12 bit AD reads. Which exact product are you using?

User avatar
jarekdudzinski
 
Posts: 13
Joined: Mon Jul 04, 2016 5:08 pm

Re: Feather M0 analogread() very slow...

Post by jarekdudzinski »

This one: https://www.adafruit.com/product/2995

Normally, it gives 10bit (0-1023 value) output on ADC pins.

User avatar
adafruit_support_bill
 
Posts: 88041
Joined: Sat Feb 07, 2009 10:11 am

Re: Feather M0 analogread() very slow...

Post by adafruit_support_bill »

The ATSAMD21 has 12 bit resolution on the ADC. https://www.microchip.com/wwwproducts/ATsamd21g18
The AnalogRead() in the Arduino IDE defaults to 10 bits for backward compatibility. But it allows you to specify a higher resolution on processors that support it: https://www.arduino.cc/reference/en/lan ... esolution/

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”