Shop OBEX P1 Docs P2 Docs Learn Events
Very simple dimmer? — Parallax Forums

Very simple dimmer?

eagletalontimeagletalontim Posts: 1,399
edited 2008-06-21 22:00 in General Discussion
I am attempting to dim a 2v LED at a specified rate with just 1 pin from the SX chip and no other extra circuitry from that pin. Is this possible?

Here is kind of what i want to do :

dim_pin VAR RB.4
dim_rate VAR Byte

Main:
dim_pin = do_dim dim_rate
GOTO Main

do_dim:
'Dim function or sub
RETURN

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2008-06-21 17:28
    I would put a resistor (270 ohm or greater) in series with the led,
    and then use the PWM command, changing the dutycycle to
    control the led intensity.

    regards peter
  • eagletalontimeagletalontim Posts: 1,399
    edited 2008-06-21 17:30
    I thought the PWM command only charges, not discharges. I am using a 33k in line with the LED. Any code examples for making the LED dim down and not up?
  • BeanBean Posts: 8,129
    edited 2008-06-21 17:33
    The PWM command makes the pin HIGH and LOW while it is active.
    When the PWM command is finished, it makes the pin an INPUT.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Uhhhm, that was on fire when I got here...

    www.iElectronicDesigns.com

    ·
  • eagletalontimeagletalontim Posts: 1,399
    edited 2008-06-21 17:40
    so something like this would work?

    RB.4 = 1
    PWM RB.4, 0, 1000
    ....running something else even while the PWM command is still working
  • eagletalontimeagletalontim Posts: 1,399
    edited 2008-06-21 17:51
    hmmm...this is really confusing me.

    RB.3 = 1
    PWM RB.3, 1, 2000

    It turns the LED on for a spit second at a low voltage, but it does not dim or brighten. What do I have wrong?
  • BeanBean Posts: 8,129
    edited 2008-06-21 17:58
    If you want to dim the LED you'll have to make a loop that decreases the PWM dutycycle value.

    FOR temp=255 TO 0 STEP -1
    · PWM RB.3, temp, 10
    NEXT

    Also why are you doing "RB.3 = 1" ?

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Uhhhm, that was on fire when I got here...

    www.iElectronicDesigns.com

    ·
  • eagletalontimeagletalontim Posts: 1,399
    edited 2008-06-21 18:08
    Thanks for the code [noparse]:)[/noparse] I found that i had to use the FOR NEXT commands, but i could not figure out how to go down instead of up. I am using RB.3 = 1 to turn on the LED before some other code is run, then after the code is done, it slowly dims the led. I think i got it working [noparse]:)[/noparse]
  • StarManStarMan Posts: 306
    edited 2008-06-21 18:37
    I did <this> a while back.· It worked pretty well. The dimming was very smooth.

    Are you sure you're using a 33k resistor?· I wouldn't expect to see any light at all with that.· The suggested 270 ohm sounds more like it.· If the LED can handle 20mA, you could go as low as 150 ohms for max brightness.

    Chris I.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-06-21 21:21
    This is neither the where-all nor end-all, but it may be of value to you --
    ' 5 Intensities
    
    FOR Hi_Nib = 0 TO 4
      FOR Byt_Part = $00 TO $FF
        HIGH RA.3
        PAUSEUS 100
        LOW RA.3
        PAUSEUS 900
        NEXT Byt_Part
      NEXT Hi_Nib
     
    FOR Hi_Nib = 0 TO 4
      FOR Byt_Part = $00 TO $FF
        HIGH RA.3
        PAUSEUS 250
        LOW RA.3
        PAUSEUS 750
        NEXT Byt_Part
      NEXT Hi_Nib
     
    FOR Hi_Nib = 0 TO 4
      FOR Byt_Part = $00 TO $FF
        HIGH RA.3
        PAUSEUS 500
        LOW RA.3
        PAUSEUS 500
        NEXT Byt_Part
      NEXT Hi_Nib
     
    FOR Hi_Nib = 0 TO 4
      FOR Byt_Part = $00 TO $FF
        HIGH RA.3
        PAUSEUS 750
        LOW RA.3
        PAUSEUS 250
        NEXT Byt_Part
      NEXT Hi_Nib
     
    FOR Hi_Nib = 0 TO 4
      FOR Byt_Part = $00 TO $FF
        HIGH RA.3
        PAUSEUS 950
        LOW RA.3
        PAUSEUS 50
        NEXT Byt_Part
      NEXT Hi_Nib
    
  • BeanBean Posts: 8,129
    edited 2008-06-21 22:00
    Peter,
    · Just FYI "RA.3 = 1" executes much faster (and generate less code) than "HIGH RA.3" because HIGH and LOW always sets the direction bit. Of course you must make sure the pin is already an output.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Uhhhm, that was on fire when I got here...

    www.iElectronicDesigns.com

    ·
Sign In or Register to comment.