How to configure and use SysTick Timer Interrupt in PSoC5?

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 want to configure a SysTick Timer in such a way that the SysTick Timer Interrupt should invoke every 1 ms. I am using 

CY8CKIT-059 PSoC® 5LP Prototyping Kit. 

In PSoC 4, I did this same functionality by using the following code :

 

 

 

 

#define NO_OF_TICKS 24000u
int *tick_CM0_ENABLE = (int *) CYREG_CM0_SYST_CSR;
uint32  SysTick_value;
CY_ISR_PROTO(MySysTickHandler);
void SysTick_Timer_Enable(void);     //Enabling SysTick Timer
void SysTick_Timer_Disable(void);    //Disabling SysTick Timer

void SysTick_Timer_Enable(void){
    *tick_CM0_ENABLE |= 1; // For Enabling the Tick Counter
    /* Enable SysTick timer with desired period/number of ticks */
    SysTick_Config(NO_OF_TICKS);
}    

void SysTick_Timer_Disable(void){
    
    *tick_CM0_ENABLE &= (~1); // For Disabling the Tick Counter    
}    
void Initialize(void)
{
    CyGlobalIntEnable;                                              
    CyIntSetSysVector((SysTick_IRQn + 16u), MySysTickHandler);
    SysTick_value = 0;
}
void main(void)
{
    Initialize();
}
CY_ISR(MySysTickHandler)
{
    SysTick_value++;
    if(SysTick_value >= 1000u)
    {
        SysTick_value = 0;
        SysTick_Timer_Disable(); // Stop after 1000 ms
    }    
}

 

 

 

 

I do not know why but this method does not work for PSoC5. 

0 Likes
1 Solution
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

ShVy,

I haven't verified your code listed in your first post.   However, using the SysTick is fairly easy. 

Here is working SysTick code I use ALL the time on my PSo5LP projects:

uint32_t systick = 0;
uint32_t systick_prev = 0;
CY_ISR(isr_systick)
{
	systick++;
}
/* Your Application here vvvv */
main(void)
{
...
/* SysTick init */
  CySysTickStart();  /* Start the systick */
  CySysTickSetCallback(0, isr_systick);  /* Add the Systick callback */
      /* to the standard SysTick Int Vector */
/*****/
...   /* other stuff you need to init */
/* SysTick use in the Application */
  for(;;)
  {
/* Wait for the previous SysTick event plus a set delay */
    if(systick >= (systick_prev + 1000)) 
    {    /* SysTick event occurred.  Process SysTick event in the App. */
      systick_prev = systick;    /* Set the new previous SysTick count */
      ...
      /* go do something within the systick event */
      ...
    }
}

 

Len
"Engineering is an Art. The Art of Compromise."

View solution in original post

0 Likes
5 Replies