3 Replies Latest reply on Jul 24, 2017 11:14 PM by anks

    PSoC Creator - Using Built In ISR

    ted_1467596

      I created a design for a CYBLE-222014-01 which includes a TCPWM moduse set up as a timer; it has a 32 kHz clock input and 1x presaclar.  The period is 256 and the compare is 128 with interrupt on terminal count.  I connected an ISR which I called Timer_ISR to the interrupt output.

         

      My ISR code includes a simple LED toggle...

         

         LED_1_Write( ~ LED_1_Read() );

         

      Which works in main.c if I just add a 500 mS delay to the loop but when I copy that code in the ISR routine for LED2, which should be being called at 250 Hz, it seems to be called at around 300 kHz (I see a 150 kHz clock going to LED_2) and LED_1 doesn't flash any more.  Here's my code for the ISR in Timer_ISR.c

         

      CY_ISR(Timer_ISR_Interrupt)
      {
          #ifdef Timer_ISR_INTERRUPT_INTERRUPT_CALLBACK
              Timer_ISR_Interrupt_InterruptCallback();
          #endif /* Timer_ISR_INTERRUPT_INTERRUPT_CALLBACK */ 

         

          /*  Place your Interrupt code here. */
          /* `#START Timer_ISR_Interrupt` */

         

          LED_2_Write( ~ LED_2_Read() );
          Timer_ISR_ClearPending();           // Read to clear status register

         


          /* `#END` */
      }

         

      I think the issue is that I'm not clearing the Timer_ISR interrupt flag so, once it triggers, it keeps getting re-called.  I've tried Timer_ISR_GetState(); in place of the Timer_ISR_ClearPending(); line but so far no joy.  There seems to be an address defined of Timer_ISR_INTC_CLR_EN but I'm not sure if that's the one to use or how to use it.

         

      Any help appreciated.

        • 1. Re: PSoC Creator - Using Built In ISR
          user_342122993
                  The TCPWM interrupt must be cleared inside isr. Add line TCPWM_ClearInterrupt(); inside ISR code, where TCPWM - is the name of your PWM component.   
          • 2. Re: PSoC Creator - Using Built In ISR
            ted_1467596

            Thanks, I added TCPWM_1_ClearInterrupt(); in Timer_ISR.c but there are 2 issues:

               

            1. I had to add #include "TCPWM_1.h" to get the function recognized and

               

            2. It's complaining that it needs an argument.

               

            [EDIT]

               

            I figured it out, the code/command that works in the ISR is as follows...

               

            CY_ISR(Timer_ISR_Interrupt)
            {
                #ifdef Timer_ISR_INTERRUPT_INTERRUPT_CALLBACK
                    Timer_ISR_Interrupt_InterruptCallback();
                #endif /* Timer_ISR_INTERRUPT_INTERRUPT_CALLBACK */ 

               

                /*  Place your Interrupt code here. */
                /* `#START Timer_ISR_Interrupt` */

               

                LED_2_Write( ~ LED_2_Read() );
                TCPWM_1_ClearInterrupt(TCPWM_1_INTR_MASK_TC);
                

               

                /* `#END` */
            }

               

            The datasheet for the TCPWM_1 component provides just 2 arguments, one for interrupt on terminal count (mine) and interrupt on compare/capture count.  What's slightly confusing is that the TCPWM component generates the input to the ISR so you have to clear the ISR flag in the TCPWM, not the ISR component. 

               

            • 3. Re: PSoC Creator - Using Built In ISR
              anks

              You can refer to the TCPWMExample Project in Code example section of Creator for better understanding of  the Interrupt clearing.

              1 of 1 people found this helpful