Content originally posted in LPCWare by hkagreen on Fri Feb 03 03:24:29 MST 2012
Hi all,
We have question on the timer of LPC1114.
We use 24M Crystal, test the timer, it only around 17 microsecond.
PLL is 48M.
My setting as follow.
Is there any method to let LPC1114 reach to 1 microsecond?
Many thanks
//------------------------------------------------------------------------
//code
#define CLOCK_SETUP 1
#define MAIN_PLL_SETUP 33
#define MAIN_CLKSRCSEL_Val 0x00000001
#define MAIN_PLL_PSEL 0x00000002
#define MAIN_PLL_M_Val 0x00000001
#define MAIN_PLL_P_Val 0x00000007
#define SYS_AHB_DIV_Val 2 /* 1 through 255, typical is 1 or 2 or 4 */
#define XTAL (24000000UL) /* Oscillator frequency */
#define OSC_CLK ( XTAL) /* Main oscillator frequency */
#define IRC_OSC (24000000UL) /* Internal RC oscillator frequency */
#define WDT_OSC ( 250000UL) /* WDT oscillator frequency */
/*----------------------------------------------------------------------------
Clock Variable definitions
*----------------------------------------------------------------------------*/
uint32_t ClockSource = IRC_OSC;
uint32_t SystemFrequency = IRC_OSC; /*!< System Clock Frequency (Core Clock) */
uint32_t SystemAHBFrequency = IRC_OSC;
void Main_PLL_Setup ( void )
{
uint32_t regVal;
ClockSource = OSC_CLK;
LPC_SYSCON->SYSPLLCLKSEL = MAIN_CLKSRCSEL_Val; /* Select system OSC */
LPC_SYSCON->SYSPLLCLKUEN = 0x01; /* Update clock source */
LPC_SYSCON->SYSPLLCLKUEN = 0x00; /* toggle Update register once */
LPC_SYSCON->SYSPLLCLKUEN = 0x01;
while ( !(LPC_SYSCON->SYSPLLCLKUEN & 0x01) ); /* Wait until updated */
regVal = LPC_SYSCON->SYSPLLCTRL;
regVal &= ~0x1FF;
LPC_SYSCON->SYSPLLCTRL = (regVal | (MAIN_PLL_PSEL) | MAIN_PLL_M_Val);
/* Enable main system PLL, main system PLL bit 7 in PDRUNCFG. */
LPC_SYSCON->PDRUNCFG &= ~(0x1<<7);
while ( !(LPC_SYSCON->SYSPLLSTAT & 0x01) ); /* Wait until it's locked */
LPC_SYSCON->MAINCLKSEL = 0x03; /* Select PLL clock output */
LPC_SYSCON->MAINCLKUEN = 0x01; /* Update MCLK clock source */
LPC_SYSCON->MAINCLKUEN = 0x00; /* Toggle update register once */
LPC_SYSCON->MAINCLKUEN = 0x01;
while ( !(LPC_SYSCON->MAINCLKUEN & 0x01) ); /* Wait until updated */
LPC_SYSCON->SYSAHBCLKDIV = SYS_AHB_DIV_Val; /* SYS AHB clock, typical is 1 or 2 or 4 */
SystemFrequency = ClockSource * (MAIN_PLL_M_Val+1);
SystemAHBFrequency = (uint32_t) (SystemFrequency/SYS_AHB_DIV_Val);
return;
}