Timer interrupt issues LPC12xx

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

Timer interrupt issues LPC12xx

1,235 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fjrg76 on Fri Nov 16 10:24:31 MST 2012
Hi

I configured the CT16B0 timer in order to trigger an interrupt every (1/8KHz); although the timer is up and running, it doesn's trigger the interrupt. What comes to my mind is to enable a sort of global interrupt for such a timer, but I haven't found it yet (it it exists, of course).

In the LPC2129 it is rutinary to configure a tick system using one of the four timers (in fact, I wrote a little tutorial in how doing so); however, in th LPC1xxx, although timers blocks are identical to those found in the LPC2129, I haven't been able to make it work (to generate the interrupt) 'cause the interrupts controllers in both cores are totally different.

This (1/8KHz) interrupt is going to be part of a bigger project, but I created a new fresh one so I can isolate the trouble:

#define BIT(x)(1<<(x))

void TIMER16_0_IRQHandler(void)
{

LPC_GPIO0->NOT|=BIT(12);

LPC_CT16B0->IR=BIT(3);;
}

void timer16_Init(void)
{
    LPC_SYSCON->SYSAHBCLKCTRL |= 1<<7; // turn on TIM16B0 clock

    LPC_CT16B0->TCR=2;                 // stop and reset

    LPC_CT16B0->PR=45;                 // 45 MHz / 45 = 1us base time

    LPC_CT16B0->CTCR=0;

    LPC_CT16B0->MCR=(3<<9);            // reset and interrupt on MR3

    LPC_CT16B0->MR3=125;               // interrupt every 125us

    LPC_CT16B0->EMR=(3<<10);          // toggle bit (although not necessary)

    LPC_CT16B0->TC=0;

    LPC_CT16B0->IR|=BIT(3);           // clear any pending interrupt

    LPC_CT16B0->TCR=1;                // start timer
}

int main(void)
{

volatile static int i = 0 ;

LPC_SYSCON->SYSAHBCLKCTRL |= 0xE001001FUL;

LPC_GPIO0->DIR|=BIT(12);
LPC_GPIO0->CLR|=BIT(12);

timer16_Init();

while(1) {
i++ ;
}
return 0 ;
}


It's worth to mention that after this line:

    LPC_CT16B0->TCR=1;                // start timer


the LPC_CT16B0->IR flag for MR3 is set, and doesn't matter what I do, I can't reset it:

    LPC_CT16B0->IR|=BIT(3);           // clear any pending interrupt



In my code this last line of code was place before (as it's right now) and after starting the timer, but none was able to reset such an interrupt flag.

Am I missing something? Any ideas? Thank you!!

BTW: I'm using LPCXpresso 5.0
0 Kudos
Reply
4 Replies

1,197 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fjrg76 on Fri Nov 16 13:53:36 MST 2012

Quote: Zero
A simple Search is showing a working LPC1114 sample with correct prescale setting ;)

See #4 of http://knowledgebase.nxp.com/showthread.php?t=2815



Thank you!!

I saw that thread before my posting, however, my brain was focused in the interrupt's stuff, that's way I overlooked the values for the PR and MR3, but now they've been fixed ;)
0 Kudos
Reply

1,197 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fjrg76 on Fri Nov 16 13:49:32 MST 2012

Quote: ArneB
Hi fjrg76,

you have to enable the interrupt at the end of your timer init procedure:
NVIC_EnableIRQ(TIMER_16_0_IRQn);
This function is defined in the "core_cm0.h" CMSIS file. Hope this helps...



Thank you, that works!!

I completely forgot to add this line of code. Hope I won't again. This is the modified code:

void timer16_Init(void)
{
LPC_SYSCON->SYSAHBCLKCTRL |= 1<<7;
LPC_CT16B0->TCR=2;
[COLOR=Red]LPC_CT16B0->PR=44;[/COLOR]
LPC_CT16B0->CTCR=0;
LPC_CT16B0->MCR=(3<<9);
[COLOR=red]LPC_CT16B0->MR3=124;[/COLOR] // <-- 7.9998 KHz according my scope
LPC_CT16B0->EMR=(3<<10);
LPC_CT16B0->TC=0;
LPC_CT16B0->IR|=BIT(3);
[COLOR=red]NVIC_EnableIRQ(TIMER_16_0_IRQn);[/COLOR]

LPC_CT16B0->TCR=1;
}
0 Kudos
Reply

1,197 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri Nov 16 11:33:58 MST 2012

Quote: fjrg76

    LPC_CT16B0->PR=45;                 // 45 MHz / 45 = 1us base time
Am I missing something? Any ideas? Thank you!!



A simple Search is showing a working LPC1114 sample with correct prescale setting

See #4 of http://knowledgebase.nxp.com/showthread.php?t=2815
0 Kudos
Reply

1,197 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ArneB on Fri Nov 16 11:11:46 MST 2012
Hi fjrg76,

you have to enable the interrupt at the end of your timer init procedure:
NVIC_EnableIRQ(TIMER_16_0_IRQn);
This function is defined in the "core_cm0.h" CMSIS file. Hope this helps...
0 Kudos
Reply