At the heart of the PIC® MCU is the oscillator module. The oscillator is the heartbeat or system clock source that makes the device run. The oscillator module has a wide variety of clock sources and selection features that allow it to be used in many applications while maximizing performance and minimizing power consumption.
Clock sources can be supplied from external oscillators, quartz crystal resonators, ceramic resonators and Resistor-Capacitor (RC) circuits. In addition, the system clock source can be supplied from one of two internal oscillators.
The oscillator module can be configured in one of the following clock modes:
- ECL – External Clock Low-Power mode (0 MHz to 0.5 MHz)
- ECM – External Clock Medium-Power mode (0.5 MHz to 4 MHz)
- ECH – External Clock High-Power mode (4 MHz to 32 MHz)
- LP – 32 kHz Low-Power Crystal mode
- XT – Medium Gain Crystal or Ceramic Resonator Oscillator mode (up to 4 MHz)
- HS – High Gain Crystal or Ceramic Resonator mode (4 MHz to 20 MHz)
- EXTRC – External Resistor-Capacitor
- INTOSC – Internal Oscillator (31 kHz to 32 MHz)
Clock Source modes are selected by the FOSC<2:0> bits in a Configuration Word. The FOSC bits determine the type of oscillator that will be used when the device is first powered.
The ECH, ECM, and ECL clock modes rely on an external logic level signal as the device clock source.
The LP, XT, and HS clock modes require an external crystal or resonator to be connected to the device. Each mode is optimized for a different frequency range.
The EXTRC clock mode requires an external resistor and capacitor to set the oscillator frequency.
The INTOSC internal oscillator block produces low, medium, and high-frequency clock sources, designated LFINTOSC, MFINTOSC and HFINTOSC. A wide selection of device clock frequencies may be derived from these three clock sources.
A block diagram showing a typical Oscillator Module structure is below (captured from PIC16F1713):
Additional Enhancements to the Oscillator
The Oscillator Module has additional features that enhance the operation. These include:
- 4x PLL
- Clock Switch
- Two-Speed Start-up
- FSCM - Fail-Safe Clock Monitor
- OST - Oscillator Start-up Timer
PLL uses a Phase Locked Loop to boost the oscillator speed by 4x. PLL is enabled by the PLLEN bit in a configuration word.
Clock Switching allows software to change the clock source between internal and external sources.
Two Speed Start-up can eliminate the external oscillator start-up time and also reduce overall power consumption of the device. This is very handy in applications that use the sleep function. The application can perform a few instructions using the internal oscillator and then return to sleep without having to wait for the external oscillator to become stable.
Fail Safe Clock Monitor allows the device to keep operating if the external oscillator should fail.
Oscillator Start-up Timer ensures the external crystal is stable when instructions begin executing.
Instruction Clock vs Oscillator
The 8-bit PIC® MCU system clock is always designated as Fosc in data sheets. The instruction clock is derived from the Fosc through a divider to deliver an instruction clock of Fosc/4 (1/4 the oscillator speed). This is done to allow the fetch and execute pipeline in the architecture to execute one assembly instruction per instruction clock cycle (except for branches and goto's which execute in two).
If a higher speed than a divide by four instruction clock is needed, then many devices have a 4x PLL option to boost the Fosc up by four which is later divided back down by four for the instruction clock. This will yield an instruction clock equal to the Fosc speed.