- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,SIR:
Can you please help me solve a problem?
My current customer is using the PS0C4100S series, which has 5 TCPWMs, and the customer expects to generate 5 PWM outputs and needs an additional timer interrupt.
Can a TCPWM module be used as a timer interrupt and PWM output at the same time? If so, how do I set it up? If not, is there any other way to implement timer interrupts?
Thank you for your answer!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
As I heard that the interrupt interval is 1ms ~ 2ms, I wrote a sample below.
This assumes that at least 1 PWM's period (=interval) is 1ms or 2ms.
schematic
Pins
Note: Actually I did not assign any pins, so all pins were assigned automatically.
PWM_4 config
I set period 999 which will be 1ms interval
PWM_5 config
I set period 1999 which will be 2ms interval
main.c
To show 1ms interrupt and 2ms interrupt, I created 2 ISR,
but probably only 1 of them will be enough.
#include "project.h"
volatile int flag_1ms = 0 ;
volatile int flag_2ms = 0 ;
CY_ISR(isr_1ms)
{
PWM_4_ClearInterrupt(PWM_4_INTR_MASK_TC) ;
flag_1ms = 1 ;
}
CY_ISR(isr_2ms)
{
PWM_5_ClearInterrupt(PWM_5_INTR_MASK_TC) ;
flag_2ms = 1 ;
}
void init_hardware(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
isr_1_ClearPending() ;
isr_1_StartEx(isr_1ms) ;
isr_2_ClearPending() ;
isr_2_StartEx(isr_2ms) ;
PWM_1_Start() ;
PWM_2_Start() ;
PWM_3_Start() ;
PWM_4_Start() ;
PWM_5_Start() ;
}
int main(void)
{
init_hardware() ;
for(;;)
{
if (flag_1ms) { /* 1ms interrupt hit! */
flag_1ms = 0 ;
}
if (flag_2ms) { /* 2ms interrupt hit! */
flag_2ms = 0 ;
}
}
}
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
Please refer to the 'CE195351 – PWM' code example from the PSoC Creator. This example configures an instance of the PWM Component to generate signal with a desired duty cycle. The Component interrupt output is configured to generate interrupts on a terminal count event.
Thanks,
P Yugandhar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
As I heard that the interrupt interval is 1ms ~ 2ms, I wrote a sample below.
This assumes that at least 1 PWM's period (=interval) is 1ms or 2ms.
schematic
Pins
Note: Actually I did not assign any pins, so all pins were assigned automatically.
PWM_4 config
I set period 999 which will be 1ms interval
PWM_5 config
I set period 1999 which will be 2ms interval
main.c
To show 1ms interrupt and 2ms interrupt, I created 2 ISR,
but probably only 1 of them will be enough.
#include "project.h"
volatile int flag_1ms = 0 ;
volatile int flag_2ms = 0 ;
CY_ISR(isr_1ms)
{
PWM_4_ClearInterrupt(PWM_4_INTR_MASK_TC) ;
flag_1ms = 1 ;
}
CY_ISR(isr_2ms)
{
PWM_5_ClearInterrupt(PWM_5_INTR_MASK_TC) ;
flag_2ms = 1 ;
}
void init_hardware(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
isr_1_ClearPending() ;
isr_1_StartEx(isr_1ms) ;
isr_2_ClearPending() ;
isr_2_StartEx(isr_2ms) ;
PWM_1_Start() ;
PWM_2_Start() ;
PWM_3_Start() ;
PWM_4_Start() ;
PWM_5_Start() ;
}
int main(void)
{
init_hardware() ;
for(;;)
{
if (flag_1ms) { /* 1ms interrupt hit! */
flag_1ms = 0 ;
}
if (flag_2ms) { /* 2ms interrupt hit! */
flag_2ms = 0 ;
}
}
}
moto