Monday, April 15, 2024

Why is conversion time 10 instances slower in my ESP32-WROOM-32U?


The next code is used to point out conversion time and most sampling frequency. The code is from this GitHub web page for a spectrum analyzer based mostly on the ESP32. The writer in his YouTube video reveals that his studying is round 10 Ξs for the conversion time and round 100000 Hz as most sampling frequency.

Right here is my case:

Conversion time: 93.54 uS
Max sampling frequency: 10690.92 Hz

It’s 10 instances slower! What’s the downside?

#outline AUDIO_IN_PIN 35

int analogValue;
unsigned lengthy newTime;

void setup() {
  Serial.start(115200);
  Serial.println("START");
}

void loop() {
  newTime = micros();
  
  // Do 1 million reads and file time taken
  for (int i = 0; i < 1000000; i++) {
    analogValue = analogRead(AUDIO_IN_PIN);
    
  }

  float conversionTime = (micros() - newTime) / 1000000.0;
  Serial.println("END");
  Serial.print("Conversion time: ");
  Serial.print(conversionTime);
  Serial.println(" uS");

  Serial.print("Max sampling frequency: ");
  Serial.print((1.0 / conversionTime) * 1000000);
  Serial.println(" Hz");
}

Edit: Sorry my dangerous, I added yield() to see what occurs, however nothing has modified.

Edit: I’ve tried the @thebusybee recommandation and the consequence is similar!

void loop() {
  
  newTime = micros();
  //delay(10);
  //delay(100);
  delay(1000);
  // Do 1 million reads and file time taken
  for (int i = 0; i < 1000000; i++) {
    analogValue = analogRead(AUDIO_IN_PIN);
    
  }

  float conversionTime = (micros() - newTime) / 1000000.0;
   Serial.println("END");
  Serial.print("Conversion time: ");
  Serial.print(conversionTime);
  Serial.println(" uS");

  Serial.print("Max sampling frequency: ");
  Serial.print((1.0 / conversionTime) * 1000000);
  Serial.println(" Hz");
}

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles