- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi;
I call the TCPWM module (based on PSoC Creator) on the PSoC4100S+ series MCU; The configuration is as follows:
PWM align: Asymmetric
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?
Solved! Go to Solution.
- Labels:
-
PSoC 4 MCU
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Try this at your end, or else I will suggest another workaround.
Thanks and regards
Sobhit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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;
Can you compile it correctly and trigger an overflow interrupt?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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