Quote Originally Posted by ruijc View Post
Hi all,

I have a question regarding PWM.
I'm using PWM to fade in/out a LED on a 12F675 with the code below.

Code:
For steps=255 TO 1 STEP -1
pwm white,steps,2
Next
I'm looking for a linear result but is not working.
When the led is almost off the speed increases ( which is obvious since the pic is using less bits to count ).

My question is, is there a workarround to minimize this effect and make the fade out/in more linear ?

Thanks
Have your PWM command inside a TIMER overflow.

Like,
Code:
For steps=255 TO 1 STEP -1
TMR1IF = 0
WHILE TMR1IF = 0  
 pwm white,steps,2
WEND
Next
Thus, you get the same time of speed for each PWM step.

------------