LPC1313 16-bit timer 0 MR register value

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

LPC1313 16-bit timer 0 MR register value

Jump to solution
1,837 Views
prachipanse
Contributor III

Hi,

I need to set the timer CT16B0 to generate an interrupt every 10ms. The system clock is 12MHz and I am using the prescalar value of 6. I am writing 2000 (4E20h) to the MR0 register (i.e. 10ms * 12MHz / 6).

However, with this I am getting interrupts every 11.6ms instead of 10ms. I have enabled interrupt and timer reset on match 0.

Please suggest to me what may be the issue.

Thanks and Regards,

Prachi 

Labels (3)
Tags (3)
0 Kudos
1 Solution
906 Views
jeremyzhou
NXP Employee
NXP Employee

Hi,

Thank you for your interest in NXP Semiconductor products and the opportunity to serve you.

You should set PR ( Prescale Register) =5 if you want the division factor is 6.

Hope it helps.
Have a great day,
TIC

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

0 Kudos
2 Replies
907 Views
jeremyzhou
NXP Employee
NXP Employee

Hi,

Thank you for your interest in NXP Semiconductor products and the opportunity to serve you.

You should set PR ( Prescale Register) =5 if you want the division factor is 6.

Hope it helps.
Have a great day,
TIC

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
906 Views
Badman
Contributor I

Hi, please show your code.

Test my code:

#include "LPC13xx.h"

// 1 kHz = 1 ms
#define KHZ_PRESCALER (SystemCoreClock / 1000)

void TIMER16_0_IRQHandler(void)
{
     if (LPC_TMR16B0->IR & 0x1)     // check interrupt from MR0
     {
          LPC_TMR16B0->IR = 0x1;     // clear flag interrupt from MR0
          // your code
     }

}

int main(void) {

     LPC_SYSCON->SYSAHBCLKCTRL |= 1<<7;          // enable CT16B0

     // Configuration timer CT16B0
     LPC_TMR16B0->PR = KHZ_PRESCALER - 1;     // set prescaler on 1 ms
     LPC_TMR16B0->MR0 = 10;                         // set to 10 ms
     LPC_TMR16B0->MCR = (1<<0) | (1<<1);          // interrupt on MR0 when TC=MR0, and reset MR0

     NVIC_EnableIRQ( TIMER_16_0_IRQn);          // enable interrupt from CT16B0

    while(1) {

    }
    return 0 ;
}
0 Kudos