Datasheet

2012 Microchip Technology Inc. DS30575A-page 59
PIC18F97J94 FAMILY
A recommended code sequence for a clock switch
includes the following:
1. Disable interrupts during the OSCCON register
unlock and write sequence.
2. Clear the CLKLOCK bit (OSCCON2<7>) to
enable writes to the NOSCx bits (OSCCON<2:0>).
3. Write new oscillator source to NOSCx control bits.
4. Continue to execute code that is not
clock-sensitive (optional).
5. Invoke an appropriate amount of software delay
(cycle counting) to allow the selected oscillator
and/or PLL to start and stabilize.
6. Check to see if COSC contains the new oscillator
values that were requested in Step 3.
3.13.2.1 Clock Switching Considerations
When incorporating clock switching into an application,
users should keep certain things in mind when designing
their code.
If the new clock source is a crystal oscillator, the
clock switch time will be dominated by the
oscillator start-up time.
If the new clock source does not start, or is not
present, the clock switching hardware will wait
indefinitely for the new clock source. The user can
detect this situation because the COSCx bits will
not change to reflect the new desired oscillator
settings.
Switching to a low-frequency clock source, such
as the Secondary Oscillator, will result in very
slow device operation.
3.13.3 ACTIVE CLOCK TUNING (ACT)
MODULE
The Active Clock Tuning (ACT) module continuously
adjusts the 8 MHz internal oscillator, using an
available external reference, to achieve ± 0.20%
accuracy. This eliminates the need for a high-speed,
high-accuracy external crystal when the system has
an available lower speed, lower power, high-accuracy
clock source available. Systems implementing a
Real-Time Clock Calendar (RTCC) or a full-speed
USB application can take full advantage of the ACT
module.
3.13.3.1 Active Clock Tuning Operation
The ACT module defaults to the disabled state after
any Reset. When the ACT module is disabled, the user
can write to the TUN<6:0> bits in the OSCTUNE
register to manually adjust the 8 MHz internal oscillator.
The module is enabled by setting the ACTEN bit of the
ACTCON register. When enabled, the ACT module
takes control of the OSCTUNE register. The ACT
module uses the selected ACT reference clock to tune
the 8 MHz internal oscillator to an accuracy of 8 MHz ±
0.2%. The tuning automatically adjusts the OSCTUNE
register every reference clock cycle.
3.13.3.2 Active Clock Tuning Source
Selection
The ACT reference clock is selected with the ACTSRC
bit of the ACTCON register. The reference clock
sources are provided by the:
USB module in full-speed operation (ACT_clk)
Secondary clock at 32.768 kHz (SOSC_clk)
3.13.3.3 ACT Lock Status
The ACTLOCK bit will be set to1’, when the 8 MHz
internal oscillator is successfully tuned.
The bit will be cleared by the following conditions:
Out of Lock condition
Device Reset
Module is disabled
3.13.3.4 ACT Out-of-Range Status
If the ACT module requires an OSCTUNE value
outside the range to achieve ± 0.20% accuracy, then
the ACT Out-of-Range (ACTORS) Status bit will be set
to ‘1’.
An out-of-range status can occur:
When the 8 MHZ internal oscillator is tuned to its
lowest frequency and the next ACT_clk event
requests a lower frequency.
When the 8 MHZ internal oscillator is tuned to its
highest frequency and the next ACT_clk event
requests a higher frequency.
When the ACT out-of-range event occurs, the 8 MHz
internal oscillator will continue to use the last written
OSCTUNE value. When the OSCTUNE value moves
back within the tunable range and ACTLOCK is
established, the ACTORS bit is cleared to ‘0’.
Note: The application should not attempt to
switch to a clock with a frequency lower
than 100 kHz when the FSCM is enabled.
Clock switching in these instances may
generate a false oscillator fail trap and
result in a switch to the Internal Fast RC
Oscillator.