LPC824 System Oscillator 24MHz, clock setup issues

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC824 System Oscillator 24MHz, clock setup issues

Jump to solution
958 Views
sanders7284
Contributor III

Hello, having trouble setting up to run off an external oscillator 24MHz, used MCUXpresso Config Tools v11 to produce some code but I can't use it directly as the project was generated with V1 SDKs so been trying to map it across with little success. The datasheet and user manual are unclear on if the PPL needs to be setup if you are just pointing the main clock to the input? 

MCUXpresso Config Tools v11 suggested code 

void BOARD_BootClockRUN(void)
{
/*!< Set up the clock sources */
/*!< Set up IRC */
POWER_DisablePD(kPDRUNCFG_PD_IRC_OUT); /*!< Ensure IRC OUT is on */
POWER_DisablePD(kPDRUNCFG_PD_IRC); /*!< Ensure IRC is on */
POWER_DisablePD(kPDRUNCFG_PD_SYSOSC); /*!< Ensure SYSOSC is on */
CLOCK_InitSysOsc(24000000U); /*!< Set main osc freq */
CLOCK_Select(kSYSPLL_From_SysOsc); /*!< set sysosc to pll select */
clock_sys_pll_t config;
config.src=kCLOCK_SysPllSrcSysosc; /*!< set pll src */
config.targetFreq = 24000000U; /*!< set pll target freq */
CLOCK_InitSystemPll(&config); /*!< set parameters */
CLOCK_SetMainClkSrc(kCLOCK_MainClkSrcSysPllin); /*!< select pllin for main clock */
CLOCK_Select(kCLKOUT_From_Irc); /*!< select IRC for CLKOUT */
CLOCK_SetCoreSysClkDiv(1U);
POWER_EnablePD(kPDRUNCFG_PD_IRC_OUT); /*!< Disable IRC OUT */
POWER_EnablePD(kPDRUNCFG_PD_IRC); /*!< Disable IRC */
/*!< Set SystemCoreClock variable. */
SystemCoreClock = BOARD_BOOTCLOCKRUN_CORE_CLOCK;
}

My version of code 

void Setup_Clock(uint8_t MSel, uint8_t PSel)
{
//No bypass and higher freq range
Chip_Clock_SetPLLBypass(FALSE, TRUE);

//Turn on the SYS OSC by clearing the power down bit
Chip_SYSCTL_PowerUp(SYSCTL_SLPWAKE_SYSOSC_PD);

//Select the PLL input in the extern ocs
Chip_Clock_SetSystemPLLSource(SYSCTL_PLLCLKSRC_SYSOSC);

//Setup FLASH access to 2 clocks (up to 30MHz)
Chip_FMC_SetFLASHAccess(FLASHTIM_30MHZ_CPU);

//Power down PLL to change the PLL divider ratio
Chip_SYSCTL_PowerDown(SYSCTL_SLPWAKE_SYSPLL_PD);

//Configure the PLL M and P dividers
Chip_Clock_SetupSystemPLL(MSel, PSel);

//Turn on the PLL by clearing the power down bit
Chip_SYSCTL_PowerUp(SYSCTL_SLPWAKE_SYSPLL_PD);

//Wait for PLL to lock
while (Chip_Clock_IsSystemPLLLocked() == FALSE)
{
}

//Set system clock divider to 1
Chip_Clock_SetSysClockDiv(1);

//Set main clock source to the system PLL IN
Chip_Clock_SetMainClockSource(SYSCTL_MAINCLKSRC_PLLIN);
SystemCoreClockUpdate();
}

I am sure I am missing something obvious, any help would be gratefully received.

Labels (1)
Tags (1)
0 Kudos
1 Solution
909 Views
sanders7284
Contributor III

This code now works, issue put down to GPIO pinmode, and active pull up or pull downs? 

 

void SetForExtrnlXtal (void)
{
uint32_t reg;
//sys osc bypass options
#define SYSOSC_BYPASS_DISABLE 0
#define SYSOSC_BYPASS_ENABLE 1
#define LO_FREQ_XTAL 0 // set when xtal in range of 1 - 20MHz
#define HI_FREQ_XTAL 1 // set when xtal in range of 15 - 25MHz

//CRTSTAL PIN - pins 8 and 9 set for external crystal
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM); // Enable the clock to the Switch Matrix to save power
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_IOCON); // Enable clk for IO config
Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, PORT0, 8, GPIO_INPUT); // Set port p0.8 to input for XTAL IN
Chip_IOCON_PinSetMode(LPC_IOCON, IOCON_PIO8, PIN_MODE_INACTIVE);
Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, PORT0, 9, GPIO_INPUT); // Set port p0.9 to input for XTAL OUT
Chip_IOCON_PinSetMode(LPC_IOCON, IOCON_PIO9, PIN_MODE_INACTIVE);
Chip_SWM_EnableFixedPin(SWM_FIXED_XTALIN);
Chip_SWM_EnableFixedPin(SWM_FIXED_XTALOUT);
Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM); // Disable the clock to the Switch Matrix to save power
Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_IOCON); // done with the general port pins
// Going to use internal OScillator with external crystal, set frequency range as appropriate
Chip_Clock_SetPLLBypass(SYSOSC_BYPASS_DISABLE , HI_FREQ_XTAL); // (bool bypass, bool highfr)

