Is this PWM reaction normal?
ERM
Posts: 34
Hi everybody,
Does anyone have an answer to this glitch I've noticed. Using the program below, I've noticed that when the led's I have on each pin fade on and off back and forth, the led that should be out lights dimly. This happens even when you take out the second half of the program to flash 1 by itself. Led 2 will light dimly and go out.
Any thoughts or remedies?
fade:
FOR fade = 255 TO 1 STEP 5
PWM 1, 255 - fade, 1
NEXT
FOR fade = 1 TO 255 STEP 5
PWM 1, 255 - fade, 1
NEXT
FOR fade = 255 TO 1 STEP 5
PWM 2, 255 - fade, 1
NEXT
FOR fade = 1 TO 255 STEP 5
PWM 2, 255 - fade, 1
NEXT
goto fade
Does anyone have an answer to this glitch I've noticed. Using the program below, I've noticed that when the led's I have on each pin fade on and off back and forth, the led that should be out lights dimly. This happens even when you take out the second half of the program to flash 1 by itself. Led 2 will light dimly and go out.
Any thoughts or remedies?
fade:
FOR fade = 255 TO 1 STEP 5
PWM 1, 255 - fade, 1
NEXT
FOR fade = 1 TO 255 STEP 5
PWM 1, 255 - fade, 1
NEXT
FOR fade = 255 TO 1 STEP 5
PWM 2, 255 - fade, 1
NEXT
FOR fade = 1 TO 255 STEP 5
PWM 2, 255 - fade, 1
NEXT
goto fade
Comments
When the PWM command finishes it puts the pin into an INPUT state.
I'm not sure why that would make your LEDs stay on dimmly though ???
Can you post a schematic ?
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
"I reject your reality, and substitute my own." Mythbusters
·
Just for the record, the program listed can not be the operational program, since it contains syntactical errors. The problem may be more self-evident if we can see the actual, operational program.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
The setup consists of both pins going to their own transistor through a resistor to control the leds.
The scenario, as led 1 lights up, led 2 lights up dimly and diminishes when led 1 dims out and vice versa when led 2 lights.
The same happens with the other outputs if led's are connected to pins 3, 4, and so on. As led 1 or 2 lights, the other leds on the other outputs light dimly all together.
' {$STAMP BS2}
' {$PBASIC 2.5}
fade VAR Word
BtnWk VAR Byte
singlefade:
FOR fade = 255 TO 1 STEP 5
PWM 1, 255 - fade, 1
NEXT
FOR fade = 1 TO 255 STEP 5
PWM 1, 255 - fade, 1
NEXT
FOR fade = 255 TO 1 STEP 5
PWM 2, 255 - fade, 1
NEXT
FOR fade = 1 TO 255 STEP 5
PWM 2, 255 - fade, 1
NEXT
GOTO singlefade
FOR fade=0 TO 255 STEP 5
PWM 1,fade,1
HIGH 1 '<---definite HIGH
NEXT
FOR fade=255 TO 0 STEP 5
PWM 1,fade,1
LOW 1 '<-- definiite LOW
NEXT[noparse][[/noparse]/code]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
singlefade:
FOR fade = 0 TO 255
PWM 1, fade, 9
NEXT
FOR fade = 255 TO 0
PWM 1, fade, 9
NEXT
GOTO singlefade
and the result is that led 1 slowly lights up, and here's the twist, no matter what output pin I use 0-15 minus number one which I am already using, the led on that pin will light dimly increasing in intensity and then extinguish as pin 1 reaches its maximum intensity and then the other led's will light dimly again as led 1 begins its "fall" and the others will dim out.
Can anyone else reproduce this problem? I chose 9 for the rate so I can see what happens in "slow motion". The attached picture is an example of how I have my setup coming off of the output to a transistor that controls a higher load. When I connect a second one of these arrays to any other output, I get the above result. Can anybody figure this out?
Thanks,
Tony
See what happens when you add a blocking diode, as in the modified version of your schematic, which is attached. My first inclination is that there·may be a +VDC back-feed through the ground plane. If so, the blocking diode·should prevent it from affecting your circuitry.
If I'm wrong, stop taking advice from software guys like me :-)
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
Post Edited (Bruce Bates) : 6/11/2006 7:20:53 AM GMT
Maybe he should pull those lines low (through a resistor) to ensure the transister for the other banks of LED's stays OFF.
Post Edited (grimshady) : 6/11/2006 12:26:44 PM GMT
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
"I reject your reality, and substitute my own." Mythbusters
·
I have a web page writeup on this at www.emesys.com/BS2PWM.htm
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Also, the base has to at least reach 0.7v to overcome the base,emmiter junction so the pin not only has to rise up more than 0.7V but also source enough current to accomdate the hfe of the transistor.· He's running 60ma I guess through the transistor so what does he need to get the transistor to turn on a little...like maybe 3ma?
I'll go read your link, maybe all my questions are already answered.
There might also be leakage current from the Stamp input pin, but that current would only be femtoamps. A 100pf capacitor in parallel with the pin or from base to emitter should easily shunt the high frequency current spike away from the base. Or, for the solution with no additional components in Tony's application, simply make the pin a definite LOW or HIGH output after completion of the PWM command, instead of leaving it as an input. That is not an option when you want to use PWM as a DAC.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
singlefade:
·FOR fade = 0 TO 255
·PWM 1, fade, 9
·NEXT
·FOR fade = 255 TO 0
·PWM 1, fade, 9
·NEXT
·GOTO singlefade
Maybe that's a "typo"?· I believe that it should be:
singlefade:
·FOR fade = 0 TO 255
·PWM 1, fade, 9
·NEXT
·FOR fade = 255 TO 0 STEP -1
·PWM 1, fade, 9
·NEXT
·GOTO singlefade
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
Use the IF...THEN...ELSE form of the IF statement rather than the IF...THEN format, and that THEN....GO TO restriction will disapper.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
I think only bs2 has the good stuff.
I didn't mean to threadjack (actually did but I dont want to pull this thread away from its original topic so please no more posts on my IF then problem).· PM me if you want to add to this.·· I've deleted my original message.
To get this back on topic, I'm using the PWM command also and getting unexpected results..maybe due to impropper byte variable use.
PWM is the topic. ...I"ll go back and read that page more carefully...wish I was using a bs2!!!
Post Edited (grimshady) : 6/12/2006 10:33:42 AM GMT