CE012 - Dynamic Clock Switching for Low-Power Operation
by Microchip Technology
Microchip's dsPIC30F Digital Signal Controllers provide several means to reduce power consumption while the application is running.
About this Code Example
Microchip's dsPIC30F Digital Signal Controllers provide several means to reduce power consumption while the application is running. Power consumption is directly proportional to the operating MIPS. In certain applications, it may be possible to run the device at lower MIPS for a certain tasks and at higher MIPS for certain compute-intensive tasks. In such applications, one of the mechanisms available to the user to dynamically increase or decrease the system clock frequency is to switch the system clock source to either of the 32 KHz LP Oscillator, 512 KHz Internal LPRC oscillator, the 7.37 MHz Internal Fast RC oscillator or the Primary oscillator (crystal or canned oscillator). This run-time clock switching is performed by writng to the NOSC bits and the OSWEN bit in the OSCCON register.
The attached code example contains 2 C source files - main.c and clock_switch.c. The clock_switch.c file provides a clock switching function that may be used in your application to dynamically switch from one clock source to another. The function has the following prototype and description:
Function: int clockSwitch (unsigned int)
Input: int data type of a value chosen from OscillatorSystemCodes.h
file Valid values are 0,1,2,3 and for devices featuring
Oscillator System version 3, a value of 7 is also supported.
Please read the dsPIC30F Family Reference Manual
for further details.
Return: RET_CODE_OSC_SUCCESS for a successful clock switch operation
RET_CODE_OSC_ERROR for an illegal clock switch request
Description: This subroutine performs an OSCCONH unlock and then writes the
requested new oscillator source value to OSCCONH. Next, it
unlocks OSCCONL and sets the OSWEN bit to initiate a clock-
switch. The subroutine returns when OSWEN has been cleared by
hardware to indicate a successful clock switch.
The main.c file simply calls the clockSwitch() routine to switch the system clock to the Low-Power RC (LPRC) oscillator. The configuration macros in the main.c file ensure the FOSC configuration register has been set up to enable run-time clock switching.
- Current Version: 1.0.0
- Updated: Jun 23, 2012
- Downloads: 777
- Status: Released
- MPLAB Version: V8.xx or above
- C Compiler: MCC18 v3.30 or above
- Development Tools: dsPICDEM™ 1.1 Development Board
- Supported Devices: dsPIC30F6014A
- There are no reviews for this Code Example.
- CE012 - Dynamic Clock Switching for Low-Power Operation (current version) June 22, 2012
- First Release to ECS