System Tick Timer

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

System Tick Timer

3,266 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by WrathFox on Mon Sep 13 09:27:43 MST 2010
Hello.

I am in need of some help / explanation of the system tick timer for LPC13xx. http://ics.nxp.com/support/documents/microcontrollers/pdf/user.manual.lpc13xx.pdf , chapter 16 covers the system tick timer but I find it hard to follow. Could anyone provide an example / explain how to setup a routine (ISR) that gets called each 10 ms automatically? I have looked at the examples that can be exported, but these examples are not really what I am looking for, I'm trying to figure out how to have an ISR that gets called auto called each 10 ms.

I appriciate all help / examples.
0 Kudos
Reply
13 Replies

2,780 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Mike45 on Tue Nov 09 17:10:46 MST 2010
In the supplied example :
__INLINE static void Delay (uint32_t dlyTicks) {
  uint32_t curTicks;

  curTicks = msTicks;
  while ((msTicks - curTicks) < dlyTicks);
}



What happens to Curticks / msTicks when it has incremented past 32 bits? does it simply reset to 0?
0 Kudos
Reply

2,780 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by cyberstudio on Thu Nov 04 13:17:40 MST 2010
Systick will still be ticking while in non-sleep mode, right? If not, what would work as a timed wake-up?
0 Kudos
Reply

2,780 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Fri Sep 17 10:56:28 MST 2010
why not:
void Systick_Handler() {
  something() ;
  something_else();
}
?
0 Kudos
Reply

2,780 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by qili on Fri Sep 17 08:06:20 MST 2010

Quote:
Is it possible to use several different System Tick Handler events at  the same time?



the answer is definitively no.

however, that doesn't mean what I think you are trying to do is not possible.
0 Kudos
Reply

2,780 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri Sep 17 07:31:30 MST 2010
No, there is only one SysTick Timer. If you need another timer, you can use 16- / 32-bit timer.
If you just need a second time signal, add a counter for the slower timer:

volatile int timer;
volatile int flag;
 
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void [/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][B]SysTick_Handler[/B]([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]) [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//Interrupt handler[/COLOR][/SIZE][/COLOR][/SIZE]
 
 
[LEFT][SIZE=2]{[/SIZE]

[SIZE=2]timer++;                                 [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//[U]inc[/U] counter[/COLOR][/SIZE][/COLOR][/SIZE]
[LEFT][SIZE=2][SIZE=2]if (timer >= 100)[/SIZE][/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2]flag =1;                                 //set flag[/SIZE]
[SIZE=2]timer =0;[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2]}[/SIZE][/LEFT]
[/LEFT]

 
 
0 Kudos
Reply

2,780 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by WrathFox on Fri Sep 17 05:20:30 MST 2010
Hello again, I have another question. Is it possible to use several different System Tick Handler events at the same time? For instances that you have[Code]

[SIZE=2][COLOR=#7f0055]
[LEFT][/COLOR][/SIZE][SIZE=2][B][COLOR=#7f0055]void [/COLOR]SysTick_Handler[/B]([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]) {[/SIZE]

[SIZE=2]// something[/SIZE]

[SIZE=2]}[/SIZE][/LEFT]


[LEFT][SIZE=2][B][COLOR=#7f0055]void [/COLOR][/B][SIZE=2][B]SysTick_Handler2[/B]([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]) {[/SIZE][/SIZE][SIZE=2]
[LEFT][SIZE=2]// something else[/SIZE][/SIZE][/LEFT]
[/LEFT]
[SIZE=2]
[LEFT][SIZE=2]}[/SIZE][/LEFT]
[/SIZE][/Code]

[LEFT]Is this possible to do ?[/LEFT]
0 Kudos
Reply

2,780 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by WrathFox on Tue Sep 14 08:10:42 MST 2010
Thank you very much for the answers! I now understand how it works and have it working!
0 Kudos
Reply

2,780 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by qili on Tue Sep 14 06:18:09 MST 2010
the SysTick_Handler() routine does precisely that: it is an isr, and you can set it up so that it triggers at a certain interval (SystemCoreClock / 10000 for example sets it up every 10ms), as shown in many of the example code.

what else do you need?
0 Kudos
Reply

2,780 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Tue Sep 14 01:10:41 MST 2010
The provided example already basically does what you want.

In the LPCXpresso1343_systick example, in systick.c, in main(), the line:

if (SysTick_Config(SystemCoreClock / 1000)) { /* Setup SysTick Timer for 1 msec interrupts  */
    while (1);                                  /* Capture error */
  }
sets up the SysTick timer so that the corresponding interrupt handler is called every 1ms.

The corresponding interrupt handler is SysTick_Handler() higher up the source file. In this case the interrupt handler simply increments a counter, which is then used elsewhere it the code as a delay counter.

void SysTick_Handler(void) {
  msTicks++;                        /* increment counter necessary in Delay() */
}
But it could do whatever you like.

Thus in your code where you want to have your interrupt handler called every 10ms, change the divide in the Systick setup call from 1000 to 100, then provide your new version of SysTick_Handler().

[As an aside, the reason why the Systick interrupt handler is called "SysTick_Handler" is because that is the name of the function that the startup code in cr_startup_lp13.c file places in the systick interrupt vector address.]

Regards,
CodeRedSupport
0 Kudos
Reply

2,780 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by WrathFox on Tue Sep 14 00:55:53 MST 2010
Let me clearify even further, I have used the avr family for some university courses. I got interested in embedded systems and decided to try lpc at home.

In the avr family I could do something like this :

void initOC1() {// init ISR 
TCCR1A = 0;
TCCR1B = 0b00001010;
OCR1A = 1250 << 4;
TIMSK = TIMSK | 0x10;
}

ISR (SIG_OUTPUT_COMPARE1A) {
// do something
}

int main(void) {
    initOC1();  
    SREG |= 0x80; // now ISR (SIG_OUTPUT_COMPARE1A) will run automatically 
}


This is what I'm trying to achieve with my LPC1343. So far I have only been able to use the examples to create a delay, but in the long run it is not what I want. Could anyone please help a fellow beginner? I'm really stuck at this point.
0 Kudos
Reply

2,780 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by WrathFox on Tue Sep 14 00:16:37 MST 2010
I have looked at the example projects and they only seem use it as a delay, and as a delay in the main loop. I'm looking for something that works as in the avr family ISR function.. If anyone could help me out I would be very grateful.. I haven't done much embedded hardware programming and I find some of the examples (at least the ones related to this topic) hard to use..
0 Kudos
Reply

2,780 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by qili on Mon Sep 13 15:18:43 MST 2010

Quote:
I have looked at the examples that can be exported, but these examples  are not really what I am looking for, I'm trying to figure out how to  have an ISR that gets called auto called each 10 ms.



really? those examples may not be exactly what you want but if you go through the documentation and the code, it should be quite obvious to anyone (with half decent comprehension) how to modify the code to do what you want to do.
0 Kudos
Reply

2,780 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Sep 13 10:14:45 MST 2010
Did you try LPCXpresso1343_systick example provided in LPCXpresso example folder?
0 Kudos
Reply