Skip to content

Commit 95dbb18

Browse files
authored
Merge pull request #9396 from timchinowsky/main
fix off-by-one in ADC sample rate divisor
2 parents a037491 + 4620323 commit 95dbb18

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

ports/raspberrypi/common-hal/analogbufio/BufferedIn.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ void common_hal_analogbufio_bufferedin_construct(analogbufio_bufferedin_obj_t *s
5353
// sample rate determines divisor, not zero.
5454

5555
// sample_rate is forced to be >= 1 in shared-bindings
56-
float clk_div = (float)ADC_CLOCK_INPUT / (float)sample_rate;
56+
// Per the datasheet: "Setting DIV.INT to some positive value n will trigger the ADC once per n + 1 cycles."
57+
// So subtract 1. See PR #9396.
58+
float clk_div = (float)ADC_CLOCK_INPUT / (float)sample_rate - 1;
5759
adc_set_clkdiv(clk_div);
5860

5961
// Set up the DMA to start transferring data as soon as it appears in FIFO

0 commit comments

Comments
 (0)