Skip to content

Update hardcoded I2S::SYSCLK exact mappings - #3497

Merged
earlephilhower merged 3 commits into
masterfrom
brutus
Aug 24, 2026
Merged

Update hardcoded I2S::SYSCLK exact mappings#3497
earlephilhower merged 3 commits into
masterfrom
brutus

Conversation

@earlephilhower

Copy link
Copy Markdown
Owner

Adds a utility to run on the Pico and Pico2 to identify the lowest frequency error possible for a given output sample rate.

Use that data on the Pico and Pico2 to implement a smarter I2S::setSysClk() method which varies the SYSCLK depending on the sample rate and if the I2S is bidirectional.

Originally had the same hardcoded values for RP2040 and RP2350, and the RP2040 values were calculated from the release max F_CPU of 133, not the new official 200MHz support.

Fixes #3496

Adds a utility to run on the Pico and Pico2 to identify the lowest
frequency error possible for a given output sample rate.

Use that data on the Pico and Pico2 to implement a smarter I2S::setSysClk()
method which varies the SYSCLK depending on the sample rate and if the
I2S is bidirectional.

Originally had the same hardcoded values for RP2040 and RP2350, and the
RP2040 values were calculated from the release max F_CPU of 133, not the
new official 200MHz support.

Fixes #3496
@earlephilhower

Copy link
Copy Markdown
Owner Author

For posterity, the output of the brute force checker on real HW as of today is

RP2040

Checking for 8000
220000 0.160000
218400 0.131868
213600 0.044944
213000 0.003756
192000 0.000000
8000: 192000, err=0.000000%
Checking for 16000
220000 0.392727
218400 0.131868
213000 0.003756
153600 0.000000
16000: 153600, err=0.000000%
Checking for 32000
220000 0.392727
213600 0.284644
213000 0.003756
153600 0.000000
32000: 153600, err=0.000000%
Checking for 64000
220000 1.323636
219000 0.873059
218400 0.600733
218000 0.418349
213600 0.284644
213000 0.003756
102400 0.000000
64000: 102400, err=0.000000%
Checking for 48000
220000 0.858185
219000 0.405479
218400 0.131868
212000 0.015091
153600 0.000000
48000: 153600, err=0.000000%
Checking for 96000
220000 2.254549
219000 1.808219
218400 1.538462
218000 1.357795
216000 0.444444
196800 0.097561
190500 0.018898
153600 0.000000
96000: 153600, err=0.000000%
Checking for 192000
220000 5.047276
219000 4.613698
218400 4.351648
218000 4.176143
216000 3.288889
214000 2.385050
213600 2.202247
213000 1.926761
212000 1.464147
211200 1.090909
210000 0.525714
196800 0.097561
192000: 196800, err=0.097561%
Checking for 11025
220000 0.253818
219000 0.120547
216000 0.039996
204000 0.039995
11025: 204000, err=0.039995%
Checking for 22050
220000 0.574545
219000 0.120547
216000 0.039996
22050: 216000, err=0.039996%
Checking for 44100
220000 1.216000
219000 0.764930
218400 0.492306
218000 0.309723
212000 0.150946
195000 0.130458
192000 0.040005
144000 0.040001
44100: 144000, err=0.040001%
Checking for 88200
220000 2.498909
219000 2.053697
218400 1.784613
218000 1.604401
216000 0.693329
210000 0.544000
204000 0.385877
198000 0.218181
192000 0.040005
88200: 192000, err=0.040005%

RP2350

Checking for 8000
165000 0.082424
160800 0.019900
157200 0.010178
153600 0.000000
8000: 153600, err=0.000000%
Checking for 16000
165000 0.082424
160800 0.019900
153600 0.000000
16000: 153600, err=0.000000%
Checking for 32000
165000 0.703030
164000 0.097561
153600 0.000000
32000: 153600, err=0.000000%
Checking for 64000
165000 0.703030
164000 0.097561
127000 0.018898
118800 0.013468
106500 0.003756
102400 0.000000
64000: 102400, err=0.000000%
Checking for 48000
165000 1.323636
164000 0.721954
163500 0.418349
163200 0.235294
160000 0.159998
153600 0.000000
48000: 153600, err=0.000000%
Checking for 96000
165000 3.185454
164000 2.595124
163500 2.297248
163200 2.117647
162000 1.392593
160800 0.656716
160500 0.471028
160000 0.159998
153600 0.000000
96000: 153600, err=0.000000%
Checking for 192000
165000 3.185454
164000 2.595124
163500 2.297248
163200 2.117647
162000 1.392593
160800 0.656716
160500 0.471028
160000 0.159998
147600 0.097561
192000: 147600, err=0.097561%
Checking for 11025
165000 0.360727
164000 0.183413
163200 0.126468
159600 0.084210
156000 0.040002
144000 0.040001
132000 0.040000
120000 0.039998
108000 0.039996
11025: 108000, err=0.039996%
Checking for 22050
165000 0.788363
164000 0.183413
159600 0.084210
144000 0.040001
120000 0.039998
22050: 120000, err=0.039998%
Checking for 44100
165000 0.788363
164000 0.183413
147000 0.159998
144000 0.040001
44100: 144000, err=0.040001%
Checking for 88200
165000 0.788363
164000 0.183413
147000 0.159998
135600 0.092032
88200: 135600, err=0.092032%

@earlephilhower
earlephilhower merged commit 94dfb9f into master Aug 24, 2026
32 checks passed
@earlephilhower
earlephilhower deleted the brutus branch August 24, 2026 00:51
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.

Bug: I2S clocks are off by 1.3% when sample rate is 32kHz, due to rounding error.

1 participant