0

I need to read multiple analog inputs as fast as possible on a ESP32. With as fast as possible, i mean that ideally all inputs are read simultaneously.

Currently I simply read them one after the other with consecutive AnalogREAD() calls in my code, but it happens that I read a value on a Input where no current is applied. I have read somewhere some months ago that in these cases it is good to put a pause between Read calls to give it the time to switch to the proper input.

Is this true? What is a reasonable amount of time to put in there, keeping in mind that I would need to read tehm all (5 inputs) as quick as possible?

All inputs are on the ADC 1.

sharkyenergy
  • 279
  • 1
  • 3
  • 10
  • Depends on the type of ADC. If it's a capacitive sample-and-hold then it indeed might be wise to have a pause after switching to a diffirent input to allow the capacitor to settle at the new input voltage. How long this takes depends on the impedances involved. – Unimportant Jul 21 '21 at 06:46
  • @Unimportant Usually the analog input pin is disconnected and only connected to the sampling capacitor during the sampling period after starting the conversion. And it is the job of ADC to reset the sampling capacitor when it is done. Therefore, as the sampling period is always the same, there is no difference if there is a delay or not. If a delay helps, it means the ADC may be running too fast anyway or source impedance is too high for the sampling time. – Justme Jul 21 '21 at 09:56

1 Answers1

1

The fastest way would be to use two different ADCs so you can simultaneously sample and convert two analog inputs.

The second fastest way (according to the reference manual) would be to tell the ADC a list of channels which to sample and tell it to go sample the channels in the list, writes results to memory using DMA, and reports with a scan complete interrupt when it is done going through the list.

There is little benefit of delaying between taking ADC conversions, if it helps then it is a sign of the sampled signals having too high impedances to get a stable result, which could be also a sign of the ADC being incorrectly configured for the expected signal impedances, and just longer sampling period (or slower ADC clock) might fix it. Usually the switch between channels is done when the analog sampling circuit is not connected to the analog pin.

Justme
  • 127,425
  • 3
  • 97
  • 261