You are here

Using Systick Timer as a counter | Cypress Semiconductor

Using Systick Timer as a counter

Summary: 3 Replies, Latest post by odissey1 on 23 Nov 2015 05:21 PM PST
Verified Answers: 2
Last post
Log in to post new comments.
user_350540870's picture
175 posts

Hi All

I am working in a direction to use SysTick timer in order to record a time period in between two events and save it in a variable. SysTick Timer has not any dedicated API to get time period from it. Can anybody please guide me to resolve this?

user_1377889's picture
9283 posts

The answer is "CySysTickGetValue()". Have a look into "System Reference Guide", Boot Component 5.20. There are all the APIs for the SysTick timer.



user_49271930's picture
407 posts

Maybe you are interested in a component of meh for PSoC4 and PSoC 5LP :     SysTimers component

user_342122993's picture
530 posts


This is example of using SysTick timer on PSoC4 and 5 to measure number of CPU cycles. Limit is 2^24 CPU ticks (about 0.7sec @24MHz CPU speed), as SysTick counter on Cortex M0 and M3 can not go beyond SYSTICK_MAXVAL:

#define SYSTICK_MAXVAL 0x00FFFFFF //max allowed SysTick counter value for 24bit
uint32 SysCntVal; // The value of SysTick counter you are trying to retrieve

SysTick_Config(SYSTICK_MAXVAL); //reset counter set to max value, 1-time, will not reload

//do some operations here..

SysCntVal = SYSTICK_MAXVAL - (SysTick->VAL); //get elapsed ticks (min offset 3 ticks)

sprintf(strMsg, "%d\r\n", SysCntVal); //report result


Note that SysTick counter will not reload this way (it will quietly expires). It is possible to roll over 2^24 cpunts by enabling SysTick interrupt and resetting the timer, but doing this accumulates errors

Log in to post new comments.