Cubecell HTTC-AB02A very slow analogRead()

I’m working on a project that includes sampling audio signal and using FFT.
But I found that reading ADC data with analogRead() is very slow.
Every sample is taken for almost 1s.
Is it really so slow or I do something wrong?

hi,

Could you post your test code for adc?

Let’s figure out the reason.

hi,

actually I was not correct, I meant that the bunch of samples takes about 1 second, not single reading.

But the single reading is also slow, for example, the code:

microseconds = micros();
data[i] = analogRead(ADC3);
microseconds2 = micros();
Serial.println(microseconds2 - microseconds);

shows that every reading takes about 10ms.
But it means that I can get only 100 samples per second. It is not enough.

Could you confirm speed of the analogRead()?
If it is really so slow, is there any workaround to read ADC data faster, maybe direct register access?

For example, on Arduino (based on Atmel AVR) we can read ADC registers directly and also we have interrupts to read data when it is ready.

Thanks

I can confirm 10ms too, then tested same code on stm32l1 just for fun and that was 40microseconds per adc read

1 Like

Could you confirm the ADC reading speed?

hi,

We carefully read the source code in the sdk.It is found that every time an adc value is obtained, mcu reads 256 times, and then takes an average value.

We have now changed it to twice(the min vaule can be config twice). The reading time now drops below 100 microseconds.

please git pull.

2 Likes

Hi Jason,
Is it possible to change the average time in our program?

Hi,
It’s not conveniently to change the average dynamic. Now we set the default average time to 2. I think you can read repeatly and take a average in your own code.