//power up sys osc
Chip_SYSCTL_PowerUp(SYSCTL_SLPWAKE_SYSOSC_PD); // power up oscillator
//delay for power up
for (reg=0; reg<200; reg++) // give some time to stabilise
asm("nop");

// Set PLL Source to external crystal
Chip_Clock_SetSystemPLLSource(SYSCTL_PLLCLKSRC_SYSOSC);
for (reg=0; reg<200; reg++) // give some time to stabilise
asm("nop");

// Set main clock
Chip_Clock_SetMainClockSource(SYSCTL_MAINCLKSRC_PLLIN); // ???? (CHIP_SYSCTL_CLKOUTSRC_T src, uint32_t div)
while (!(LPC_SYSCTL->MAINCLKUEN&0x01));
//set system clock divider
LPC_SYSCTL->SYSAHBCLKDIV = 1;
}

View solution in original post

3 Replies
910 Views
sanders7284
Contributor III

This code now works, issue put down to GPIO pinmode, and active pull up or pull downs? 

 

void SetForExtrnlXtal (void)
{
uint32_t reg;
//sys osc bypass options
#define SYSOSC_BYPASS_DISABLE 0
#define SYSOSC_BYPASS_ENABLE 1
#define LO_FREQ_XTAL 0 // set when xtal in range of 1 - 20MHz
#define HI_FREQ_XTAL 1 // set when xtal in range of 15 - 25MHz

//CRTSTAL PIN - pins 8 and 9 set for external crystal
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM); // Enable the clock to the Switch Matrix to save power
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_IOCON); // Enable clk for IO config
Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, PORT0, 8, GPIO_INPUT); // Set port p0.8 to input for XTAL IN
Chip_IOCON_PinSetMode(LPC_IOCON, IOCON_PIO8, PIN_MODE_INACTIVE);
Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, PORT0, 9, GPIO_INPUT); // Set port p0.9 to input for XTAL OUT
Chip_IOCON_PinSetMode(LPC_IOCON, IOCON_PIO9, PIN_MODE_INACTIVE);
Chip_SWM_EnableFixedPin(SWM_FIXED_XTALIN);
Chip_SWM_EnableFixedPin(SWM_FIXED_XTALOUT);
Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM); // Disable the clock to the Switch Matrix to save power
Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_IOCON); // done with the general port pins
// Going to use internal OScillator with external crystal, set frequency range as appropriate
Chip_Clock_SetPLLBypass(SYSOSC_BYPASS_DISABLE , HI_FREQ_XTAL); // (bool bypass, bool highfr)

//power up sys osc
Chip_SYSCTL_PowerUp(SYSCTL_SLPWAKE_SYSOSC_PD); // power up oscillator
//delay for power up
for (reg=0; reg<200; reg++) // give some time to stabilise
asm("nop");

// Set PLL Source to external crystal
Chip_Clock_SetSystemPLLSource(SYSCTL_PLLCLKSRC_SYSOSC);
for (reg=0; reg<200; reg++) // give some time to stabilise
asm("nop");

// Set main clock
Chip_Clock_SetMainClockSource(SYSCTL_MAINCLKSRC_PLLIN); // ???? (CHIP_SYSCTL_CLKOUTSRC_T src, uint32_t div)
while (!(LPC_SYSCTL->MAINCLKUEN&0x01));
//set system clock divider
LPC_SYSCTL->SYSAHBCLKDIV = 1;
}

917 Views
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @sanders7284,

I'm very sorry about the tardy response. Is there any reason why you can't migrate to the newer version, instead of trying to implement the code in the old one? Our recommendation is to always update the software to the latest version.

That said, there is a basic configuration guide in the User Manual of said device found here: LPC82X | NXP Semiconductors. It is located in chapter 5.3 (Basic configuration);

"The PLL creates a stable output clock at a higher frequency than the input clock. If you
need a main clock with a frequency higher than the 12 MHz IRC clock, use the PLL to
boost the input frequency"

Hope you find this useful, and again, sorry for the late response.

Best regards, Julian

0 Kudos
912 Views
sanders7284
Contributor III

Thanks Julian, 

I can't update the SDK as this project is based on an existing one with ten's of millions of service hours and industry approvals. 

I don't actually need the PLL as I have a 24MHz external oscillator, but it looks like you can only route this in the 824 as PLLIN (the 844 & 845 have exeocs linkage), so my question was can you use PLLIN without the PLL being set up? 

 In effect I want this 

paulsanders_0-1660636098351.png

As that did not seem to work, I thought maybe the PLL needs to be active to use PLLIN? 

0 Kudos