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 device 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 the power consumption. Various sleep options are available for very low power but its 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
- INTOSC – Internal Oscillator
- Timer1 External 32.768 Khz clock crystal
Note: Clock Switching is a software application controlled operation and not an automatic operation. Other clock switching functions such as Fail Safe Clock Monitor and Two Speed Start-Up are automatic clock switching features that do not affect the clock switching settings.
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 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, its recommended to check 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.
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 it's start-up delay or even the Power-Up Timer delay. Checking the OSTS bit will indicate which oscillator is controlling the device.