LPC1114 timer reach to 1 microsecond

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

LPC1114 timer reach to 1 microsecond

1,173 Views
lpcware
NXP Employee
NXP Employee
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;
}
0 Kudos
Reply
4 Replies

1,042 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri Feb 03 22:09:23 MST 2012

Quote:
We are using Keil to develop.
IRC_OSC     is (24000000UL)

No. IRC = Internal RC oscillator. So how did you change it :rolleyes:
Datasheet:

Quote:
7.15.1.1 Internal RC oscillator
The IRC may be used as the clock source for the WDT, and/or as the clock that drives the PLL and subsequently the CPU. The nominal IRC frequency is 12 MHz. The IRC is trimmed to 1 % accuracy over the entire voltage and temperature range.


Quote: hkagreen
FCCO range is from 156 to 320MHz, am I right?


Yes.

If you are not sure about your setting, use CLKOUT to measure it:
//clkout 48Mhz main clock / 48 = 1MHz
 LPC_SYSCON->SYSAHBCLKCTRL|= (1<<16);     //enable IOCON
 LPC_IOCON->PIO0_1          &=~0x3F;        //reset FUNC/MODE/HYS
 LPC_IOCON->PIO0_1          |= ((1<<7)|(1<<0));//set FUNC=CLKOUT, ADMODE: DIGITAL
 LPC_SYSCON->CLKOUTCLKSEL = 0x03;        //clock source 0:IRC 1:SYSTEM 2:WD 3:MAIN
 LPC_SYSCON->CLKOUTDIV    = 48;         //set divider
 LPC_SYSCON->CLKOUTUEN    = 0;
 LPC_SYSCON->CLKOUTUEN    = 1;             //enable clkout
 while (!(LPC_SYSCON->CLKOUTUEN & 0x01));

Quote:
#define SYS_AHB_DIV_Val       2            /*

You shouldn't use a SYS_AHB_DIV_Val > 1. That's slowing down your system :eek:


Quote:
We have try to use timer16 and timer32.
When more than 400 microsecond, timer32 work well.
timer16 is out of control.

Sorry, I don't understand what you are trying to do / measuring.
0 Kudos
Reply

1,042 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by hkagreen on Fri Feb 03 20:42:32 MST 2012
Many thanks for the replies.

Hi stalisman,
We are using Keil to develop.
IRC_OSC     is (24000000UL)

Hi Zero,
We have try to use timer16 and timer32.
When more than 400 microsecond, timer32 work well.
timer16 is out of control.

SYSOSCCTRL is use 15 ~ 50MHz

It should be:
#define MAIN_PLL_PSEL            0x00000001
#define MAIN_PLL_M_Val        0x00000001

LPC_SYSCON->SYSPLLCTRL = (regVal | (MAIN_PLL_PSEL << 5) | MAIN_PLL_M_Val);

My calculation is:

M=2
P=2

Fclkin = 24M
Fclkout = 2 * 24M
FCCO = 2 * 2 * 48M = 192M

FCCO range is from 156 to 320MHz, am I right?

I found that the timer cannot reach 1 microsecond
0 Kudos
Reply

1,042 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri Feb 03 04:10:53 MST 2012
Which timer are we talking about?

Your clock setting is nonsense:

Quote:

LPC_SYSCON->SYSPLLCTRL = (regVal | (MAIN_PLL_PSEL) | MAIN_PLL_M_Val);

You're writing P_Val in M_VAL (bit 4:0), so M_VAL is 3 and LPC1114 is trying to run with FCLKOUT=4*24MHz=96 MHz and FCCO=148MHz :eek:
0 Kudos
Reply

1,042 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by stalisman on Fri Feb 03 03:56:19 MST 2012
I don't quite understand your variables ( I think your values might be breaking the FCCO limit) try and set them so that they are equivalent to PSEL = 1, MSEL = 1 and SYSAHBCLKDIV = 1.

Also shouldn't the IRC_OSC remain at 12000000UL?

If you are using CMSIS you'll need to rebuild it before rebuilding your project.
0 Kudos
Reply