How to determine the interrupt that was triggered by a PWM block

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

cross mob
KeLa_4479261
Level 4
Level 4
First like received

I am using the PWM v3 30, in a PSOC 4M series board.

I have set up two compare values in the structure along with the interrupt on pwm1 and pwm2.

I have created the ISR:

CY_ISR(pwm_isr_ON_OFF)

{

    status = PWM_ReadStatusRegister() ;

     // Pseudo code

     if (stats & COMPARE_FLAG_1)

          do_stuff(pwm1);

     else if(status & COMPARE_FLAG_2)

          do_stuff(pwm2);

    

    pwm_on_off_flag = 1;

}

I was hoping to identify the source of the interrupt; compare1 or compare2.  I have checked the documentation and tried looking for examples but have not been successful so far.

Help would be appreciated,

Thanks,

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I tried this with CY8CKIT-044.

Being a lazy, I made the PWM very slow and let pins light LED Red and LED Green.

I picked the status values from PWM.c

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

    /*******************************************************************************

    * Function Name: PWM_ReadStatusRegister

    ********************************************************************************

    *

    * Summary:

    *  This function returns the current state of the status register.

    *

    * Parameters:

    *  None

    *

    * Return:

    *  uint8 : Current status register value. The status register bits are:

    *  [7:6] : Unused(0)

    *  [5]   : Kill event output

    *  [4]   : FIFO not empty

    *  [3]   : FIFO full

    *  [2]   : Terminal count

    *  [1]   : Compare output 2

    *  [0]   : Compare output 1

    *

    *******************************************************************************/

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

schematic

001-schematic.JPG

PWM config

002-PWM-config1.JPG

003-PWM-config2.JPG

FreqDiv Config

004-freq-div-config.JPG

pins

005-pins.JPG

main.c

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

#include "project.h"

#include "stdio.h"

#define STR_LEN 64

char str[STR_LEN+1] ;

void print(char *str)

{

    UART_UartPutString(str) ;

}

void cls(void)

{

    print("\033c") ; /* reset */

    CyDelay(20) ;

    print("\033[2J") ; /* clear screen */

    CyDelay(20) ;

}

void splash(void)

{

    cls() ;

    print("CY8CKIT-044 PWM 2 Compares Test") ;

    snprintf(str, STR_LEN, "(%s %s)\n", __DATE__, __TIME__) ;

    print(str) ;

}

#define COMPARE_FLAG_1 0x01

#define COMPARE_FLAG_2 0x02

volatile int red_flag = 0 ;

volatile int green_flag = 0 ;

volatile int pwm_on_off_flag = 0 ;

CY_ISR(pwm_isr_ON_OFF)

{

    uint8_t status ;

  

    status = PWM_ReadStatusRegister() ;

     if (status & COMPARE_FLAG_1)

          red_flag = 1 ;

     else if(status & COMPARE_FLAG_2)

          green_flag = 1 ;

  

    pwm_on_off_flag = 1;

}

void init_hardware(void)

{

    CyGlobalIntEnable; /* Enable global interrupts. */

    UART_Start() ;

    splash() ;

  

    isr_pwm_ClearPending() ;

    isr_pwm_StartEx(pwm_isr_ON_OFF) ;

    PWM_Start() ;

}

int main(void)

{

    init_hardware() ;

    for(;;)

    {

        if (pwm_on_off_flag) {

            pwm_on_off_flag = 0 ;

            print("INTR : ") ;

            if (red_flag) {

                red_flag = 0 ;

                print("RED ") ;

            }

            if (green_flag) {

                green_flag = 0 ;

                print("GREEN ") ;

            }

            print("\n\r") ;

        }

    }

}

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

Tera Term Log

000-TeraTerm-log.JPG

moto

View solution in original post

0 Likes
2 Replies
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I tried this with CY8CKIT-044.

Being a lazy, I made the PWM very slow and let pins light LED Red and LED Green.

I picked the status values from PWM.c

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

    /*******************************************************************************

    * Function Name: PWM_ReadStatusRegister

    ********************************************************************************

    *

    * Summary:

    *  This function returns the current state of the status register.

    *

    * Parameters:

    *  None

    *

    * Return:

    *  uint8 : Current status register value. The status register bits are:

    *  [7:6] : Unused(0)

    *  [5]   : Kill event output

    *  [4]   : FIFO not empty

    *  [3]   : FIFO full

    *  [2]   : Terminal count

    *  [1]   : Compare output 2

    *  [0]   : Compare output 1

    *

    *******************************************************************************/

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

schematic

001-schematic.JPG

PWM config

002-PWM-config1.JPG

003-PWM-config2.JPG

FreqDiv Config

004-freq-div-config.JPG

pins

005-pins.JPG

main.c

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

#include "project.h"

#include "stdio.h"

#define STR_LEN 64

char str[STR_LEN+1] ;

void print(char *str)

{

    UART_UartPutString(str) ;

}

void cls(void)

{

    print("\033c") ; /* reset */

    CyDelay(20) ;

    print("\033[2J") ; /* clear screen */

    CyDelay(20) ;

}

void splash(void)

{

    cls() ;

    print("CY8CKIT-044 PWM 2 Compares Test") ;

    snprintf(str, STR_LEN, "(%s %s)\n", __DATE__, __TIME__) ;

    print(str) ;

}

#define COMPARE_FLAG_1 0x01

#define COMPARE_FLAG_2 0x02

volatile int red_flag = 0 ;

volatile int green_flag = 0 ;

volatile int pwm_on_off_flag = 0 ;

CY_ISR(pwm_isr_ON_OFF)

{

    uint8_t status ;

  

    status = PWM_ReadStatusRegister() ;

     if (status & COMPARE_FLAG_1)

          red_flag = 1 ;

     else if(status & COMPARE_FLAG_2)

          green_flag = 1 ;

  

    pwm_on_off_flag = 1;

}

void init_hardware(void)

{

    CyGlobalIntEnable; /* Enable global interrupts. */

    UART_Start() ;

    splash() ;

  

    isr_pwm_ClearPending() ;

    isr_pwm_StartEx(pwm_isr_ON_OFF) ;

    PWM_Start() ;

}

int main(void)

{

    init_hardware() ;

    for(;;)

    {

        if (pwm_on_off_flag) {

            pwm_on_off_flag = 0 ;

            print("INTR : ") ;

            if (red_flag) {

                red_flag = 0 ;

                print("RED ") ;

            }

            if (green_flag) {

                green_flag = 0 ;

                print("GREEN ") ;

            }

            print("\n\r") ;

        }

    }

}

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

Tera Term Log

000-TeraTerm-log.JPG

moto

0 Likes

Thanks Motoo.

This works in the continuous mode.

Regards.

Ken.