- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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