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

PSoC™ 4 Forum Discussions

Demi1
Level 1
25 sign-ins First like given 5 replies posted
Level 1

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!

0 Likes
1 Solution
MotooTanaka
Level 9
First comment on KBA 1000 replies posted 750 replies posted
Level 9

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

001-schematic.JPG

Pins

Note: Actually I did not assign any pins, so all pins were assigned automatically.

004-Pins.JPG

PWM_4 config

I set period 999 which will be 1ms interval

002-PWM_4_config.JPG

PWM_5 config

I set period 1999 which will be 2ms interval

003-PWM_5_config.JPG

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

 

View solution in original post

0 Likes
2 Replies
Yugandhar
Moderator
Moderator 5 likes given First comment on blog 750 replies posted
Moderator

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.

0 Likes
MotooTanaka
Level 9
First comment on KBA 1000 replies posted 750 replies posted
Level 9

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

001-schematic.JPG

Pins

Note: Actually I did not assign any pins, so all pins were assigned automatically.

004-Pins.JPG

PWM_4 config

I set period 999 which will be 1ms interval

002-PWM_4_config.JPG

PWM_5 config

I set period 1999 which will be 2ms interval

003-PWM_5_config.JPG

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

 

0 Likes