Propeller Manual

Table Of Contents
2: Spin Language Reference – CLKSET
Propeller Manual v1.1 · Page 71
CLKSET
Command: Set both the clock mode and System Clock frequency at run time.
((PUB PRI))
CLKSET (Mode, Frequency)
Mode is an integer expression that will be written to the CLK register to change the
clock mode.
Frequency is an integer expression that indicates the resulting System Clock
frequency.
Explanation
One of the most powerful features of the Propeller chip is the ability to change the clock
behavior at run time. An application can choose to toggle back and forth between a slow
clock speed (for low-power consumption) and a fast clock speed (for high-bandwidth
operations), for example.
CLKSET is used to change the clock mode and frequency during run
time. It is the run-time equivalent of the
T
_CLKMODE and _CLKFREQ constants defined by the
application at compile time. For example:
clkset(%01101100, 4_000_000) 'Set to XTAL1 + PLL2x
This sets the clock mode to a low-speed external crystal and a Clock PLL multiplier of 2, and
indicates the resulting System Clock frequency (
CLKFREQ) is 4 MHz. After executing this
command, the
CLKMODE and CLKFREQ commands will report the updated settings for objects
that use them.
In general, it is safe to switch between clock modes by using a single
CLKSET command,
however, if enabling the Crystal Oscillator circuit (CLK register’s OSCENA bit) it is
important to perform the clock mode switch as a three-stage process:
1) First set the CLK register’s PLLENA, OSCENA, OSCM1 and OSCM0 bits as
necessary. See CLK Register on page 28 for more information.
2) Wait for 10 ms to give the external crystal time to stabilize.
3) Set the CLK register’s CLKSELx bits as necessary to switch the System Clock to the
new source.
The above process is only necessary when switching the Crystal Oscillator circuit on. No
other clock mode changes require this process if the Crystal Oscillator circuit is left in its