7 Replies Latest reply on May 9, 2020 6:25 PM by MoTa_728816

    Timer interrupt priority issue

    ChHs_4614611

      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.

       

       

         

       

       

        • 1. Re: Timer interrupt priority issue
          MoTa_728816

          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

          • 2. Re: Timer interrupt priority issue
            LinglingG_46

            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!

            2 of 2 people found this helpful
            • 3. Re: Timer interrupt priority issue
              MoTa_728816

              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

               

               

               

               

              1 of 1 people found this helpful
              • 4. Re: Timer interrupt priority issue
                ChHs_4614611

                Hi Moto,

                 

                My 100ms counter in SystemLed() function.

                CY_ISR just set flag to true.

                • 5. Re: Timer interrupt priority issue
                  ChHs_4614611

                  Dear LinglingG_46-san,

                   

                  Thank you for your information.

                  I will try it.

                  • 6. Re: Timer interrupt priority issue
                    MoTa_728816

                    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

                    1 of 1 people found this helpful
                    • 7. Re: Timer interrupt priority issue
                      MoTa_728816

                      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

                      1 of 1 people found this helpful