English
Language : 

PIC32MX440F256H-80I Datasheet, PDF (82/646 Pages) Microchip Technology – 64/100-Pin General Purpose and USB 32-Bit Flash Microcontrollers
PIC32MX3XX/4XX
case, the OSWEN bit is cleared automatically
and the clock switch is aborted.
2. The new oscillator is turned on by the hardware
if it is not currently running. If a crystal oscillator
must be turned on, the hardware will wait until
the Oscillator Start-up timer (OST) expires. If the
new source is using the PLL, then the hardware
waits until a PLL lock is detected (LOCK = 1).
3. The hardware clears the OSWEN bit to indicate
a successful clock transition. In addition, the
NOSC bit values are transferred to the COSC
Status bits.
4. The old clock source is turned off at this time if
the clock is not being used by any modules.
Note:
The processor will continue to execute
code throughout the clock switching
sequence. Timing-sensitive code should
not be executed during this time.
The following is a recommended code sequence for a
clock switch:
1. Disable interrupts and DMA prior to the system
unlock sequence.
2. Execute the system unlock sequence by writing
the Key values of 0xAA996655 and
0x556699AA to the SYSKEY register in two
back-to-back assembly or ‘C’ instructions.
3. Write the new oscillator source value to the
NOSC control bits.
4. Set the OSWEN bit in the OSCCON register to
initiate the clock switch.
5. Write a non-key value (such as 0x12345678) to
the SYSKEY register to perform a lock. Con-
tinue to execute code that is not clock-sensitive
(optional).
6. Check to see if OSWEN is ‘0’. If it is, the switch
was successful. Loop until the bit is ‘0’.
7. Re-enable interrupts and DMA.
Notes:
There are no timing requirements for the
steps other than the initial back-to-back
writing of the Key values to perform the
unlock sequence.
The unlock sequence unlocks all registers
that are secured by the lock function. It is
recommended that amount to time is the
system is unlock is kept to a minimum. The
core sequence for unlocking the OSCCON
register and initiating a clock switch is
shown in Example 4-2.
4.2.6.3 Clock Switching Considerations
When incorporating clock switching into an application,
users should keep certain things in mind when
designing their code.
• The SYSLOCK unlock sequence is timing critical.
The two Key values must be written back-to-back
with no in-between peripheral register access. To
prevent unintended peripheral register accesses,
it is recommended that all interrupts and DMA
transfers are disabled.
• The system will not relock automatically. The user
should perform the relock sequence as soon after
the clock switch as is possible.
• The unlock sequence unlocks other registers
such as the those related to Real-Time Clock
control.
• If the destination clock source is a crystal oscilla-
tor, the clock switch time will be dictated by the
oscillator start-up time.
• If the new clock source does not start, or is not
present, the OSWEN bit will remain set.
• A clock switch to a different frequency will affect
the clocks to peripherals. Peripherals may require
reconfiguration to continue operation at the same
rate as they did before the clock switch occurred.
• If the new clock source uses the PLL, a clock
switch will not occur until lock has been achieved.
• If the WDT is used, care must be taken to ensure
it can be serviced in a timely manner at the new
clock rate.
Note:
The application should not attempt to
switch to a clock with a frequency lower
than 100 kHz when the Fail-Safe Clock
Monitor is enabled. Clock switching in
these instances may generate a false
oscillator fail event and result in a switch to
the Internal Fast RC oscillator.
Note:
The device does not prevent changing the
PLL postscaler or multiplier values on the
clock source that is in use. The device will
not permit direct switching between PLL
clock sources. The user should not
change the PLL multiplier values or post-
scaler values when running from the
affected PLL source. To perform either of
the above clock switching functions, the
clock switch should be performed in two
steps. The clock source should first be
switched to a non-PLL source, such as
FRC, and then switched to the desired
source. This requirement only applies to
PLL-based clock sources.
DS61143E-page 80
Preliminary
© 2008 Microchip Technology Inc.