From 34d7f771e532ee6091b981adacc38e6d8b85a1c3 Mon Sep 17 00:00:00 2001 From: Markus Gyger <182590275+magy00@users.noreply.github.com> Date: Fri, 20 Dec 2024 19:22:42 +0700 Subject: [PATCH 1/2] Overclock to 153.6 MHz (instead of 147.6 MHz) for I2S 48 kHz sample rate --- docs/i2s.rst | 2 +- libraries/I2S/src/I2S.cpp | 6 ++---- libraries/I2S/src/I2S.h | 2 +- tools/makeboards.py | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/docs/i2s.rst b/docs/i2s.rst index 2aadcf11a..3e1e95af3 100644 --- a/docs/i2s.rst +++ b/docs/i2s.rst @@ -71,7 +71,7 @@ sample rate on-the-fly. bool setSysClk(int samplerate) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Changes the PICO system clock to optimise for the desired samplerate. -The clock changes to 147.6 MHz for samplerates that are a multiple of 8 kHz, and 135.6 MHz for multiples of 11.025 kHz. +The clock changes to 153.6 MHz for samplerates that are a multiple of 8 kHz, and 135.6 MHz for multiples of 11.025 kHz. Note that using ``setSysClk()`` may affect the timing of other sysclk-dependent functions. Should be called before any I2S functions and any other sysclk dependent initialisations. diff --git a/libraries/I2S/src/I2S.cpp b/libraries/I2S/src/I2S.cpp index d3387c3cd..b3e71659a 100644 --- a/libraries/I2S/src/I2S.cpp +++ b/libraries/I2S/src/I2S.cpp @@ -123,12 +123,10 @@ bool I2S::setFrequency(int newFreq) { bool I2S::setSysClk(int samplerate) { // optimise sys_clk for desired samplerate if (samplerate % 11025 == 0) { - set_sys_clock_khz(I2SSYSCLK_44_1, false); // 147.6 unsuccessful - no I2S no USB - return true; + return set_sys_clock_khz(I2SSYSCLK_44_1, false); } if (samplerate % 8000 == 0) { - set_sys_clock_khz(I2SSYSCLK_8, false); - return true; + return set_sys_clock_khz(I2SSYSCLK_8, false); } return false; } diff --git a/libraries/I2S/src/I2S.h b/libraries/I2S/src/I2S.h index dfb62f97e..bb60e538c 100644 --- a/libraries/I2S/src/I2S.h +++ b/libraries/I2S/src/I2S.h @@ -163,5 +163,5 @@ class I2S : public Stream, public AudioOutputBase { int _sm, _smMCLK; static const int I2SSYSCLK_44_1 = 135600; // 44.1, 88.2 kHz sample rates - static const int I2SSYSCLK_8 = 147600; // 8k, 16, 32, 48, 96, 192 kHz + static const int I2SSYSCLK_8 = 153600; // 8k, 16, 32, 48, 96, 192 kHz }; diff --git a/tools/makeboards.py b/tools/makeboards.py index 12be76360..4bf061ec1 100755 --- a/tools/makeboards.py +++ b/tools/makeboards.py @@ -39,7 +39,7 @@ def BuildDebugLevel(name): def BuildFreq(name, defmhz): out = 0 - for f in [ defmhz, 50, 100, 120, 125, 128, 133, 150, 175, 200, 225, 240, 250, 275, 300]: + for f in [ defmhz, 50, 100, 120, 125, 128, 133, 150, 153.6, 175, 200, 225, 240, 250, 275, 300]: warn = "" if f > defmhz: warn = " (Overclock)" if (out == 1) and (f == defmhz): From b94bc6bd7fa1dcf060b5a71c0093116370e40d0a Mon Sep 17 00:00:00 2001 From: Markus Gyger <182590275+magy00@users.noreply.github.com> Date: Sat, 21 Dec 2024 13:44:47 +0700 Subject: [PATCH 2/2] Remove 153.6 MHz entry from menu --- tools/makeboards.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/makeboards.py b/tools/makeboards.py index 4bf061ec1..12be76360 100755 --- a/tools/makeboards.py +++ b/tools/makeboards.py @@ -39,7 +39,7 @@ def BuildDebugLevel(name): def BuildFreq(name, defmhz): out = 0 - for f in [ defmhz, 50, 100, 120, 125, 128, 133, 150, 153.6, 175, 200, 225, 240, 250, 275, 300]: + for f in [ defmhz, 50, 100, 120, 125, 128, 133, 150, 175, 200, 225, 240, 250, 275, 300]: warn = "" if f > defmhz: warn = " (Overclock)" if (out == 1) and (f == defmhz):