8-bit PIC® MCU Clock Switching
The system clock source can be switched between an internal and external source via control bits in the OSCCON register. This allows the PIC® MCU to control the speed of the operation and can also help with power reduction. A slower oscillator will draw less current than a higher-speed oscillator. During normal operation, a higher speed may be needed, but when the application is less active, a slower oscillator may be able to handle the processing duties. This will reduce power consumption. Various sleep options are available for very low power but it's often necessary to maintain continuous operation during sleep. A slower oscillator speed may be all that is required during this Sleep mode operation.
The clock switching feature on many devices can be controlled from the application software. There are three choices that can be selected for the system clock via the clock switching feature. They include:
- System Clock determined by the Fosc settings in the Configuration Word
- 8-bit PIC MCU Internal Oscillator
- 8-bit PIC MCU Timer1 Secondary Oscillator
Clock Switching Control
The Clock Switching mode is controlled by the SCS bits in the OSCCON register. These bits can be changed via software during run time to change the clock source.
When the SCS bits = 00, the system clock is switched to the clock source selected by the Fosc bits in the Configuration Register. This can be the Internal Oscillator, External Crystal/Resonator, or External Clock.
When the SCS bits = 01, the system clock is switched to the Secondary Oscillator which is an external 32.768 Khz crystal that controls the Timer1 Peripheral. The external clock crystal is an optional clock source that must be part of the Timer1 design circuit.
When the SCS bits = 10 or 11, then the system clock is switched to the Internal Oscillator independent of the Fosc configuration bit settings. The IRCF bits of the OSCCON register will select the internal oscillator frequency.
Oscillator Status Bits
When switching to a new clock source, we recommend checking the status of the clock source before switching. Each oscillator selection has a status bit in the OSCSTAT Register to indicate if it is ready or if the expected accuracy is achieved. If a device was in Sleep mode, where an oscillator may have been shut down to save power, there may be a delay in the clock source being ready for a clock switch. A check of the specific clock source status bit in the OSCSTAT register will determine if the source is ready for the clock switch.
Fosc Status
The OSTS bit indicates the status of the oscillator selected by the Fosc configuration bit settings. After a reset, the INTOSC internal oscillator may be controlling the device while the Fosc selection completes its start-up delay or even the Power-Up Timer delay. Checking the OSTS bit will indicate which oscillator is controlling the device.