lpcware

Problem with the main oscillator

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by Patrick_W on Mon Apr 20 00:36:26 MST 2015
Hey guys,

it's me again. After debugging my board with the IRC i wanted to switch to the main osc.
So i wrote a function which i call at the beginning of the main function. In this function i wanted to set up the oscillator
and deactivate the PLL0 (i don't need it). The CPU should just be clocked by the main osci.


void MAIN_CLK_without_PLL(bool f_15_25MHz)
{
//first step PLL0 Setup Sequence
if(Chip_Clock_IsMainPLLConnected())
{
Chip_Clock_DisablePLL(SYSCTL_MAIN_PLL, SYSCTL_PLL_CONNECT);//disconnect PLL0
}
//second step in PLL0 Setup Sequence
if(Chip_Clock_IsMainPLLEnabled())
{
Chip_Clock_DisablePLL(SYSCTL_MAIN_PLL, SYSCTL_PLL_ENABLE);//deactivat PLL0
}
//third step in PLL0 Setup Sequence

if(f_15_25MHz)
{
LPC_SYSCTL->SCS |= SYSCTL_OSCRANGE_15_25;//Oscillator got a frequencie between 15 and 25 MHz
}else{
LPC_SYSCTL->SCS &= ~SYSCTL_OSCRANGE_15_25;
}

LPC_SYSCTL->SCS |= SYSCTL_OSCEC;//activate main oscillator
while(!Chip_Clock_IsCrystalEnabled()) {}//wait till oscillator is started correc

Chip_Clock_SetCPUClockDiv(0);//set the cpu prescaller to 1
Chip_Clock_SetMainPLLSource(SYSCTL_PLLCLKSRC_MAINOSC);

//for testing deliver the clock on CLKOUT

Chip_IOCON_PinMux(LPC_IOCON, PORT_1, PIN_27, IOCON_MODE_INACT, IOCON_FUNC1);
Chip_Clock_SetCLKOUTSource(SYSCTL_CLKOUTSRC_CPU, 1);
Chip_Clock_EnableCLKOUT();
}


After i tried this with several crystals (24MHz and 14.7456MHz) and measured on the CLKOUT Pin the frequency always had been wrong.
The crystall is connected to two 18pF Capacities.
Have i made a error in setting up the oscillator?

Any advice would be great.

Regards

Outcomes