PSoC TCPWM Overflow

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

cross mob
chme_4646286
Level 4
Level 4
Distributor - Intron(GC)
100 sign-ins First comment on blog 50 sign-ins

Hi;

I call the TCPWM module (based on PSoC Creator) on the PSoC4100S+ series MCU; The configuration is as follows:

PWM align: Asymmetric

chme_4646286_0-1658242577138.png

I want to handle something in the interrupt when the overflow event occur;

But referring to the TRM register manual, there is no overflow flag bit in TCPWM_CNT_INTR;

How to judge the occurrence of overflow event in Asymmetric mode? Is there an example to provide reference?

chme_4646286_1-1658243007258.png

 

 

0 Likes
1 Solution
PandaS
Moderator
Moderator
Moderator
250 replies posted 100 solutions authored 5 likes given

Hi @chme_4646286 ,

I tried that at my end, it is an invalid connection. We cant generate an interrupt especially for Overflow or Underflow, because only Terminal Count triggers an interrupt or for Capture and Compare Register. Now what we can do is to identify whether it is OV(Overflow) or UN(Underflow) in the ISR of TC(Terminal Count) itself. That is the interrupt line of TCPWM block.

For that, we can check the period value and compare it counter value in the ISR of TC, we will get to know whether it is OV or UV. Please refer the below snippet and add it to the ISR:

 

#include <project.h>




/******************************************************************************
* Function Name: Isr_TC_Handler
*******************************************************************************
*
* Summary:
*  Handles the Interrupt Service Routine for the PWM Component.
*
******************************************************************************/
CY_ISR(Isr_TC_Handler)
{   
	/* Clear the TC Interrupt */
   	PWM_ClearInterrupt(PWM_INTR_MASK_TC);
    
    /* Decrement the PWM Compare value to increase the LED brightness */
    if(PWM_ReadCounter() == PWM_ReadPeriod()-1){
        //OV
        LED_Write(1);
    }else{
        //UN
        LED_Write(0);
    }
}


/******************************************************************************
* Function Name: main
*******************************************************************************
* Summary:
*  This function:
*  1. Sets up and enables the PWM interrupt.
*  2. Starts the PWM Component.
******************************************************************************/
int main()
{   
    /* Enable the global interrupt */
    CyGlobalIntEnable;
    
    /* Enable the Interrupt component connected to the PWM interrupt output */
    Isr_TC_StartEx(Isr_TC_Handler);
    
	/* Start the PWM Component */
    PWM_Start();
    
    for(;;)
    {
        
    }
}

 

Thanks and Regards

Sobhit

View solution in original post

0 Likes
3 Replies
PandaS
Moderator
Moderator
Moderator
250 replies posted 100 solutions authored 5 likes given

Hi @chme_4646286 ,

In order to have a interrupt on OV event or UN event, may be you try attaching an interrupt to the OV Pin of TCPWM Block. And just like a button interrupt you will need to define the ISR in the code.

PandaS_0-1658302513764.png

 

Try this at your end, or else I will suggest another workaround.

Thanks and regards

Sobhit

0 Likes
chme_4646286
Level 4
Level 4
Distributor - Intron(GC)
100 sign-ins First comment on blog 50 sign-ins

Hi PandaS;

Thank you very much for your reply

But referring to the method you provided, I attach an interrupt to the OV pin of the TCPWM component, and it prompts that the component placement is invalid when compiling;

chme_4646286_0-1658391863728.png

 

Can you compile it correctly and trigger an overflow interrupt?

0 Likes
PandaS
Moderator
Moderator
Moderator
250 replies posted 100 solutions authored 5 likes given

Hi @chme_4646286 ,

I tried that at my end, it is an invalid connection. We cant generate an interrupt especially for Overflow or Underflow, because only Terminal Count triggers an interrupt or for Capture and Compare Register. Now what we can do is to identify whether it is OV(Overflow) or UN(Underflow) in the ISR of TC(Terminal Count) itself. That is the interrupt line of TCPWM block.

For that, we can check the period value and compare it counter value in the ISR of TC, we will get to know whether it is OV or UV. Please refer the below snippet and add it to the ISR:

 

#include <project.h>




/******************************************************************************
* Function Name: Isr_TC_Handler
*******************************************************************************
*
* Summary:
*  Handles the Interrupt Service Routine for the PWM Component.
*
******************************************************************************/
CY_ISR(Isr_TC_Handler)
{   
	/* Clear the TC Interrupt */
   	PWM_ClearInterrupt(PWM_INTR_MASK_TC);
    
    /* Decrement the PWM Compare value to increase the LED brightness */
    if(PWM_ReadCounter() == PWM_ReadPeriod()-1){
        //OV
        LED_Write(1);
    }else{
        //UN
        LED_Write(0);
    }
}


/******************************************************************************
* Function Name: main
*******************************************************************************
* Summary:
*  This function:
*  1. Sets up and enables the PWM interrupt.
*  2. Starts the PWM Component.
******************************************************************************/
int main()
{   
    /* Enable the global interrupt */
    CyGlobalIntEnable;
    
    /* Enable the Interrupt component connected to the PWM interrupt output */
    Isr_TC_StartEx(Isr_TC_Handler);
    
	/* Start the PWM Component */
    PWM_Start();
    
    for(;;)
    {
        
    }
}

 

Thanks and Regards

Sobhit

0 Likes