Shop OBEX P1 Docs P2 Docs Learn Events
PWMPal LED dimmer? — Parallax Forums

PWMPal LED dimmer?

InteractivesInteractives Posts: 83
edited 2007-07-02 15:12 in BASIC Stamp
Good evening,

For a long time now I have been aspiring to reproduce the wonderful glow of the old G4 Macintosh on/off buttons. It is clearly a white LED that ramps up, and then ramps down repeatedly- resulting in a wonderful glow that seems to be breathing. I just cracked open my PWMpal, which I have ordered to attempt recreating this look. However, the documentation does not make it 100% obvious how I would go about programming this feat. I have replaced the DC motor with a bank of LEDs using the PWMPla_simple_motor.BS2 files, but the lights dont ramp up smoothly. I have attempted the same circuit using plain old resistors+capacitors, but have never been able to produce anything as lovely. Any help/advice would be greatly appreciated! Thanks

Comments

  • InteractivesInteractives Posts: 83
    edited 2007-07-01 22:14
    Thanks guys. Really
  • TechnoRobboTechnoRobbo Posts: 323
    edited 2007-07-02 02:24
    Try using an omp amp as a voltage to current converter.

    Heres an example:

    ·attachment.php?attachmentid=48001

    and some code to test it.

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    x VAR Word
    DO
    'ramp up
    FOR x=0 TO·80
    · PWM 0,x,50
    NEXT
    'pause & hold
    FOR x=0 TO 5
    · PWM 0,80,50
    NEXT
    'ramp down
    FOR x=80 TO 0
    · PWM 0,x,50
    NEXT
    'pause & hold
    FOR x=0 TO 10
    · PWM 0,0,50
    NEXT
    LOOP


    When testing LED dimmers it's best to have a non-dimmed LED next to the dimmed one as a reference, because your eyes compensate for brightness. You don't·have to use the full throttling range of the PWM command to achieve the effect you want - a value of 80 yields 6.274 mA. The op amp gives you a very linear rise in current and pwm gives you a linear rise in voltage so the dimming is very controlled. Increasing the OpAMP voltage allows you to make the LED brighter. 7.5 volts on the op ampallows you to goto to 12 mA using a 160 output from the PWM command.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Have Fun


    TR

    Post Edited (TechnoRobbo) : 7/2/2007 10:41:04 AM GMT
    720 x 379 - 21K
  • Desy2820Desy2820 Posts: 138
    edited 2007-07-02 03:13
    Have you tried adding a resistor/capicitor circuit to the PWM Pal's output?· It might smooth out the response.· Check the WAM text for an example.

    I don't think the LED's have a linear response to the PWM Pal.· You may need to experiment with percieved brightness vs. power level.·

    I'm not familair with the orginal effect you're trying to get, but maybe try randomizing the brightness levels within a certain range?· You may need to set a lower range for dim and an upper range for the bright.·

    Trying to help!
  • metron9metron9 Posts: 1,100
    edited 2007-07-02 05:07
    Tell me how long you want the led to go from dim to full and back again. I am using a tiny11 to do just that on a project. I will reprogram the cycle to whatever time frame you want and send you a chip if you PM me with your address. These chips only cost me .35 cents so the postage is actually more than the chip, but no charge because I just like to help out now and then. I am thinking of marketing some of my drum lights in this configuration to make that living breathing feeling. My swimming pool fiber optic system does the same thing and varies colors as well. I may program up one that will have 3 outpins where they psudo randomly fade up and down between the three pins so a red/blue/green led could be used instead of just one color. I may have to use a tiny13 to get the speed though.

    It runs at 1mhz at 5V. You can run it on a single LED at 20ma or add a fet for higher amp LED's. I use LuxeonIII and run 1AMP through a mosfet.
    If you vary the voltage from 5V down to 2.7V you can change the cycle time as well as the on chip oscillator is dependent on the voltage supplied to the chip.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-07-02 06:45
    Is there some reason you want to use the PWMPAL? The Stamp with a resistor and the LED can do a decent job of pretending to be a Mac. The human eye can't really discern the high frequency pulsing in freqout or PWM.
    .          270      LED
    p0 ----/\/\---->|-----o Vss
    


    The following puts out a 1 hertz sine wave, which looks petty smooth...
    DO
       FREQOUT 0,10000,1
    LOOP
    


    but that is faster than the G4 pulsation. Try something like this...

    idx VAR byte
    x VAR byte
    DO
      FOR idx=0 TO 128
        x=64 + 320 */ SIN idx
        PWM 6, x, 16 - (x/16)
      NEXT
    LOOP
    



    That steps through 1/2 of a cycle, so SINe goes from zero to maximum and back to zero. The formula that starts with "x =" adds an offset (so the LED won't go completely off), and scales the values from 64 to 255. That is what is output as PWM, at nominally 16 cycles per step, which makes it pulsate at about 3 seconds period. However, one more refinement, the amount of time spent at high value of x is decreased. That is to compensate for the logarithmic perception of light intensity by the eye. You just have to play with it until it matches the tempo and timber of the Mac G4 light. I think you could use the same sort of logic with the PWMPAL.

    The Stamp can't do anything else while it is pulsing the light though. Metron9's chip would be a good deal!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • TechnoRobboTechnoRobbo Posts: 323
    edited 2007-07-02 10:24
    I added the following sentence to my previous post:

    "Increasing the OpAMP voltage allows you to make the LED brighter. 7.5 volts on the op ampallows you to goto to 12 mA using a 160 output from the PWM command."

    And I changed the PWM duration to 50 (oops). I'm sure you can port this circuit to the PWMPAL.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Have Fun


    TR

    Post Edited (TechnoRobbo) : 7/2/2007 10:59:57 AM GMT
  • metron9metron9 Posts: 1,100
    edited 2007-07-02 15:12
    Here is the code for a tiny11 fader. The assembly is pretty easy to read is you want to port it to another language. I am not using interrupts so the chip is dedicated to the task. That is the nice thing about these cheap little chips, they can be programmed for tiny dedicated tasks.
    I added some comments to some of the code. I accelerate the duty cycle curve at higher duty cycles and slow it down on lower duty cycles to make the fade look better.

    .include "tn11def.inc"
    
    ; 3.17mA active 
    ; 1MHZ internal oscillator
    
    
    .def     temp        =    r16
    .def    Toff        =    r17
    .def    hold        =    r18
    .def    FBflag        =    r19
    .def     hold1         =    r20
    
    rjmp    RESET        ; Reset handler
    rjmp    EXT_INT0    ; IRQ0 handler
    rjmp    PIN_CHANGE    ; Pin change handler
    rjmp    TIM0_OVF    ; Timer0 overflow handler
    rjmp    ANA_COMP    ; Analog Comparator handler
    
    
    RESET:
    
    ldi r16,0b00001000
    out ddrb,r16
    ldi toff,1
    ldi temp,0
    ldi hold,230
    ldi hold1,230
    
    ldi temp,(1<<ACD)    ;Disable Analog Comparator (to save power)
    out ACSR,temp
     
    MAIN:
    inc temp     ;TEMP=TEMP+1
    brne not0    ;IF TEMP IS NOT EQUAL TO 0 THEN GOTO NOT0
    sbi portb,3   ;TURN ON LED
    not0:
    cp temp,Toff ; COMPARE TEMP WITH TOFF
    brne notoff   ; IF TEMP AND TOFF ARE NOT EQUAL THEN GOTO NOTOFF
    cbi portb,3   ; TURN LED OFF
    rjmp slide     ;GOTO SLIDE
    notoff:
    rjmp main
    
    slide:
    ;Note-- I buffer the duty cycle so it only can change when the led is off
    inc hold              ;HOLD=HOLD+1
    brne main           ;IF HOLD IS NOT EQUAL TO 0 THEN GOTO MAIN
    mov hold,hold1    ;HOLD=HOLD1
    
    
    cpi FBflag,0        ;test if going up or down in intensity
    breq UP             ; it is up so goto up
    DOWN:              
    dec toff             ;going down so decrement the duty cycle pointer
    breq reversit       ;if duty cycle is zero then goto reverseit
    
    cpi toff,64          ;compare toff with 64
    brlo main            ;if it is lower goto main
    dec toff             ;it is higher so decrement toff
    breq reversit       ;if toff is greater then 255 (rolls over when incremented from 255 to 0) then goto reversit 
    
    cpi toff,127        ;
    brlo main
    dec toff
    brne main
    
    reversit:
    ldi FBflag,0
    inc toff
    rjmp main
    
    UP:
    inc Toff
    breq reversit1
    
    cpi toff,64
    brlo main
    inc toff
    breq reversit1
    
    cpi toff,127
    brlo main
    inc toff
    brne main
    
    reversit1:
    ldi FBflag,1
    dec Toff
    rjmp main
    
    
    EXT_INT0:    ; IRQ0 handler 
    RETI
    PIN_CHANGE:    ;Pin change handler
    RETI
    TIM0_OVF:    ; Timer0 overflow handler
    reti
    ANA_COMP:    ; Analog Comparator handler
    RETI
    
    
    
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
Sign In or Register to comment.