Electronic – Implementing dynamic frequency scaling on PIC32 by changing PLL multiplier/divider

low-powerpicpll

I read in the PIC32 Reference Manual that one can change the PLL multiplier and divider at run-time, provided that the input frequency is between 4 and 5 MHz and the resulting frequency does not exceed device specifications. Does this mean that one can use this to implement a dynamic frequency scaling scheme to save power (taking ino account PLL switching time and lock)

Thanks

Best Answer

Yes, you can switch the clock speed of the PIC32MX dynamically.

The easiest way is to use the OSCConfig call in the PIC32 Peripheral Libraries, since it switches the clock temporarily to the FRC mode before switching back to one of the other clock modes, including PLL. So you don't have to explicitly switch to FRC mode first, like you would have to do if you were writing directly to the clock mode fields. You do need to disable interrupts around the call though.

Here is an example:

    #include <p32xxxx.h>
    #include <plib.h>
       .
       .
       .
    INTDisableInterrupts();
    OSCConfig(OSC_POSC_PLL, OSC_PLL_MULT_15, OSC_PLL_POST_1, 0);
    INTEnableInterrupts();

The various constants are listed in the documentation for the OSCConfig call.

Danger, Will Robinson! The code example Microchip shows in their documentation is wrong, so if you cut and paste from the documentation, it won't compile! The example uses OscConfig instead of OSCConfig. The latter is correctly used in the rest of their documentation.

I found the documentation for the PIC32 Peripheral Libraries is in this document. Oddly, I couldn't find the PDF on the Microchip site. There is a compiled help file with the same information in the Microchip\MPLAB C32 Suite\doc folder, but I like the PDF better.

You don't have to install anything to use their peripheral library, as it comes with the PIC32 compiler. NOTE: I am using an older compiler, pic32-gcc.exe v2.01, so it is possible the call has changed, but I doubt it for compatibility with older code.