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
Solved! Go to Solution.
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!
-----------------------------------------------------------------------------------------------------------------------
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!
-----------------------------------------------------------------------------------------------------------------------
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 ;
}