LPC1313 16-bit timer 0 MR register value

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

LPC1313 16-bit timer 0 MR register value

跳至解决方案
2,495 次查看
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 

标签 (3)
标记 (3)
0 项奖励
回复
1 解答
1,564 次查看
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 项奖励
回复
2 回复数
1,565 次查看
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 项奖励
回复
1,564 次查看
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 项奖励
回复