Using Systick Timer as a counter

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
ShVy_264716
Level 4
Level 4
50 replies posted 25 replies posted 10 replies posted

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?

0 Likes
3 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

   

 

   

Bob

0 Likes
EvPa_264126
Level 7
Level 7
500 replies posted 250 replies posted 100 likes received

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

0 Likes
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

Shaunak,

   

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
UART_PutString(strMsg);

   

 

   

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

0 Likes