If an external crystal (Primary Oscillator) is providing a clock source for your device, you will need to wait for the oscillator and PLL to stabilize before executing any code after a Power-on Reset (POR) or exit from sleep. If you want to start executing code before the oscillator has stabilized, you can use the "Two-Speed Start-up" option.
Two-Speed Start-up uses the internal Fast RC Oscillator (FRC) as the system clock source until the Primary Oscillator (POSC) has stabilized. This allows the CPU to begin running code while the oscillator is stabilizing. After it has stabilized, the clock source will automatically be switched to use the Primary Oscillator (POSC).
Application code will need to verify that the switch has completed.
The following MPLAB® XC16 compiler code example enables two-speed start-up (FRC to 8 MHz XTAL POSC) for a PIC24FJ128GA010 MCU:
#include <xc.h>
#pragma config FNOSC = PRI // Primary Oscillator desired
#pragma config POSCMOD = XT // XT Oscillator mode selected
#pragma config IESO = ON // Two-Speed Start-Up enabled
int main(void)
{
// compare the current OSC with new OSC - when these bits match, the clock switch is complete
while(OSCCONbits.COSC != OSCCONbits.NOSC);
...
}
The Watchdog Timer (WDT), if enabled, will continue to count at the same rate regardless of the SYSCLK frequency. Care must be taken to service the WDT during Two-Speed Start-up, taking into account the change in SYSCLK.