lpcware

Help Regarding Timer Configuration

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
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

Outcomes