_CLKFREQ

Constant: Pre-defined, one-time settable constant for specifying the System Clock frequency.

CON
  _CLKFREQ = Expression

  • Expression is an integer expression that indicates the System Clock frequency upon application start-up.

Explanation

_CLKFREQ specifies the System Clock frequency for start-up. It is a pre-defined constant symbol whose value is determined by the top object file of an application. _CLKFREQ is either set directly by the application itself, or is set indirectly as the result of the _CLKMODE and _XINFREQ settings.

The top object file in an application (the one where compilation starts from) can specify a setting for _CLKFREQ in its CON block. This defines the initial System Clock frequency for the application and is the frequency that the System Clock will switch to as soon as the application is booted up and execution begins.

The application can specify either _CLKFREQ or _XINFREQ in the CON block; they are mutually exclusive and the non-specified one is automatically calculated and set as a result of specifying the other.

The following examples assume that they are contained within the top object file. Any _CLKFREQ settings in child objects are simply ignored by the compiler.

For example:

CON
  _CLKMODE = XTAL1 + PLL8X
  _CLKFREQ = 32_000_000

The first declaration in the above CON block sets the clock mode for an external low-speed crystal and a Clock PLL multiplier of 8. The second declaration sets the System Clock frequency to 32 MHz, which means the external crystal's frequency must be 4 MHz because 4 MHz * 8 = 32 MHz. The _XINFREQ value is automatically set to 4 MHz because of these declarations.

CON
  _CLKMODE = XTAL2
  _CLKFREQ = 10_000_000 

These two declarations set the clock mode for an external medium-speed crystal, no Clock PLL multiplier, and a System Clock frequency of 10 MHz. The _XINFREQ value is automatically set to 10 MHz, as well, because of these declarations.

_CLKFREQ vs CLKFREQ

_CLKFREQ is related to, but not the same as, CLKFREQ. _CLKFREQ contains the application's System Clock frequency at startup whereas CLKFREQ is a command that returns the current System Clock frequency. In other words, _CLKFREQ is the original System Clock frequency and CLKFREQ is the current System Clock frequency; they both may happen to be the same value but they certainly can be different.

Unless otherwise noted, content on this site is licensed under the
Creative Commons Attribution-ShareAlike 4.0 International License.