You are here

Probleme with PWM | Cypress Semiconductor

Probleme with PWM

Summary: 2 Replies, Latest post by gaicher_1912301 on 30 Sep 2016 10:47 PM PDT
Verified Answers: 0
Last post
Log in to post new comments.
gaicher_1912301's picture
User
3 posts

Hi,

i made my first experiment with pwm on PSOC4 S Series Pioneer Kit and i want to create a breathing led.

It works, but sometimes there is a flashing on the red led. Can somebody give me a hint, why the flashing occurs?

 

I use a pwm with a period of 1000 and a clock frequency of 100kHz. The result is a pwm of 100Hz - this is ok!

The red led is connected on port 3[4].

This is my code:

#include <project.h>

uint32_t i=0;

int main()
{
    CyGlobalIntEnable; /* Enable global interrupts. */

    PWM_1_Start();

    for(;;)
    {
        for(i=0; i<999; i++)
        {
            PWM_1_WriteCompare(i);
            CyDelay(2);
        }
        for(i=999; i>1; i--)
        {
            PWM_1_WriteCompare(i);
            CyDelay(2);
        }
    }
}

user_1377889's picture
User
10440 posts

Welcome in the forum.

When you set the compare value to something that is actually larger than the current count, the counter will count down to zero and a new cycle is started. This will introduce flicker.

Your loops are executing a lot faster than the PWM clock runs. I would suggest you to try making a breathe on or off in a fixed time given as 0.5 seconds using a 1ms timer with an interrupt. This would allow the CPU working on some other jobs in parallel.

 

Bob

 

gaicher_1912301's picture
User
3 posts

Thank's Bob!

Now i increased the pwm-frequency and it works fine :-)

Please can you explain exactly, how it should work with the timer interrupt? Do you have an example?

Many thank's

Heimo

 

Log in to post new comments.