8-bit PIC® MCU Clock Switching

Last modified by Microchip on 2023/11/22 16:33

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:

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.

1 clock switching

Back to top

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.

2 clock switching

3 clock switching

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 OscillatorExternal 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.

Back to top

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.

4 clock switching

5 clock switching

Back to top

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.

Tip: For more information on 8-bit oscillator options, visit the "8-bit PIC® MCU Oscillator Options" page.

Back to top