Shop OBEX P1 Docs P2 Docs Learn Events
PWM and LED Problem — Parallax Forums

PWM and LED Problem

WolfWolf Posts: 1
edited 2008-05-07 02:26 in BASIC Stamp
I have a LED that fades from·OFF to ON

I start by setting the pin LOW then running the pwm 0 - 255 and finish by setting the pin to HIGH.

It fades just fine except for one transition.· The problem occurs when it goes from 255 to HIGH.· It seems to jump in brightness as if the PWM stopped at 225 and then went HIGH.· Now I know this is not the case but its the best way I can explain the amount of brightness jump that is happening.·

I just need to know why it does this and how I can stop it from happening.· Here is the code:


LOW 1 ' LED completely off
FOR B2 = 0 TO 255 ' Loop from off to on.
PWM 1, B2,5 ' Output one burst of pwm.
NEXT
HIGH 1 ' Leave LED on. (this is where the brightness jump happens)

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-05-07 02:26
    The problem you're seeing is due to the intervals between your PWM statements, where the LED isn't getting driven at all. So, at 255, the LED is not receiving a 100% "on" signal. You can alleviate this by lengthening the PWM interval from 5 to a higher number. If the brightness increases too slowly, increment in steps larger than 1. Also, if you don't mind not starting at zero intensity, you could put the HIGH inside the FOR/NEXT loop, just before the NEXT.

    Another thing that may help is to add an electrolytic capacitor across the LED's leads. This will maintain some current drive between PWMs.

    -Phil
Sign In or Register to comment.