Content originally posted in LPCWare by NXP_USA on Thu Mar 04 15:21:26 MST 2010
Quote: TomT617
Hello all,
I’m new to the arm processors. This week I’ve been playing with the LPCXpresso with the LP1343 on it. I want to configure the Clock Generation Unit to produce system clock of 72MHz. Can't seem to get it working. Does anyone know of any good examples of this. Been trying stuff like:
LPC_SYSCON->SYSOSCCTRL = 00;// 1-20MHz range + Oscillator not bypassed
LPC_SYSCON->PDAWAKECFG = 00;// enable system oscillator module
LPC_SYSCON->SYSPLLCLKSEL = 1;// PLL is input for the System oscillator
LPC_SYSCON->SYSPLLCTRL = 105;// M
LPC_SYSCON->SYSPLLCLKUEN = 1;// start clock change
Thanks,
Tom.
Hi Tom,
In a CMSIS project, the CGU would be set up by default for 72 MHz. It would be initialized by the code in the SystemInit() function in the CMSIS library file system_LPC13xx.c which is called from the Code Red startup code in cr_startup_lpc13.c.
Looking at the init code that you posted, PDRUNCFG should be used to enable the System oscillator (external crystal) and PLL instead of PDAWAKECFG.
SYSPLLCTRL should be set to 001 00101 (binary) which is 25 hex or 37 decimal. This is because the PLL needs an M value of 6 and a P value of 2 to generate 72 MHz. The layout of this register is described in section 5 of the User's Manual. To calculate M and P, see section 10 of the User's Manual for the PLL diagram. First, the 12 MHz input clock must be boosted to something between 156 MHz and less than 320 MHz. This is called the CCO clock. CCO = FCLKIN*M*P*2 = 288 MHz. Afterward, the CCO clock must be divided to generate FCLKOUT for the core. FCLK must be 72 MHz or less. FCLK = CCO/M. The process here should be to take the desired PLL output clock (FCLKOUT=72 MHz) and divide it by the input clock (FCLKIN=12 MHz) to get M (6). Now pick a P value that results in a CCO > 156 MHz remembering that CCO = FCLKOUT * P * 2.
Regarding SYSPLLCLKUEN, the PLL settings will not be updated until ENA is set to 0 and then set back to 1. In the posted code it is only set to 1.
Some more tasks that are needed (see the CGU diagram in Chapter 3):
* Select the PLL as the main clock with MAINCLKSEL
* Set the clock divider to /1 with AHBCLKDIV (this is a reset default)
Here is some sample code to set up the PLL for 72 MHz with a 12 MHz crystal. I have commented out things that are already set by default out of reset.
//LPC_SYSCON->SYSOSCCTRL = 0; // 1-20MHz range + Oscillator not bypassed
LPC_SYSCON->PDRUNCFG &=
~(1<<5); // power up system oscillator
LPC_SYSCON->SYSPLLCLKSEL = 1;// System oscillator is input for the PLL
LPC_SYSCON->SYSPLLCLKUEN = 0;// clear SYSPLLCLKUEN
LPC_SYSCON->SYSPLLCLKUEN = 1;// start pll input clock change
LPC_SYSCON->SYSPLLCTRL = 0x25;// PLL P=2, M=6 for CLKIN x 6 = 72 MHz
LPC_SYSCON->PDRUNCFG &=
~(1<<7); // power up system pll
while(!(LPC_SYSCON->SYSPLLSTAT & 0x01)); // Wait for PLL to lock
LPC_SYSCON->MAINCLKSEL = 3; // main clock = system pll clock out
LPC_SYSCON->MAINCLKUEN = 0;// clear MAINCLKUEN
LPC_SYSCON->MAINCLKUEN = 1;// start main clock change to pll output
//LPC_SYSCON->SYSAHBCLKDIV = 1; // core/peripheral clock = main clock divided by 1
// note some peripherals don't go through this divider
// see CGU divider