Page 1 of 2

Gaps in ADC voltage response when using DMA

Posted: Fri Sep 04, 2020 6:44 pm
by jkingdon
Hi,

I'm trying to run multi-channel DMA based ADC and I'm getting some strange results. Since this config isn't supported by the APIs I've had to manipulate the registers directly so it's possible I've done something wrong, but it isn't immediately obvious how an ADC could be misconfigured to behave like this. In the following plots I have simply logged the raw values returned from the ADC and plotted each sample as a dot. It's clear that there are multiple voltage regions in which no samples are ever returned. The problem remains with different bit widths and attenuation settings (although I can only try the 6 and 11 dB settings without adding a resistor network on the input).

Has anyone run into this before or have any suggestions?
adc-gaps-12bit-11db.jpg
adc-gaps-12bit-11db.jpg (140.52 KiB) Viewed 11374 times
adc-gaps-12bit-6db.jpg
adc-gaps-12bit-6db.jpg (127.28 KiB) Viewed 11374 times
adc-gaps-9bit-6db.jpg
adc-gaps-9bit-6db.jpg (128.95 KiB) Viewed 11374 times

Re: Gaps in ADC voltage response

Posted: Sun Sep 06, 2020 12:49 pm
by jkingdon
As an update, I created a simplified test case that only reads one channel and doesn't use any of my dubious register hacking, and it still shows the same behaviour. I've tested on three different esp32 and all behave in the same way, so it's not a single bad chip, and with different sources for the analog input, including the signal generator on my oscilloscope. I confirmed that the problem isn't visible when using the synchronous (non-dma) APIs.

The attached chart is from the single channel test case.

Re: Gaps in ADC voltage response when using DMA

Posted: Sun Sep 13, 2020 4:41 pm
by jkingdon
I've been unable to solve the gaps in the ADC data despite a fair bit of effort. I have some more esp32 on order to see if the newer chip revisions behave differently.

In the mean time, I've implemented multi-channel ADC on an STM32F103 and the data looks good. The following is a similar setup to the esp32 tests, raw results from one of four channels that were being sampled plotted as individual dots.
stm32f103_8kHzx4_raw.jpg
stm32f103_8kHzx4_raw.jpg (88.85 KiB) Viewed 11271 times

Re: Gaps in ADC voltage response when using DMA

Posted: Sun Sep 13, 2020 9:28 pm
by plusorc
can you repeat your simplified test after pulling low the PIN you're reading from ?

I had strange results recently when I was just reading mains frequency , and now all is good after
inverting the signal (had to do that instead of pulling low the PIN)

Re: Gaps in ADC voltage response when using DMA

Posted: Mon Sep 14, 2020 2:51 am
by jkingdon
plusorc wrote:
Sun Sep 13, 2020 9:28 pm
can you repeat your simplified test after pulling low the PIN you're reading from ?

I had strange results recently when I was just reading mains frequency , and now all is good after
inverting the signal (had to do that instead of pulling low the PIN)
Hi, what would pulling the pin low involve? I assume you don't mean externally as then there wouldn't be any signal to read, so I guess we're talking about the internal pull down on the digital input?

Re: Gaps in ADC voltage response when using DMA

Posted: Mon Sep 14, 2020 10:37 am
by plusorc
I actually meant externally , If you're trying to read from INPUT pins like GPIO34 .. AFAIK it doesn't have internal resistors
see this thread , I ended up using 2n222 to invert the signal and only that made it work accurately
In my case I also couldn't pull down the PIN externally so I inverted the signal

viewtopic.php?f=19&t=17188

Re: Gaps in ADC voltage response when using DMA

Posted: Mon Sep 14, 2020 12:02 pm
by jkingdon
Thanks, I'll have to read through the link later. I don't think I can put an external pull down on the adc pin without influencing the voltage I'm trying to read. However, when I was wondering about crosstalk from the digital pin it made me realise that the pins I chose to use are the ones attached to the deprecated LNA. It's probably worth me testing with a different set of pins and see if things are any different.

Re: Gaps in ADC voltage response when using DMA

Posted: Tue Sep 15, 2020 1:09 am
by jkingdon
Sadly it wasn't the LNA causing problems, I get the same thing if I use ADC channel 4. I made a small test case to demonstrate the problem using the DAC to output a sine wave as a test signal. It was written for platformIO with the arduino framework but is small enough that it should be easy to port.
adcTest.zip
(235.6 KiB) Downloaded 626 times

Re: Gaps in ADC voltage response when using DMA

Posted: Tue Sep 15, 2020 12:49 pm
by plusorc
I'm getting the same thing you have , even when I pulled it low .. same result
bands.png
bands.png (60.26 KiB) Viewed 11098 times

Re: Gaps in ADC voltage response when using DMA

Posted: Tue Sep 15, 2020 2:51 pm
by jkingdon
Hey @plusorc many thanks for trying it out! It's good to know it's not just me/the esp32s I have here.

It seems unlikely this is a real problem in the hardware, after all, the ADC works if we call it without using DMA/I2S, so now the thing is to figure out what I've done wrong :)