Timer interrupt priority issue

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

cross mob
AdamsChengTW
Level 3
Level 3
10 sign-ins 5 sign-ins 10 questions asked

HI ,

     I use 1ms system tick sample code . System LED toggle per 100ms.

     It is OK no problem.

     When I add other function. like SPI and Capsence...etc.

    LED toggle time is will exceed 100ms.

     How to setting 1ms timer priority to high priority ?

     My code is under below.

    pastedImage_1.png

pastedImage_0.png

pastedImage_2.png

0 Likes
1 Solution
LinglingG_46
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 10 questions asked

If it is the priority issue, please try to use the below API to change the NVIC priority:


    NVIC_SetPriority (CY_INT_SYSTICK_IRQN, (1UL << __NVIC_PRIO_BITS) - 2UL); // You can change the 2UL to (0,1,2,3,4)

    CySysTickStart();
   
    t= NVIC_GetPriority(CY_INT_SYSTICK_IRQN); // Get the t to judge whether it is successful to change the priority
   
     UART_PutHexByte(t); // use the debug interface to check the value

Hope it can be helpful for you!

View solution in original post

7 Replies
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I wonder if it's the interrupt priority or following block is pre-empted by other interrupts

====================

     if (AS_TRUE == Sys1msTask) {

          ..

     }

====================

So if only toggle the LED each 100ms how about do it inside the isr?

Something like

===================

volatile uint32_t led_tick_count = 0 ;

CY_ISR(SysTick_ISR)

{

    led_tick_count++ ;

    if ((led_tick_count % 100) == 0) {

        led_tick_count = 0 ;

        LED_Write(!LED_Read()) ;

    }

}

===================

If this still exceeds 100ms, maybe it's time to consider the priority....

moto

Hi Moto,

My 100ms counter in SystemLed() function.

CY_ISR just set flag to true.

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

> My 100ms counter in SystemLed() function.

> CY_ISR just set flag to true.

Yes, that is a correct usage of ISR, in general.

But in your case, if you want the LED blink not disturbed by other interrupt(s),

the safest approach I could think of was blink it inside the Timer ISR.

No mater how high priority you could set the interrupt,

the usual procedure in the main loop will be preempted by interrupts.

moto

MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

Have you had a chance to try below, which I wrote in my first response?

===================

volatile uint32_t led_tick_count = 0 ;

CY_ISR(SysTick_ISR)

{

    led_tick_count++ ;

    if ((led_tick_count % 100) == 0) {

        led_tick_count = 0 ;

        LED_Write(!LED_Read()) ;

    }

}

===================

moto

LinglingG_46
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 10 questions asked

If it is the priority issue, please try to use the below API to change the NVIC priority:


    NVIC_SetPriority (CY_INT_SYSTICK_IRQN, (1UL << __NVIC_PRIO_BITS) - 2UL); // You can change the 2UL to (0,1,2,3,4)

    CySysTickStart();
   
    t= NVIC_GetPriority(CY_INT_SYSTICK_IRQN); // Get the t to judge whether it is successful to change the priority
   
     UART_PutHexByte(t); // use the debug interface to check the value

Hope it can be helpful for you!

MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Dear LinglingG_46-san,

Thank you very much for the information!

> CY_INT_SYSTICK_IRQN

This is the information I was looking for about an hour last night but in vain.

So I modified my test program to see the priority of the SysTick.

000-TeraTerm-log.JPG

It seems that the priority is already 0 and I think this is the highest priority we can set, right?

So I'm afraid that there is not much we can do about making the priority of SysTick Higher.

I hope that my previous approach can soothe the situation...

Best Regards,

9-May-2020

Motoo Tanaka

Dear LinglingG_46-san,

Thank you for your information.

I will try it.

0 Likes