type Clock_Id is
(GPOUT0, GPOUT1, GPOUT2, GPOUT3, REF, SYS, PERI, USB, ADC, RTC,
PLL_SYS, GPIN0, GPIN1, PLL_USB, ROSC, XOSC);
procedure Configure_PLL
(PLL : PLL_Clock_Id;
Config : PLL_Config)
Remember to switch clk_sys to another source before modifying PLL_SYS
subtype Countable_Clock_Id is Clock_Id range REF .. RTC;
By default, the fractional part of the frequency counter result register is ignored. Setting Rounded = False includes the fractional frequency, which may include as much as 2048 KHz of error, depending on the value of Accuracy. Higher Accuracy values take longer to measure the clock, but produce more accurate results.
procedure Disable
(CID : Clock_Id)
procedure Enable
(CID : Clock_Id)
function Enabled
(CID : Clock_Id)
return Boolean
function Frequency
(CID : Countable_Clock_Id;
Rounded : Boolean := True;
Accuracy : UInt4 := 15)
return Hertz
By default, the fractional part of the frequency counter result register is ignored. Setting Rounded = False includes the fractional frequency, which may include as much as 2048 KHz of error, depending on the value of Accuracy. Higher Accuracy values take longer to measure the clock, but produce more accurate results.
GP_Divider_Fraction : constant := 1.0 / (2 ** 8);
If GP_Divider is 0.0, then it represents (2.0 ** 16)
subtype GP_Output is Clock_Id range GPOUT0 .. GPOUT3;
subtype GP_Source is Clock_Id range REF .. XOSC;
procedure Initialize
(XOSC_Frequency : XOSC_Hertz := 0;
XOSC_Startup_Delay : XOSC_Cycles := 770_048)
See 2.16.3 Startup Delay for XOSC_Startup_Delay calculation. The default value is approximately 1ms with a 12 MHz crystal.
~64ms with a 12 MHz crystal
PLL_125_MHz : constant PLL_Config :=
(FREF => 12_000_000,
REFDIV => 1,
FBDIV => 125,
POSTDIV1 => 6,
POSTDIV2 => 2);
PLL_133_MHz : constant PLL_Config :=
(FREF => 12_000_000,
REFDIV => 1,
FBDIV => 133,
POSTDIV1 => 6,
POSTDIV2 => 2);
PLL_250_MHz : constant PLL_Config :=
(FREF => 12_000_000,
REFDIV => 1,
FBDIV => 125,
POSTDIV1 => 6,
POSTDIV2 => 1);
PLL_48_MHz : constant PLL_Config :=
(FREF => 12_000_000,
REFDIV => 1,
FBDIV => 64,
POSTDIV1 => 4,
POSTDIV2 => 4);
subtype PLL_Clock_Id is Clock_Id
with Static_Predicate => PLL_Clock_Id in PLL_SYS | PLL_USB;
2.18.2. Calculating PLL parameters PLL = (FREF / REFDIV) * FBDIV / (POSTDIV1 / POSTDIV2) Common configurations are included below. Use pico-sdk/src/rp2_common/hardware_clocks/scripts/vcocalc.py
type PLL_Config is record
FREF : PLL_FREF_Field;
REFDIV : PLL_REFDIV_Field;
FBDIV : PLL_FBDIV_Field;
POSTDIV1 : PLL_POSTDIV_Field;
POSTDIV2 : PLL_POSTDIV_Field;
end record;
2.18.2. Calculating PLL parameters PLL = (FREF / REFDIV) * FBDIV / (POSTDIV1 / POSTDIV2) Common configurations are included below. Use pico-sdk/src/rp2_common/hardware_clocks/scripts/vcocalc.py
subtype PLL_FBDIV_Field is UInt12 range 16 .. 320;
2.18.2. Calculating PLL parameters PLL = (FREF / REFDIV) * FBDIV / (POSTDIV1 / POSTDIV2) Common configurations are included below. Use pico-sdk/src/rp2_common/hardware_clocks/scripts/vcocalc.py
subtype PLL_FREF_Field is Hertz range 5_000_000 .. 800_000_000;
2.18.2. Calculating PLL parameters PLL = (FREF / REFDIV) * FBDIV / (POSTDIV1 / POSTDIV2) Common configurations are included below. Use pico-sdk/src/rp2_common/hardware_clocks/scripts/vcocalc.py
subtype PLL_POSTDIV_Field is UInt3 range 1 .. 7;
2.18.2. Calculating PLL parameters PLL = (FREF / REFDIV) * FBDIV / (POSTDIV1 / POSTDIV2) Common configurations are included below. Use pico-sdk/src/rp2_common/hardware_clocks/scripts/vcocalc.py
subtype PLL_REFDIV_Field is UInt6 range 1 .. 63;
2.18.2. Calculating PLL parameters PLL = (FREF / REFDIV) * FBDIV / (POSTDIV1 / POSTDIV2) Common configurations are included below. Use pico-sdk/src/rp2_common/hardware_clocks/scripts/vcocalc.py
function ROSC_Frequency return Hertz
procedure Set_Divider
(GP : GP_Output;
Div : GP_Divider)
procedure Set_Source
(GP : GP_Output;
Source : GP_Source)
GP will glitch if enabled while changing sources
procedure Set_SYS_Source
(Source : SYS_Clock_Id)
subtype SYS_Clock_Id is Clock_Id range PLL_SYS .. XOSC;
subtype XOSC_Cycles is Natural;
subtype XOSC_Hertz is Hertz range 0 .. 15_000_000
with Static_Predicate => XOSC_Hertz in 0 | 1_000_000 .. 15_000_000;
The special value 0 indicates that the XOSC is not available.