PIC32MX Oscillator - Reference Clock
Last modified by Microchip on 2023/11/10 11:08
The Reference Clock can be used to drive the Serial Peripheral Interface (SPI) peripheral or to generate a clock on the Reference Clock Output (REFCLKO) pin.
The reference clock can be derived from any of the following clock sources: System Phased-Lock Loop, Primary Oscillator, Fast RC, Low-Power RC, USB Phased-Lock Loop output (96 MHz), Secondary Oscillator, System Clock, Peripheral Bus Clock, and Reference Clock input.
Each reference clock has a high-precision divider based on this formula:
- refOscDiv can be any integer from 1 to 32768,
- when refOscDiv = 0, the output clock = the input clock.
- trimValue can be any integer from 1 to 512.
// ref clock base = FRC
PLIB_OSC_ReferenceOscBaseClockSelect (OSC_ID_0, OSC_REFERENCE_1, OSC_REF_BASECLOCK_FRC);
// disable ref clock
PLIB_OSC_ReferenceOscDisable(OSC_ID_0, OSC_REFERENCE_1);
// enable ref clock
PLIB_OSC_ReferenceOscEnable(OSC_ID_0, OSC_REFERENCE_1);
// refOscDiv = 32768
PLIB_OSC_ReferenceOscDivisorValueSet (OSC_ID_0, OSC_REFERENCE_1, 32768);
// trimValue = 256
PLIB_OSC_ReferenceOscTrimSet(OSC_ID_0, OSC_REFERENCE_1, 256);
// ref clock is driven out REFCLKO pin
PLIB_OSC_ReferenceOutputEnable(OSC_ID_0, OSC_REFERENCE_1);
PLIB_OSC_ReferenceOscBaseClockSelect (OSC_ID_0, OSC_REFERENCE_1, OSC_REF_BASECLOCK_FRC);
// disable ref clock
PLIB_OSC_ReferenceOscDisable(OSC_ID_0, OSC_REFERENCE_1);
// enable ref clock
PLIB_OSC_ReferenceOscEnable(OSC_ID_0, OSC_REFERENCE_1);
// refOscDiv = 32768
PLIB_OSC_ReferenceOscDivisorValueSet (OSC_ID_0, OSC_REFERENCE_1, 32768);
// trimValue = 256
PLIB_OSC_ReferenceOscTrimSet(OSC_ID_0, OSC_REFERENCE_1, 256);
// ref clock is driven out REFCLKO pin
PLIB_OSC_ReferenceOutputEnable(OSC_ID_0, OSC_REFERENCE_1);