ADC Sampling // DMA // FFT (Raspberry Pico)

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Post Reply
Chillmaz
Posts: 3
Joined: Mon Sep 13, 2021 9:43 am

ADC Sampling // DMA // FFT (Raspberry Pico)

Post by Chillmaz » Tue Sep 28, 2021 2:49 pm

Hi,

In my project I want to check the sound emission of a motor (current status of the project), for analyzing anomaly purposes (2nd part of the project). For this reason I've placed a piezo sensor on it for reading the voltage. The goal is to transform this acquired data into frequency spectrum with a sample amount about 50k, save it in a csv file and send the file with the whole dataset via a NRF24L01+ module to a raspi 3.

The datasheet of the Pico says it has a sampling rate of 500k.
Apparently this is only achievable if the values are written directly into the the ram registers (DMA = Direct Memory Access).
What's the max sampling rate i could achieve without DMA, without jittering?
Is there a reasonable benchmark test for checking how many samples I actually could get in a second?
If not, how would a code snippet look like to approve the true sample amount? I need to verify that I've a good amount of dataset to progress further.

For the FFT part, I've been trying to use Peter Hinch's repo:
https://github.com/peterhinch/micropython-fourier (FFT), which gave me the following error:
Traceback (most recent call last):
File "<stdin>", line 63, in fft
SyntaxError: unsupported Thumb instruction 'rbit' with 2 arguments
File: dft.py
I can only assume it has to do with using a different board (pyboard). What would i have to do to adapt to the Pico?

Finally I've had found this https://www.hackster.io/AlexWulff/adc-s ... ico-f883dd
which has already done most of the work i needed, but it is written in C/C++ and I'd like to stick to micropython.

Any advices, help or hints are welcomed and appreciated. Bear with me, I'm still new to this whole coding thing and I'm trying really hard.

further sources:
https://github.com/jbentham/rpi
https://iosoft.blog/2020/06/11/fast-dat ... pberry-pi/ (DMA)
https://iosoft.blog/2020/11/16/streamin ... pberry-pi/ (DMA)
Last edited by Chillmaz on Wed Sep 29, 2021 9:13 am, edited 2 times in total.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: ADC Sampling // DMA // FFT (Raspberry Pico)

Post by pythoncoder » Wed Sep 29, 2021 5:26 am

Unfortunately my DFT repo was written some years ago when the only supported platform was the Pyboard. It is written in Arm Thumb V7 assembler: this supports hardware floating point. The Pico supports only V6, with software floating point. Here are three possible solutions:
  • Use a Pyboard.
  • Investigate ulab: I don't know if this has been ported to the Pico but it does fast DFT in C.
  • Write the DFT in Python. Easy but slow. Might be possible to use Viper to speed it up.
An NRF24l01+ has a maximum payload size of 32 bytes. I've never tried to send data of that size but it may not be particularly quick. You might be interested in my work on this. It was also written in the Pyboard-only days but should readily adapt.
Peter Hinch
Index to my micropython libraries.

Chillmaz
Posts: 3
Joined: Mon Sep 13, 2021 9:43 am

Re: ADC Sampling // DMA // FFT (Raspberry Pico)

Post by Chillmaz » Wed Sep 29, 2021 9:24 am

It's a condition to use the pico actually. I cant use any other boards unfortunately.
Applying DFT/FFT shouldn't be big of a problem. The main issue atm is, how to make use of the 500ksps without getting delays or memory allocation. At least I know that DMA comes here into action, but im quite clueless how to code this part, with all the registers etc. That's the point im stuck right now.

jayben
Posts: 1
Joined: Tue Oct 26, 2021 6:41 pm

Re: ADC Sampling // DMA // FFT (Raspberry Pico)

Post by jayben » Tue Oct 26, 2021 6:48 pm

I've just written a post on high-speed analog dataq acquisition in MicroPython, using the Pico ADC and DMA.
See https://iosoft.blog/pico-adc-dma/

Post Reply