A new LPCOpen Version 2.12 for boards using LPC18xx and LPC43xx MCUs, available <a href="http://www.lpcware.com/content/nxpfile/lpcopen-platform">here</a>.
For change log please visit the <a href="http://www.lpcware.com/content/project/lpcopen-software-development-platform-nxp-lpc-microcontroller...">History page</a>.
// set PLL1 frequency directly (crystal osc. must be already enabled and running) Chip_Clock_SetupMainPLL_mch(CLKIN_CRYSTAL,100000000); // update clock variable SystemCoreClockUpdate(); |
/* Directly set the PLL1 frequency
*
* Input Clock is divided by 3 to obtain a finer range.
* For 12MHz crystal we can thus get CCO frequencies that are a multiple of 4 in the range from 156 to 320 MHz.
* This is important if Ethernet is used, because we want to have a 50 MHz clkout signal for the PHY chip.
* We can derive that frequency if we use 50/100/150/200 MHz as the PLL1 output clock.
*/
uint32_t Chip_Clock_SetupMainPLL_mch(CHIP_CGU_CLKIN_T Input, uint32_t fout)
{
volatile uint32_t delay = 250;
uint32_t PLL1Reg, cco, msel, nsel = 2, psel;
uint32_t fin = Chip_Clock_GetClockInputHz(Input)/(nsel+1);
// sanity checks
if ((fout>204000000) || (fout <10000000)) return 0;
// determine required postscaler
cco=fout;
psel=0;
if (fout < 156000000)
{
cco*=2;
for (; cco<156000000; cco*=2)
{
psel++;
}
}
// determine M
msel=cco/fin-1;
// now set up new loop parameters without direct mode on
PLL1Reg = (Input << 24) | (msel << 16) | (nsel << 12) | (1 << 11) | (psel << 8);
LPC_CGU->PLL1_CTRL = PLL1Reg;
// wait until PLL1 has locked
while (!Chip_Clock_MainPLLLocked());
// if f>156 MHz use direct output (no postscaler)
if (fout > 156000000)
{
PLL1Reg |= (1<<7);
LPC_CGU->PLL1_CTRL = PLL1Reg;
}
/* Wait for 50uSec */
while(delay--) {}
return Chip_Clock_GetMainPLLHz();
}
|