_XINFREQ
Constant: Pre-defined, one-time settable constant for specifying the external crystal frequency.
CON
_XINFREQ = Expression
- Expression is an integer expression that indicates the external crystal frequency; the frequency on the XI pin. This value is used for application start-up.
Explanation
_XINFREQ specifies the external crystal frequency, which is used along with the clock mode to determine the System Clock frequency at start-up. It is a pre-defined constant symbol whose value is determined by the top object file of an application. _XINFREQ is either set directly by the application itself, or is set indirectly as the result of the _CLKMODE and _CLKFREQ settings.
The top object file in an application (the one where compilation starts from) can specify a setting for _XINFREQ in its CON block. This, along with the clock mode, defines 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 _XINFREQ or _CLKFREQ 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 _XINFREQ settings in child objects are simply ignored by the compiler.
For example:
CON _CLKMODE = XTAL1 + PLL8X _XINFREQ = 4_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 indicates the external crystal frequency is 4 MHz, which means the System Clock's frequency will be 32 MHz because 4 MHz * 8 = 32 MHz. The _CLKFREQ value is automatically set to 32 MHz because of these declarations.
CON _CLKMODE = XTAL2 _XINFREQ = 10_000_000
These two declarations set the clock mode for an external medium-speed crystal, no Clock PLL multiplier, and an external crystal frequency of 10 MHz. The _CLKFREQ value, and thus the System Clock frequency, is automatically set to 10 MHz, as well, because of these declarations.
Unless otherwise noted, content on this site is licensed under the
Creative Commons Attribution-ShareAlike 4.0 International License.