Starting with PDM micro on RP2040 - bypass the callback

Hi.

I'm starting with the microphone that came with nano RP2040 using the PDM lib.
The example https://docs.arduino.cc/tutorials/nano-rp2040-connect/rp2040-microphone-basics for turning a led ON/OFF works fine.
Then I have commented the line that declares the callback for handling the incoming data and after upload the RP204 crashed immediately (SOS led blinking).

Serial.println("SERIAL OK!");
 // PDM.onReceive(onPDMdata);
  PDM.setBufferSize(512);

Is this the expected behavior?
My goal is to pull data from PDM and bypass the callback. Is this possible?

Cheers.

Do you mean that you want to access the unprocessed PDM bitstream, rather than the filtered and downsampled PCM data returned by the PDM library? Yes, that is possible, but you'll need to bypass the PDM library, and do the PIO/DMA processing yourself -- at least, I haven't found another way of doing it.

Hi.
The PCM data returned by PDM isn't the problem.
The problem is the calllback that pops up in a unpredictable way messing with other time dependent libs like Neopixel.
I would like to get readings from microphone and perform some animations after some processing like FFT.
Any ideia? Thanks.

Looking at the code, as soon as you call PDM.begin(), data will be delivered to the PDM module at intervals via a DMA ISR. Having done some processing (quite a lot, actually), that module will then call your onReceive callback if there is one. I don't see any way of stopping that.

To meet the timing requirements of Neopixels while this is happening, I can think of three things which I might try:

(a) driving the Neopixels from the other core of the RP2040
(b) driving the Neopixels via a PIO program
(c) disabling interrupts round the timing critical sections of the Neopixel code

(a) Will be tricksy, though maybe not impossible. Lots of Arduino functions can't safely be used from the second core, so it'll take some experimentation to find a way of doing it which does work.

I suspect that (b) is the "right" answer, but unless you can find a library that someone's already written, it might be rather deep water if you haven't done anything like it before.

(c) Might work OK, as long as you don't need to keep interrupts disabled for too long: that'll depend on the length of your NeoPixel string.

That's all I can think of, though I'm a relative newbie myself!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.