I am trying to set up a 'low power' operation mode for a battery operated project but I still would like to return to full speed to perform processing routines, then back to low speed.
At the moment as a start, I am setting sim2.clock.pll_cr[REFDIV] to 1 to half the Vco frequency. This works most of the time but seems to lock up sometimes, usually after a power reset (as opposed to a soft reset)
Here's the code I'm using to set this (which is partly based on this post: http://forum.embeddedethernet.com/viewt ... ?f=7&t=512) :
Code: Select all
SerialClose(0);
// set the Fvco clock speed variable
CPU_CLOCK = 125000000;
// set PLL_CR[REFDIV] to 1
sim2.clock.pll_cr |= (1 << 8);
asm("nop"); asm("nop"); asm("nop"); // Some nops to ensure lose of clock is detected
while( ( sim2.clock.pll_sr & 0x10 ) == 0 ); // Wait for PLL lock
// Now adjust the system tick
DWORD tpmr = ( CPU_CLOCK / (128 * 2) ); // divide by 2 because we halved the Fvco by setting the REFDIV bit to 1
tpmr /= TICKS_PER_SECOND;
sim2.pit[0].pmr = ( WORD ) tpmr;
SimpleOpenSerial( 0, 9600 );
I'm looking at slowing down some other clocks in sim2.clock.pll_dr (turning some off that I don't need) but I have had less success with that and will come to it once this is working. Does anyone have any advice for the code above, or any other advice for changing system clock speed back and forth?
Thanks, (and sorry for the vague question :S)
Josh