Fast ADC Sampling

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
Posts: 2
Joined: Tue Feb 09, 2021 8:01 pm

Fast ADC Sampling

Post by segallis » Tue Feb 09, 2021 8:55 pm

I have several applications for ESP8266 modules incorporating signal processing that requires fast ADC sampling. One example is performing FFTs on sampled data. In many cases, I can get by with as few as 256 samples. 1024 samples would probably be the longest I need. The problem is I need a reasonably high sample rate in some cases.

My first measurements seemed to achieve about 4 Ksps in uPython. After trying different coding structures, I achieved faster sample rates.
I found that the same code in a function runs faster than having it in the main loop (not sure why that is?). The native code switch also speeds things up further. With the timing code/prints removed, the guts look like this:

def getadc():
global x
ain = ADC(0).read
x = [ain() for j in range(N)]

N = 1000

With an 80 MHz CPU clock I get 9.7 ksps, with the CPU running at 160 MHz I get 11.7 ksps. (Btw, this is almost as fast as using C in the Arduino IDE.)

If I disable WiFi, using, I can get 20.7 ksps at 80 MHz, or 25.6 ksps at 160 MHz.

Is there some way to get this performance without needing to drop the WiFi link? I only need 10 to 40 ms of capture time without the radio, or whatever is slowing down ADC access. I have no idea why disabling WiFi speeds things up more than 2X? Is there something
like a register poke that will improve the ADC capture rate for 10 to 40 ms? Disabling interrupts? My goal would be to have a faster recovery than having to drop and then reconnect WiFi every couple of seconds.

Also, using C/Arduino IDE, I am able to get sample rates as high as 212 ksps using the system_adc_read_fast() function. Is there anyway to get even close to that kind of performance with uPython? Is there a way to code a C call to that routine and embed into an mpy file to use as a library???



Post Reply