Recording PDM data of XIAO nRF52840 Sense to SD card

I recorded PDM data to an SD card for practice. I hope this will be helpful for those who are interested. To record PDM data to SD card, several measures were necessary.

  1. Flush after each block recording to prevent file corruption.
  2. Prepare a sampleBuffer of 1000mS to match the 400mS write and flush time.
  3. Use a FIFO for 1000mS to prevent data loss due to SD’s long write time of 1500mS that sometimes occurs.
  4. speed up SD’s SPI clock as much as possible
  5. minimize the gain to prevent data overflow because the microphone is highly sensitive.

The SD contains PCM data with 16-bit 16 kHz sampling; I used Audacity’https://www.audacityteam.org/’ to convert it to WAV format. Unfortunately, the sound quality is far from HiFi.
Note: If the microphone input is even slightly too loud, the data will overflow and noise will be recorded.

Here are the sketches and sample WAV files used in the experiment.
POST_nRF52_XIAO_PDM_SD.zip (384.7 KB)

3 Likes

Hello! I was able to create a similar program to yours, and I had a few questions that you may be able to answer.

Have you recorded the current draw at all for your program?
Why do higher amplitude recordings cause skips/clipping in the audio? How can this be combatted? (An issue in my code)

Thanks!

Current consumption when 3.8V is applied to the battery pad. The average current is 15 mA and the peak is 60 mA.
If the recording clips even with minimal gain, how about reducing the sound input by plugging the microphone hole or moving the microphone away from the sound source?

Thanks for the graph! I have tried moving the device further away from the source, and while this does work, I want to ensure my device can log as much data as possible.

Audio analysis is fairly new to me, and I was wondering what causes the clipping? Additionally, for further clarification, does PDM.setGain(0); set the gain to -20dB? Is that the lowest setting?

Thank you in advance!

does PDM.setGain(0); set the gain to -20dB? Is that the lowest setting?

setGain(0); sets the gain to -20dB.

If you import the waveform into Audacity and check the waveform, you can see how it clips and inverts.

Thank you for your help!