Shop OBEX P1 Docs P2 Docs Learn Events
Dimming LED with PWM? — Parallax Forums

Dimming LED with PWM?

CrosswindsCrosswinds Posts: 182
edited 2011-08-15 05:51 in Propeller 1
Hi Guys!

Well got my LED feeding issues sorted! So now ive start playing around and tried out to dim an LED, just to experiment with it.


I used the SquareWave object, but i could not find a frequency that made it "dim" just blink real fast, or stay on all the time.

Am i way out here or what am i doing wrong?

I both tested on a simple LED, and also my 12v G4 LED´s that i will use in the project!


Thanks

Comments

  • Heater.Heater. Posts: 21,230
    edited 2011-08-14 06:54
    Do you really mean square wave. Of course that will never dim, well if it's a high enough frequency it appears lit but at half brightness. At lower frequencies it will flicker or flash.
    Or does that object do pulse width modulation? I'd want to set the frequency to 100hz or so and change the amount of on time.
  • StefanL38StefanL38 Posts: 2,292
    edited 2011-08-14 07:15
    HI Crosswinds,

    old wisdom that I ( a medium old programmer) heard from really wise really old programmers:

    "your program does always what you have coded. If what your program does is somehthing different than you expected you don't really understand what you have coded.

    a squarewave is a signal half time on half time off. Feeding this into a LED makes the LED light up means the LED gets a current which is 50% of the current if the voltage would be on all the time (100%)
    In other words a squarewave is a PWM-signal with cnstant duty 50% (50% on time)

    You need a real PWM-signal and an object than can vary the duty from 0% up to 100%. For dimming the LED the ontime has to vary from 5= on =LED.off to 100% on LED gets current all the time.

    I had a quick look into some PE-Kit objects but I did not find a set and forget code using the counters.

    By set and forget I mean

    1.) configuring the a counter to operate as a PWM-generator and as long as I don't chance the duty-value the counter will produce the PWM-signal just alone
    without any repeat-loop in spin or PASM.

    2.) if a want to change the duty-value I write it once to the counter and after that the counter is able to produce an endless PWM-signal again.

    I can't believe it! 32 counter-modes and none of them is producing a self-sufficient-pwm-signal like described above?
    Is this really true? Do I have to engage a cog running code to create PWM?
    keep the explanations coming
    best regards

    Stefan
  • CrosswindsCrosswinds Posts: 182
    edited 2011-08-14 07:17
    Heater. wrote: »
    Do you really mean square wave. Of course that will never dim, well if it's a high enough frequency it appears lit but at half brightness. At lower frequencies it will flicker or flash.
    Or does that object do pulse width modulation? I'd want to set the frequency to 100hz or so and change the amount of on time.


    Mygod i feel stupid now. I jumped on the wrong stuff here :p

    But i have not gotten it to work! Used "Single-Ended DUTY Mode". Works great.

    But now i have discovered a problem with the G4 LED´s i bought. i get the 6 middle to do what they supposed to. But the 4 on the edges seem to stay on all the time. This is ofcourse how they are connected to each other.

    Stupid enough i did buy the ones that was not "dimmable" Since i tought the ones that is dimmable should have some special circuit made for some other dimmer. And these should just be stupid and work great with a microcontroller.

    If you have the time to have a look at the video and the picture, there may be some way to modify these to make them work?

    Link to picture: http://gallery.me.com/svenssondaniel/100034/IMG_0713

    Link to video: http://gallery.me.com/svenssondaniel/100034/IMG_0710


    Thanks for all your help man! Your'e great.
  • CrosswindsCrosswinds Posts: 182
    edited 2011-08-14 07:19
    Hey!

    Thank you very much for your informative reply!

    I noticed directly after posting my question that i had the stuff mixed up! :)

    StefanL38 wrote: »
    HI Crosswinds,

    old wisdom that I ( a medium old programmer) heard from really wise really old programmers:

    "your program does always what you have coded. If what your program does is somehthing different than you expected you don't really understand what you have coded.

    a squarewave is a signal half time on half time off. Feeding this into a LED makes the LED light up means the LED gets a current which is 50% of the current if the voltage would be on all the time (100%)
    In other words a squarewave is a PWM-signal with cnstant duty 50% (50% on time)

    You need a real PWM-signal and an object than can vary the duty from 0% up to 100%. For dimming the LED the ontime has to vary from 5= on =LED.off to 100% on LED gets current all the time.

    I had a quick look into some PE-Kit objects but I did not find a set and forget code using the counters.

    By set and forget I mean

    1.) configuring the a counter to operate as a PWM-generator and as long as I don't chance the duty-value the counter will produce the PWM-signal just alone
    without any repeat-loop in spin or PASM.

    2.) if a want to change the duty-value I write it once to the counter and after that the counter is able to produce an endless PWM-signal again.

    I can't believe it! 32 counter-modes and none of them is producing a self-sufficient-pwm-signal like described above?
    Is this really true? Do I have to engage a cog running code to create PWM?
    keep the explanations coming
    best regards

    Stefan
  • Heater.Heater. Posts: 21,230
    edited 2011-08-14 08:05
    This is confusing, we now have two threads for the one project.
    Now I'm at a loss. If what you say is true about there only being a rectifier in the lamps I can't think what would make them not dimmable.
  • CrosswindsCrosswinds Posts: 182
    edited 2011-08-14 08:46
    Heater. wrote: »
    This is confusing, we now have two threads for the one project.
    Now I'm at a loss. If what you say is true about there only being a rectifier in the lamps I can't think what would make them not dimmable.

    Hello again Heater!


    Sorry if im confusing you, but the other thread were about a way to drive these suckers. In this case a ULN-IC!

    This thread is about dimming them via PWM! Have had a chance to take a look at the photo and the video i linked to?

    There you can see there is 4 resistors and one rectifier? I just cant see any other components. And as you can see in the video, they do dim, but i cannot see why the 4 outer LED´s dont?
  • smbakersmbaker Posts: 164
    edited 2011-08-14 09:58
    Is it possible the outer 4 are a different spectrum than the inner 6? From the video it looked like there was some dimming going on with the outer LEDs, although perhaps not as much. The inner LEDs also looked a bit bluer to me than the outer ones. Then again, it could be some auto-exposure settings on the camera tricking me.

    Given that there are 4 resistors and 10 LEDs, we also have to wonder about the configuration. Could be the middle groups are wired 3 LEDs + 1 resistor and the outer groups are wired 2 LEDs + 1 resistor. Different configuration causes different characteristics?

    Just a few guesses...
  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-08-14 10:46
    And as you can see in the video, they do dim, but i cannot see why the 4 outer LED´s dont?

    The board is probably designed for AC, using the positive half-cycles for one set of LEDs and the negative half-cycles for the others. I've seen this in 120VAC LED strings.
  • Heater.Heater. Posts: 21,230
    edited 2011-08-14 10:51
    Interesting. But then why would they all light in some way from a D.C. Supply?
  • kwinnkwinn Posts: 8,697
    edited 2011-08-14 11:06
    Posting a part number or schematic for the LED string would probably make the answer to most of these questions clear.
  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-08-14 11:31
    Posting a part number or schematic for the LED string would probably make the answer to most of these questions clear.

    Excellent point. A link to a data sheet for the module would be very helpful.
  • CrosswindsCrosswinds Posts: 182
    edited 2011-08-15 05:51
    kwinn wrote: »
    Posting a part number or schematic for the LED string would probably make the answer to most of these questions clear.

    Thats a good point! :) I will try to contact the seller to see if i can get a schematic.

    But i would think that the 6 in the middle is in series, and the 2 on the sides are in series just with eachother. Making these "rails" uneven? Would that be a teory?
Sign In or Register to comment.