Configure PIC24E to run at 70 MIPS

Again, consult the Microchip FRM for the explanation of these commands. In essence, we put in the 3 values to the fields of corresponding register CLKDIV (notice that in the command PLLDIV is called PLLFBD; I have no idea about the inconsistent names used). Then write to OSCCON using special macros __builtin_write_ to initiate clock switch. After that we must wait for the switch to complete before leaving.

It is left to the reader to verify for the external 8 MHz crystal case that N1 = 2, N2 = 2, M = 70 yield the desired 70 MIPS FCY. Replace the previous code by this one

If (SW1)   {
       // Configure PLL prescaler, PLL postscaler, PLL divisor (primary OSC )
       PLLFBD = 68;   // M = 70
       CLKDIVbits.PLLPOST = 0;     // N2 = 2
       CLKDIVbits.PLLPRE=0;     // N1 = 2
       // initiate clock switch to primary oscillator with PLL (NOSC=0b11)
       while (OSCCONbits.COSC != 0b011);
       while (OSCCONbits.LOCK != 1);
} while (SW1);

In addition to the difference in PLLFBD values, notice the values written to OSCCONH are 0x01 and 0x03 for the FRC and primary oscillator, respectively.

To blink the LED, the following lines are added at the beginning of infinite loop in main( )

for (i=0;i<200000l;i++);

A variable i of type long is used in for() loop as a simple delay. As demonstrated in this video, the LED blinks much faster after clock switching to 70 MIPS.

You can download complete C source file at the link below. It is written to cover both cases. For FRC, uncomment the #define FRC line at the top. For external crystal, uncomment the #define PRIOSC line.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s