PIC32MZ Oscillator - Reference Clock
Reference Clock
There are 4 reference clocks in the PIC32MZ devices. They can be used to drive peripherals or an output Reference Clock pin (REFCLKOx).
The Reference Clock can be derived from any of the following clock sources: System PLL, Primary Osc, Fast RC, Low Power RC, Backup RC, Secondary Osc, System Clock, Peripheral Bus #1, 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 #1 base = FRC
PLIB_OSC_ReferenceOscBaseClockSelect (OSC_ID_0, OSC_REFERENCE_1, OSC_REF_BASECLOCK_FRC);
// disable ref clock #2
PLIB_OSC_ReferenceOscDisable(OSC_ID_0, OSC_REFERENCE_2);
// enable ref clock #3
PLIB_OSC_ReferenceOscEnable(OSC_ID_0, OSC_REFERENCE_3);
// refOscDiv #4 = 32768
PLIB_OSC_ReferenceOscDivisorValueSet (OSC_ID_0, OSC_REFERENCE_4, 32768);
// trimValue #1 = 256
PLIB_OSC_ReferenceOscTrimSet(OSC_ID_0, OSC_REFERENCE_1, 256);
// ref clock #3 is driven out REFCLKO3 pin
PLIB_OSC_ReferenceOutputEnable(OSC_ID_0, OSC_REFERENCE_3);

