cancel
Showing results for 
Search instead for 
Did you mean: 

[newbie] how to use systick?

vicki19880929
Associate III
Posted on March 05, 2014 at 00:23

Hi all,

I saw many examples using systick interrupt handler to generate the accurate delay time (like the example below).  My question would be pretty simple here:  why does ''

http://www.keil.com/pack/doc/cmsis/Core/html/group___sys_tick__gr.html#gabe47de40e9b0ad465b752297a9d9f427

(

http://www.keil.com/pack/doc/cmsis/Core/html/group__system__init__gr.html#gaa3cd3e43291e81e795d642b79b6088e6

/ 1000)

'' generate a 1 millisecond delay?  I need to examine the execution time of each section of my code in my project, which might reach to microsecond level, so I'm trying to understand the systick time calculation.  

#include ''LPC17xx.h''

uint32_t msTicks = 0;

/* Variable to store millisecond ticks */

void

SysTick_Handler(

void

) {

/* SysTick interrupt Handler.

msTicks++; See startup file startup_LPC17xx.s for SysTick vector */

}

int

main (

void

) {

uint32_t returnCode;

returnCode =

http://www.keil.com/pack/doc/cmsis/Core/html/group___sys_tick__gr.html#gabe47de40e9b0ad465b752297a9d9f427

(

http://www.keil.com/pack/doc/cmsis/Core/html/group__system__init__gr.html#gaa3cd3e43291e81e795d642b79b6088e6

/ 1000);

/* Configure SysTick to generate an interrupt every millisecond */

if

(returnCode != 0) {

/* Check return code for errors */

// Error Handling

}

while

(1);

}

I'm using STM32L.  Thanks a lot!!

~S
2 REPLIES 2
Posted on March 05, 2014 at 03:20

So SystemCoreClock contains the number of clock ticks in one second, 1 ms is 1/1000 th of a second, SystemCoreClock / 1000 is the number if ticks in 1 ms. The value is counted by the SysTick counter, every time this number of ticks occurs the interrupt is fired.

If I were benchmarking code I'd use the

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https%3a//my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/compensating%20latencies%20on%20STM32F4%20interrupts&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&...

cycle counter, which will tick at 48 MHz (or whatever you're running the STM32L1 at), so ~21ns granularity. Read the value before/after the code execution being measured, the subtract the start time from the end time.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
vicki19880929
Associate III
Posted on March 05, 2014 at 20:24

I see.  Thanks for you explanation.  I learned a lot about ST clock management these two days.  :D