English
Language : 

PIC24FJ256GA705 Datasheet, PDF (4/10 Pages) –
PIC24FJ256GA705 FAMILY
4. Module: Primary XT and HS Oscillator
(POSC)
The Primary Oscillator Start-up Timer (OST)
may indicate the oscillator is ready for use too
early. Clocking the device before the oscillator is
ready may result in incorrect execution and
exceptions. This issue exists when the POSC is
requested at power-on, during clock switching,
when waking from Sleep or when a peripheral
module requests the POSC directly. This issue
affects XT and HS modes only.
Work around
Make sure that the Primary Oscillator clock is
ready before using it by following these steps:
1. Running on a non-POSC source, request
the POSC clock using a peripheral such as
REFO.
2. Provide a delay to stabilize the POSC.
3. Switch to the POSC source.
Example 1 shows a work around for the device
power-on and Example 2 explains the work
around when the device wakes from Sleep.
EXAMPLE 1: USING POSC AT POWER-ON
#pragma config FNOSC = FRC
// Oscillator Selection bits (Fast RC oscillator (FRC))
// Clock Switching Enabled (Failsafe Clock Monitor can be enabled or disabled)
#pragma config FCKSM = CSECMD
----------------------------------------------
int
main()
{
// configure REFO to request POSC
REFOCONLbits.ROSEL = 2;
// POSC
REFOCONLbits.ROOUT = 0;
// disable output
REFOCONLbits.ROEN = 1;
// enable module
// wait for POSC stable clock
// this delay may vary depending on different application conditions
// such as voltage, temperature, layout, XT or HS mode and components
{ // delay for 9 ms
unsigned int delayms = 9;
while(delayms--) asm volatile("repeat #(8000000/1000/2) \n nop");
}
// switch to POSC = 2
__builtin_write_OSCCONH(2);
__builtin_write_OSCCONL(1);
while(OSCCONbits.OSWEN == 1);
// wait for switch
DS80000718B-page 4
 2016 Microchip Technology Inc.