Conflict between SysTick and Timer32 in LPC1114

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

Conflict between SysTick and Timer32 in LPC1114

1,661 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fjrg76 on Wed Sep 05 17:08:24 MST 2012
Hi

SysTick is for the the general system ticks, while Timer32 is for getting better resolution.

If only the SysTick module is enabled, then it works (10ms between ticks); however, if Timer32 module is enabled too, then SysTick stops generating interrupts, while Timer32 does.

I'm wondering about some kind of conflict, but I cannot seen any. Here is a snippet:


void SysTick_Handler(void)
{
++msTicks;
}
...

void timer32b_Init(uint32_t interval)
{
LPC_SYSCON->SYSAHBCLKCTRL |= BIT(9);
LPC_TMR32B0->TCR           = BIT(0)|BIT(1);
LPC_TMR32B0->MR2           = interval;
LPC_TMR32B0->MCR           = BIT(6)|BIT(7);
NVIC_EnableIRQ(TIMER_32_0_IRQn);
LPC_TMR32B0->TCR           = BIT(0);
}

void TIMER32_0_IRQHandler(void)
{
  LPC_TMR32B0->IR = 1;/* clear interrupt flag */
  ++usTicks;
}
...
void system_Init(void)
{
GPIOInit();

UARTInit(115200);


if (SysTick_Config(SystemCoreClock / 100)) { /* Setup SysTick Timer for 1 msec interrupts  */
while (1);                                  /* Capture error */
}

[COLOR=Red]timer32b_Init(48000); // 1ms[/COLOR]

chrono_Init(&cronometro,0);

}
...
int main(void)
{
 ...
system_Init();
...

for(;;){ ... }
}


If I comment the red code line out, then SysTick works.

Any clues?

Thank you!!
0 Kudos
Reply
5 Replies

1,584 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fjrg76 on Fri Sep 07 16:46:04 MST 2012
That's correct, and that's way I need a high resolution timer. Systick is going to do what it does better, the system tick, whilst another timer is going to count as fast as possible.
0 Kudos
Reply

1,584 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by NXP_Europe on Fri Sep 07 16:34:14 MST 2012
Hi fjrg76,

The default value of SysTick is mostly 10mSec, but SysTick can be changed as well.

SysTick_Config(SystemCoreClock / 100) => 10 mSec

Maybe we have to rewrite it: 1/100 = times 0.01 = * 0.01
SysTick_Config(SystemCoreClock * 0.01) => 0.01 Sec = 10 mSec

then ...
SysTick_Config(SystemCoreClock * 0.001) => 0.001 Sec = 1 mSec
SysTick_Config(SystemCoreClock / 1000) => 1 mSec
etc ...

Maybe this fits in your program.

However when counting needs to be done on uSec level, no time is left to do something else.
0 Kudos
Reply

1,584 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fjrg76 on Thu Sep 06 09:08:17 MST 2012
Hi Kayoda,

That works too, but the idea behind using the Timer32 is to get resolution in the 1us range (for a high resolution chronometer).

Thank you!!
0 Kudos
Reply

1,584 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ex-kayoda on Thu Sep 06 01:19:23 MST 2012
Or you just set SysTick to 1ms and add a counter to increment 10ms there too :rolleyes:
0 Kudos
Reply

1,584 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fjrg76 on Wed Sep 05 22:05:56 MST 2012
There is not such a conflict, instead I made I mistake. I based my code in an example, but it was using MR0, whilst I'm using MR3, so I didn't acknowledge the correct interrupt:

void TIMER32_0_IRQHandler(void)
{
  LPC_TMR32B0->IR = BIT(2); // <-- This is the correct value (former was 1)
  ++usTicks;
}


Thank you anyway!!!
0 Kudos
Reply