_CLKMODE
Constant: Pre-defined, one-time settable constant for specifying application-level clock mode settings.
CON
_CLKMODE = Expression
- Expression is an integer expression made up of one or two Clock Mode Setting Constants shown in the table Clock Mode Setting Constants. This will be the clock mode upon application start-up.
Explanation
_CLKMODE is used to specify the desired nature of the System Clock. It is a pre-defined constant symbol whose value is determined by the top object file of an application. The clock mode setting is a byte whose value is described by a combination of the RCxxxx, XINPUT, XTALx and PLLxx constants at compile time. The table Clock Mode Setting Constants illustrates the clock mode setting constants. Note that not every combination is valid; the table Valid Clock Mode Expressions and CLK Register Values shows all valid combinations.
Clock Mode Setting Constants
Clock Mode Setting Constant1 | XO Resistance2 | XI/XO Capacitance2 | Description |
---|---|---|---|
RCFAST | Infinite | n/a | Internal fast oscillator (~12 MHz). May be 8 MHz to 20 MHz. (Default) |
RCSLOW | Infinite | n/a | Internal slow oscillator (~20 KHz). May be 13 KHz to 33 KHz. |
XINPUT | Infinite | 6 pF (pad only) | External clock-oscillator (DC to 80 MHz); XI pin only, XO disconnected |
XTAL1 | 2 kΩ | 36 pF | External low-speed crystal (4 MHz to 16 MHz) |
XTAL2 | 1 kΩ | 26 pF | External medium-speed crystal (8 MHz to 32 MHz) |
XTAL3 | 500 Ω | 16 pF | External high-speed crystal (20 MHz to 60 MHz) |
PLL1X | n/a | n/a | Multiply external frequency times 1 |
PLL2X | n/a | n/a | Multiply external frequency times 2 |
PLL4X | n/a | n/a | Multiply external frequency times 4 |
PLL8X | n/a | n/a | Multiply external frequency times 8 |
PLL16X | n/a | n/a | Multiply external frequency times 16 |
1All constants are also available in Propeller Assembly.
2All necessary resistors/capacitors are included in Propeller chip.
Valid Clock Mode Expressions and CLK Register Values
Valid Expression | CLK Register Value | Valid Expression | CLK Register Value |
---|---|---|---|
RCFAST | 0_0_0_00_000 | XTAL1 + PLL1X | 0_1_1_01_011 |
RCSLOW | 0_0_0_00_001 | ||
XINPUT | 0_0_1_00_010 | ||
XTAL1 | 0_0_1_01_010 0_0_1_10_010 0_0_1_11_010 | XTAL2 + PLL1X | 0_1_1_10_011 0_1_1_10_100 0_1_1_10_101 0_1_1_10_110 0_1_1_10_111 |
XINPUT + PLL1X | 0_1_1_00_011 0_1_1_00_100 0_1_1_00_101 0_1_1_00_110 0_1_1_00_111 | XTAL3 + PLL1X | 0_1_1_11_011 0_1_1_11_100 0_1_1_11_101 0_1_1_11_110 0_1_1_11_111 |
The top object file in an application (the one where compilation starts from) can specify a setting for _CLKMODE in its CON block. This defines the initial clock mode setting for the application and is the mode that the System Clock will switch to as soon as the application is booted up and execution begins. The following examples assume that they are contained within the top object file. Any _CLKMODE settings in child objects are simply ignored by the compiler. For example:
CON _CLKMODE = RCFAST
This sets the clock mode for the internal, fast RC Clock/Oscillator circuit. The System Clock would run at approximately 12 MHz with this setting. The RCFAST setting is the default setting, so if no _CLKMODE was actually defined, this is the setting that would be used. Note that the Clock PLL can not be used with the internal RC Clock/Oscillator. Here's an example with an external clock:
CON _CLKMODE = XTAL1 + PLL8X
This sets the clock mode for an external low-speed crystal (XTAL1), enables the Clock PLL circuit and sets the System Clock to use the 8x tap from the Clock PLL (PLL8X). If an external 4 MHz crystal was attached to XI and XO, for example, its signal would be multiplied by 16 (the Clock PLL always multiplies by 16) but the 8x bit result would be used; the System Clock would be 4 MHz * 8 = 32 MHz.
CON _CLKMODE = XINPUT + PLL2X
This sets the clock mode for an external clock-oscillator, connected to XI only, and enables the Clock PLL circuit and sets the System Clock to use the 2x result. If an external clock-oscillator pack of 8 MHz was attached to XI, the System clock would run at 16 MHz; that's 8 MHz * 2.
Note that the Clock PLL is not required and can be disabled by simply not specifying any multiplier setting, for example:
CON _CLKMODE = XTAL1
This sets the clock mode for an external low-speed crystal but leaves the Clock PLL disabled; the System Clock will be equal to the external crystal's frequency.
The _CLKFREQ and _XINFREQ Settings
For simplicity, the examples above only show _CLKMODE settings, but either a _CLKFREQ or _XINFREQ setting is required to follow it so that objects can determine their actual System Clock's frequency. The following is the full version of the second example, above, with an external crystal frequency (_XINFREQ) of 4 MHz.
CON _CLKMODE = XTAL1 + PLL8X 'low-speed crystal x 8 _XINFREQ = 4_000_000 'external crystal of 4 MHz
This example is exactly like the second example above, but _XINFREQ indicates that the frequency of the external crystal is 4 MHz. The Propeller chip uses this value along with the _CLKMODE setting to determine the System Clock frequency (as reported by the CLKFREQ command) so that objects can properly adjust their timing. See _XINFREQ.
_CLKMODE vs.CLKMODE
_CLKMODE is related to, but not the same as, CLKMODE. _CLKMODE is an application-defined constant containing the requested clock mode at startup (in the form of clock setting constants that are OR'd together) whereas CLKMODE is a command that returns the current clock mode (in the form of the CLK register's bit pattern). Both may describe the same logical clock mode but their values are not equivalent.
Unless otherwise noted, content on this site is licensed under the
Creative Commons Attribution-ShareAlike 4.0 International License.