Announcements

Help us improve the Power & Sensing Selection Guide. Share feedback

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

cross mob
AdamsChengTW
Level 3
Level 3
10 sign-ins 5 sign-ins 10 questions asked

Hi,


I am using PSOC4 to control WS2811 (RGB LED) with a 1-wire protocol.

I modified the control using PWM with the PWM SAMPLE CODE. Initially, I intended to use interrupts to count 24 PWM pulses. However, the actual number of generated PWM pulses exceeds the number of interrupts.

If I want to generate a specific number of PWM pulses, how should I proceed?

 

/******************************************************************************
* Function Name: Isr_TC_Handler
******************************************************************************/
CY_ISR(Isr_TC_Handler)
{   
	/* Clear the TC Interrupt */
   	PWM_ClearInterrupt(PWM_INTR_MASK_TC);
    
    /* Counting the number of PWM pulses generated. */
    if(bits >= 24)
    {
        bits = 0;
        PWM_Stop();
        pwmStop = 1;
    }
    else
    {
        PWM_WriteCompare(WS2811_Bit1);
        bits++;
    }
}

/******************************************************************************
* Function Name: main
******************************************************************************/
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(;;)
    {

    }
}
0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
JJack
Level 5
Level 5
Associated Partner - Distributor Rutronik
5 questions asked 25 likes received 100 sign-ins

Hi

JJack_1-1690454736705.png

This generates a burst of 24 PWM periods and avoids any interrupts.

Please find my sample code of above sketched idea attached. The code runs on a CY8CKIT-149 with PSoC4 4100S Plus. The PWM (period ~0.4 s) drives user LED1. Every overrun signal is routed through the trigger multiplexer and increments another TCPWM configured as counter. A compare match with the desired numbers of PWM periods triggers a jump into an interrupt service routine where the PWM-timer is stopped per software and the LED stops flashing.

Unfortunately, I could not make the compare match signal stop or kill the PWM-timer permanently. This would have spared the interrupt service routine.

Best regards

JJack

View solution in original post

0 Likes
5 Replies
Ekta_N
Moderator
Moderator
Moderator
750 replies posted First like given 250 solutions authored

Hi @AdamsChengTW 

Could you please share your project? I want to check what is your condition for generating the interrupt.

From the code you have provided, it seems your PWM is configured to generate an interrupt on each rising edge or falling edge. This is because I see that you writing to compare register using PWM_Writecompare on every interrupt. I wanted to see how you have configured the PWM component (in the configurator).

If you just want one single interrupt after 24 pulses you can set the period value to 24 and generate an interrupt on terminal count.

Let me know if this works for you.

Best Regards
Ekta

 

0 Likes
lock attach
Attachments are accessible only for community members.

HI Ekta,

I have attached the test project.

By the way, these 24 pluses represent a 24-bit color RGB value, with each color using 8 bits. When the values are 0 and 1, the PWM duty cycle varies.

0 Likes
peya_1337906
Level 2
Level 2
Distributor - Weikeng(GC)
10 sign-ins 5 replies posted 5 questions asked

Hi ,

     There are 25 interrupts and pulses.   

if(bits >= 24)
    {
        bits = 0;
        PWM_Stop();
        pwmStop = 1;
    }
    else
    {
        PWM_WriteCompare(WS2811_Bit1);
        bits++;
    }

 

BestRegards

 

0 Likes

HI,

I think the problem actually arises from the fact that PWM is faster than interrupts.
I use a logic analyzer to capture the PWM waveform. Regardless of the number of counts, the actual generated PWM has a much higher than the number of counts from the Interrupt.

PWM.jpg

0 Likes
lock attach
Attachments are accessible only for community members.
JJack
Level 5
Level 5
Associated Partner - Distributor Rutronik
5 questions asked 25 likes received 100 sign-ins

Hi

JJack_1-1690454736705.png

This generates a burst of 24 PWM periods and avoids any interrupts.

Please find my sample code of above sketched idea attached. The code runs on a CY8CKIT-149 with PSoC4 4100S Plus. The PWM (period ~0.4 s) drives user LED1. Every overrun signal is routed through the trigger multiplexer and increments another TCPWM configured as counter. A compare match with the desired numbers of PWM periods triggers a jump into an interrupt service routine where the PWM-timer is stopped per software and the LED stops flashing.

Unfortunately, I could not make the compare match signal stop or kill the PWM-timer permanently. This would have spared the interrupt service routine.

Best regards

JJack

0 Likes