hi,
our microcontroller is running at 2 MHz and we want to make it 8 MHz. We also want to change prescaler to 1. How can I do that? Any help (with code) is appreciated. thanx.
Solved! Go to Solution.
Dear mehmedean,
Something like the following:
(Adjust SYNR & REFDV as required for your case - Read the manual!)
INTCR &= ~0x40; // Disable int pin (PE0)
PEAR |= 0x10; // Disable ECLK (PE4)
EnableInterrupts;
// Not using PLL Clk
CLKSEL_PLLSEL = 0;
// Assuming a 8MHz crystal
// PLL Clock = 2 * OscClk * (SYNR+1)/(REFDV+1), BUSClk = PLLClk/2
// PLL Clock = 2 * 8MHz * ( 5+1)/( 1+1) = 48 MHz, BUSClk = 24 MHz
// c.f. BUSClk = OscClk/2 = 8MHz / 2 = 4 MHz.
SYNR = 5;
REFDV = 1;
// Wait for PLL to lock
while (CRGFLG_LOCK == 0) {
}
// Change to PLL Clock
CLKSEL_PLLSEL = 1;
Note that there are external components required for the PLL. There is a calculator available here:
(or search for PLL calculator)
bye
Dear mehmedean,
Something like the following:
(Adjust SYNR & REFDV as required for your case - Read the manual!)
INTCR &= ~0x40; // Disable int pin (PE0)
PEAR |= 0x10; // Disable ECLK (PE4)
EnableInterrupts;
// Not using PLL Clk
CLKSEL_PLLSEL = 0;
// Assuming a 8MHz crystal
// PLL Clock = 2 * OscClk * (SYNR+1)/(REFDV+1), BUSClk = PLLClk/2
// PLL Clock = 2 * 8MHz * ( 5+1)/( 1+1) = 48 MHz, BUSClk = 24 MHz
// c.f. BUSClk = OscClk/2 = 8MHz / 2 = 4 MHz.
SYNR = 5;
REFDV = 1;
// Wait for PLL to lock
while (CRGFLG_LOCK == 0) {
}
// Change to PLL Clock
CLKSEL_PLLSEL = 1;
Note that there are external components required for the PLL. There is a calculator available here:
(or search for PLL calculator)
bye
Thank you pgo.
The code I used is below:
// initialize the PLL
CLKSEL_PLLSEL = 0; // Disengage PLL
PLLCTL_PLLON = 1; // Turn on PLL
SYNR = 0x07; // Set loop multiplier to 6 (SYNR = 5, mult=SYNR + 1)
REFDV = 0x00; // set input osc divider to 1 (REFDV = 0, div =REFDV+1)
_asm("nop"); _asm("nop"); // Delay for stabilization
while( CRGFLG_LOCK != 1){}; // Wait until clock circuit locks on
CLKSEL_PLLSEL = 1; // Engage PLL and go!
The code above is from somewhere on the internet .