There are two ways to configure the desired oscillator settings:
- "Core Configuration Bits" Registers
- Oscillator Special Function Registers (SFRs)
"Configuration Bits" Registers
These settings are saved in a special portion of flash memory, and are loaded at the moment power is applied to the microcontroller. By having them instantly available at power-on, we don’t need to waste time and processor cycles setting up the oscillator in our application code.
The configuration bits are defined using “#pragma config” statements using the MPLAB® C Compiler for PIC32 MCUs.
It is important to first define the signal source for the Primary Oscillator and the target system clock frequency. Following the guidelines in the datasheet, you can then determine the divider values and PLL multipliers required.
The “#pragma config” statements do not generate any executable code. Rather they define a word that is to be written into the appropriate configuration register address that matches the desired configuration option. This word will be written into the PIC32's flash memory when the device is programmed and is stored in the application's ‘.hex’ file generated by MPLAB® IDE.
To determine which options are allowed with the “#pragma config” statements refer to the ‘hlpPIC32MXConfigSet.chm’ file, and search for the exact PIC32 microcontroller you are using.
Refer to "C:\Program Files\Microchip\xc32\<ver>\docs\PIC32ConfigSet.html" for a listing of all #pragma config macros available for your MCU.
Refer to the "Special Features" section of the MCU data sheet to learn about all the configurable hardware options on the device.
OSCCON and OSCTUN SFRs
During run-time, it is possible to change the clock source, modify the oscillator settings, check the status of the various oscillator sources, and determine whether the PLLs are locked.
The Oscillator Family Reference Manual provides basic C-code examples that show how to configure these registers for specific applications.
Alternatively, you can use the MPLAB® Harmony library APIs to dynamically change oscillator configuration.