Help Regarding Timer Configuration

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

Help Regarding Timer Configuration

182 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ranaya on Tue Jul 24 07:32:15 MST 2012
Hello Every1.......

  This is my timer settings for lpc1769. I have few doubts about settings and delay function.

#define CLOCK_SETUP           1
#define SCS_Val               0x00000020
#define CLKSRCSEL_Val         0x00000001
#define PLL0_SETUP            1
#define PLL0CFG_Val           0x0000000B
#define PLL1_SETUP            1
#define PLL1CFG_Val           0x00000023
#define CCLKCFG_Val           0x00000003
#define USBCLKCFG_Val         0x00000000
#define PCLKSEL0_Val          0x00000000
#define PCLKSEL1_Val          0x00000000
#define PCONP_Val             0x072887DE
#define CLKOUTCFG_Val         0x00000000


delay code :
void delayMs(uint8_t timer_num, uint32_t delayInMs)
{
  if ( timer_num == 0 )
  {
LPC_TIM0->TCR = 0x02;/* reset timer */
LPC_TIM0->PR  = 0x00;/* set prescaler to zero */
LPC_TIM0->MR0 = delayInMs * (9000000 / 1000-1);
LPC_TIM0->IR  = 0xff;/* reset all interrrupts */
LPC_TIM0->MCR = 0x04;/* stop timer on match */
LPC_TIM0->TCR = 0x01;/* start timer */
  
/* wait until delay time has elapsed */
while (LPC_TIM0->TCR & 0x01);
  }
  else if ( timer_num == 1 )
  {
LPC_TIM1->TCR = 0x02;/* reset timer */
LPC_TIM1->PR  = 0x00;/* set prescaler to zero */
LPC_TIM1->MR0 = delayInMs * (9000000 / 1000-1);
LPC_TIM1->IR  = 0xff;/* reset all interrrupts */
LPC_TIM1->MCR = 0x04;/* stop timer on match */
LPC_TIM1->TCR = 0x01;/* start timer */
  
/* wait until delay time has elapsed */
while (LPC_TIM1->TCR & 0x01);
  }
  return;
}


I found this from a CMSIS examples. As i understand from the user manual + old threads my system frequency is set to 72 MHz. At reset, timer0/1 will be activated, and By default their PCLK is set to SystemFreq/4.

So my timer will count at 18 MHz since the prescalar PR is set to 0. In that case to generate a mS delay, I need  18000 counts. So Match Register should be,

LPC_TIM0->MR0 = delayInMs * (18000000 / 1000-1);
  

instead of (9000000 / 1000-1). am I right ? or is this code correct ??? appreciate ur quick responses

Thanx
0 Kudos
1 Reply

152 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ex-kayoda on Tue Jul 24 07:43:51 MST 2012

Quote: ranaya
. am I right ? or is this code correct ??? appreciate ur quick responses

Thanx



Quick reply: Yes you are right for a 18MHz timer  and yes, this code is correct for 9MHz timer ;)
0 Kudos