Skip to content

[STM32F1/STM32F4] ADC speed is very slow #1352

Closed
@rtek1000

Description

@rtek1000

analogRead:

STM32F103C8T6:.......63.950us
STM32F407VG:...........53.788us
Arduino DUE:.................4.361us
Arduino Mega2560:....112.008us

code:

uint32_t adc0 = 0;
uint32_t adc1 = 0;

uint32_t micros0 = 0;
uint32_t micros1 = 0;

void setup() {
  // put your setup code here, to run once:
  delay(250);
  Serial.begin(115200);
  Serial.println("Start");

  pinMode(13, OUTPUT);
  //pinMode(PC13, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(13, !digitalRead(13));
  //digitalWrite(PC13, !digitalRead(PC13));

  micros0 = micros();

  for (uint32_t cnt1 = 0; cnt1 < 1000; cnt1++) {
    adc0 = analogRead(A0);
    //adc0 = analogRead(PA0);
  }

  micros1 = micros();

  Serial.print(micros1 - micros0, DEC);
  Serial.println("us");

  delay(500);
}

Why is ADC so slow?

Another complaint about this:
[analogRead slow with ST libraries]
https://www.stm32duino.com/viewtopic.php?f=7&t=967&p=6393&hilit=adc+dma#p6393

Using the ST board definitions, t takes about 5645 microseconds to do the 100 conversions, so 56.45 uSec per conversion (including the loop instructions but those only take about 1 uSec, I checked). Using the stm32duino board definitions, it only takes 698 microseconds... almost 10 times faster!

Metadata

Metadata

Assignees

No one assigned

    Labels

    answeredduplicateThis issue or pull request already existsquestion ❓Usually converted as a discussion

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions