Forum : ST7/STM8
Post Information | Post |
---|---|
October 25, 2010 - 3:30am
|
hi, need some guidance about PWM codes. I had manage to get the chip and LED up and running, making it glow from off to on. however as i change to higher frequency from 100hz, 1khz still fine, but from 10khz onwards, the glowing effect just went off, it's just like blinking on and off. Below is my generalized code; while(1) So it's regarding the performance of the STM8 chip, please help enlighten me on how to change the counter freqeuency and can still produce the same pwm effect. |
Hi,
It looks like you are facing an overflow.
You did not post your full code, in particular we do not have the type for your variables.
Set these variables as "unsigned long": LED, Max_Brightness, Change_Rate, change.
This should fix your problem.
However be aware that using long variable is expensive in terms of code size and speed, so in a real application you may want to rework your algorithm in order to use only "unsigned int" variables, which are MUCH more efficient.
Regards,
Bruno