Skip to content

Conversation

@jepler
Copy link

@jepler jepler commented Feb 4, 2026

Between 7.1.1 and 7.2.0, a change was made to PDMIn that caused the passed-in sample rate to be used, instead of the fixed value 44100. When the sample rate 16000 was actually used, an underlying problem was exposed: The PIO clock was determined incorrectly.

Some problems in the same area were also resolved: The PIO frequency check was also wrong by a factor of two, and when a too-low sample rate led to the exception being thrown, the incomplete PDMIn object was not correctly deallocated, leading to an error that the pin objects were still in use.

After this change, I get plausible RMS noise level values changing from under 200 in a "quiet room" and up to 6000+ when I make noise directly next to the mic.

I did my testing on a Metro RP2350 with the adafruit PDM mic board, using pins 22 and 23 at a specified frequency of 16000. I also used my scope and checked that a sample rate of 16000 actually gives a PDM "CLK" frequency of 64*16kHz (1.024MHz) after the change, and that significantly smaller sample rate values such as 8000 are correctly rejected and can be tried again without resetting.

Closes: #10799

The sample rate needs to be mutiplied by oversampling, not by 32.
The "actual frequency" is the PIO frequency, which is twice the audio
clock.
This ensures that after using an invalid sample rate, the pin objects
and pio object are deinitialized.
Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!! @caternuson would you like to test?

@caternuson
Copy link

Nice! Seems to fix things re-running same test from issue thread:

Adafruit CircuitPython 10.1.0-beta.1-28-ge1bc5e2f40 on 2026-02-04; Adafruit QT Py RP2040 with rp2040
>>> import pdm_test
160 (96.1623,)
160 (63.4923,)
160 (73.8208,)
160 (81.238,)
160 (5275.07,)
160 (11503.3,)
160 (2226.01,)
160 (185.137,)
160 (55.1477,)
160 (59.0909,)
160 (59.9527,)
160 (52.0881,)
160 (61.6757,)

@dhalbert dhalbert merged commit 25e8293 into adafruit:main Feb 5, 2026
166 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

audiobusio.PDMIn not working on RP2040 since v7.2.0

3 participants