Skip to content

raspberrypi: reject 732 Hz in analogbufio.BufferedIn - #11910

Merged
dhalbert merged 1 commit into
adafruit:mainfrom
emincan2000:analogbufio-min-rate
Nov 18, 2026
Merged

dhalbert merged 1 commit into
adafruit:mainfrom
emincan2000:analogbufio-min-rate

Conversation

@emincan2000

Copy link
Copy Markdown

On raspberrypi, BufferedIn accepts sample rates from ADC_CLOCK_INPUT / ADC_MAX_CLOCK_DIV = 732 Hz up to 500 kHz. The ADC divider is calculated as 48000000 / sample_rate - 1. At 732 Hz, that gives 65572.8, which does not fit in the 16-bit integer part of the DIV register. adc_set_clkdiv() checks this with invalid_params_if, but that check is off in normal builds. The value then wraps to a divider below 96, so the ADC runs at its full 500 kHz. BufferedIn(pin, sample_rate=732) therefore samples about 680 times faster than requested, while 733 Hz works.

This raises the lower bound to ADC_CLOCK_INPUT / (ADC_MAX_CLOCK_DIV + 1) + 1, which is 733 Hz. I checked every allowed rate using a small C model of the divider calculation and the DIV register. Only 732 Hz came out wrong. Every rate from 733 Hz to 500 kHz is within 1 % of the requested rate. I haven't tried it on a board.

At 732 Hz the ADC divider is 48000000 / 732 - 1 = 65572.8, which does
not fit in the 16-bit integer part of DIV. The value wraps and the ADC
runs at its full 500 kHz instead. Start the valid range at 733 Hz.

@dhalbert dhalbert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks!

@dhalbert
dhalbert merged commit 0dcb267 into adafruit:main Nov 18, 2026
177 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.

2 participants