Searching \ for '[EE] How to fade a LED?' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=how+fade+led
Search entire site for: 'How to fade a LED?'.

Exact match. Not showing close matches.
PICList Thread
'[EE] How to fade a LED?'
2002\09\13@122701 by Magnus von Rosen

flavicon
face
Hi,

I would like to make a LED fade up and down by using a PICF628.
I imagine that it could be done by alternating periods of on/off.

However, it seems like a _lot_ of experimentation is required, or a
little experince.

Does anyone know how to best do this? Should the off-time be longer than
the on-time, or vice versa?
How should that be balanced during a cycle from dark to bright?
How is it done in an ordinary fading light for room lighting?

Thanks,

Magnus v Rosen, Sweden
spam_OUTpt98mvoTakeThisOuTspamstudent.bth.se

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam@spam@mitvma.mit.edu


2002\09\13@124357 by Brent A. Crosby

flavicon
face
Hook the LED to a pin that can be controlled by a PWM output timer. Set the frequency to  70Hz. Then vary the duty cycle between
0% and 100% linearly. If the LED takes a lot of current, you can drive it through a FET. Do not forget a current limiting resistor.

--- Original Message sent by Magnus von Rosen on Fri, 13 Sep 2002 18:26:22 +0200 ---
{Quote hidden}

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestspamspam_OUTmitvma.mit.edu


2002\09\13@124810 by Wouter van Ooijen

face picon face
> I would like to make a LED fade up and down by using a PICF628.
> I imagine that it could be done by alternating periods of on/off.

Be glad you don't use a 16f84, because a 16f628 has a PWM output that is
meant exactly for this purpose. Just wire a LED to the PWM output pin,
suitable resistor sets the 'full on' current, and use the pwm setting to
reduce the average current.

An example (just replace the low-pass filter with a LED + resistor):
http://www.voti.nl/fader/

Wouter van Ooijen

-- -------------------------------------------
Van Ooijen Technische Informatica: http://www.voti.nl
consultancy, development, PICmicro products

--
http://www.piclist.com hint: To leave the PICList
@spam@piclist-unsubscribe-requestKILLspamspammitvma.mit.edu


2002\09\13@132940 by Dal Wheeler

flavicon
face
You might look at setting your pwm values with a lookup table if you want to
have a smooth bloom and dim cycle.  LED's aren't linear on their percieved
light output.  When I did them the table was more logrithmic.   I ran into
this when working on a magic trick a few years ago...
-Dal
----- Original Message -----
From: "Magnus von Rosen" <KILLspampt98mvoKILLspamspamSTUDENT.BTH.SE>
Subject: [EE] How to fade a LED?


> Hi,
>
> I would like to make a LED fade up and down by using a PICF628.
> I imagine that it could be done by alternating periods of on/off.
>
> However, it seems like a _lot_ of experimentation is required, or a
> little experince.

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestTakeThisOuTspammitvma.mit.edu


2002\09\13@133205 by

flavicon
face
Magnus von Rosen wrote :
>Hi,
>
>I would like to make a LED fade up and down by using a PICF628.
>I imagine that it could be done by alternating periods of on/off.
>
>However, it seems like a _lot_ of experimentation is required, or a
>little experince.
>
>Does anyone know how to best do this? Should the off-time be longer than
>the on-time, or vice versa?

It depends on what "stage" you are in duringthe fade. You will
probably use both the whole range from 0 to 100% during the fade.

>How should that be balanced during a cycle from dark to bright?

Well, if the LED don't fade lineary to the PWD output, you could
always build a small "calibration" table with duty cycles to use to
get a "nice" fade.

>How is it done in an ordinary fading light for room lighting?

200/110 V room lightning is using AC, so there you use some
TRIAC (double thyristor, one for each half of the period) and
fire them at a point in time rellative to the "phase"
of the current. A whole different issue...

Jan-Erik Söderholm.

--
http://www.piclist.com hint: To leave the PICList
spamBeGonepiclist-unsubscribe-requestspamBeGonespammitvma.mit.edu


2002\09\13@153705 by Smith,Steven W

flavicon
face
If you didn't want to mess with the PWM (or needed it for something
else) then you could use a fixed clock cycle, a resistor and capacitor.
Put the Resistor from the output pin (fixed clock) and put the capacitor
to ground.  Then put the diode between the capacitor-resistor junction
and ground.  Adjust the RC time constant of the pair so you get a ramp
relative to your clock.  I found for example a 180 Ohm resistor with a
100uF cap was good for about 15 hertz.   There are lots of variations on
this -- using a FET/BJT or op-amp etc which would give you more control
over brightness and power consumption etc.  But the idea is the same, to
create a ramp with a RC time constant.  In the BJT/Op-amp Case you would
control the current through the LED with the BJT and the input to the
BJT is the junction between the CAP and resistor.  
Granted the PWM method is much more efficient and your time constant is
fixed with this type of fade.  - just another method to think about. This will fade both up and down without much software.  
Steve Smith
Electrical Engineer

--
http://www.piclist.com hint: To leave the PICList
TakeThisOuTpiclist-unsubscribe-requestEraseMEspamspam_OUTmitvma.mit.edu


2002\09\13@235215 by Spehro Pefhany

picon face
At 11:25 AM 9/13/02 -0600, you wrote:
>You might look at setting your pwm values with a lookup table if you want to
>have a smooth bloom and dim cycle.  LED's aren't linear on their percieved
>light output.  When I did them the table was more logrithmic.   I ran into
>this when working on a magic trick a few years ago...

Very true. To a first approximation, varying the duty cycle is the same as
varying the current through the LED due to the eye's average-reading response.

The eye's response is logarithmic, so you need to drop the PWM cycle time from
100% much more steeply than linearly. If you use 10-bit PWM and a LUT with
50-100 entries you'll do fine, IMHO. Interpolation would allow fewer
entries to be used.

> > However, it seems like a _lot_ of experimentation is required, or a
> > little experince.

Try building your table of entries using a little C (or whatever your
favorite program is). fprintf them to a file and include them in your
program. Once you get it working, probably only a few iterations will be
required.

Best regards,

Spehro Pefhany --"it's the network..."            "The Journey is the reward"
RemoveMEspeffspamTakeThisOuTinterlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestEraseMEspam.....mitvma.mit.edu


2002\09\14@064434 by Peter L. Peres

picon face
Led brightness ~= Led current

When driving a normal led with resistor with PWM you have

 Brightness ~= Iled ~= Ton/(Ton+Toff) * (Vcc - Vled) / Rlimit

The relation is not exact because Vled changes with the current.

Peter

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\09\14@064515 by Peter L. Peres

picon face
On Fri, 13 Sep 2002, Dal Wheeler wrote:

>You might look at setting your pwm values with a lookup table if you want to
>have a smooth bloom and dim cycle.  LED's aren't linear on their percieved
>light output.  When I did them the table was more logrithmic.   I ran into
>this when working on a magic trick a few years ago...

The led light output is VERY linear with led current at a given junction
temperature, but your eyes aren't. Brightness does not mean the same thing
when used between normal humans and engineers ... the eye sensitivity is
logarithmic, so are most other human senses (like hearing and heat/cold
sense f.ex.).

A lookup table is not necessary if you use a power of 2 in the stepping.

Peter

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\09\14@090851 by Bob Ammerman

picon face
For LEDs you should certainly be able to use software-based PWM with good
results. A PWM frequency of 100 Hz should be plenty.

Bob Ammerman
RAm Systems

{Original Message removed}

2002\09\14@114749 by Magnus von Rosen

flavicon
face
<On Sat, 14 Sep 2002, Magnus von Rosen wrote:
<
<> The application contains 4 LEDs (3 mm, 20 mA, 2 yellow, 1 red and 1
<> white) which need to be turned on and off with the cycle<

<Turned on and off as a group, or one at a time?
Individually.
The application is for a model car, where I have inputs for brake,
blinker left and blinker right, and reverse.
The lights are
1 yellow blinker left
--- ""  "" ----  right
1 white reverseligt
1 red brakelight.

Evert time a light is lit, it should fade on to give the purdiest
effect. :)

The state-machine approach seems like a good alternative, although I
have to think through the tabls a bit, I haven't done that before.
Scary, since I have (recently) a master's in software engineering...

Since this is becoming a too big exercise for my puny brain, I think C
is the language to use...

Thanks,
Magnus

<> In other words, I can't use the PWM? That only works on one pin at a
<> time, right?
<
<Yes, but if you're turning them on and off at the same time you can use
the PWM to drive a transistor or <MOSFET that controls the current to
all LEDs.

<Dale

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\09\14@130551 by Peter L. Peres

picon face
On Sat, 14 Sep 2002, Magnus von Rosen wrote:

>The state-machine approach seems like a good alternative, although I
>have to think through the tabls a bit, I haven't done that before.
>Scary, since I have (recently) a master's in software engineering...

Ah, now you say that. You can move the larger part of the state machine
into a timer ISR (and drop the delay() part). Then you can steer it from
your main code by setting flags. Atomic flags ;-)

>Since this is becoming a too big exercise for my puny brain, I think C
>is the language to use...

You can do it in assembly too but C is easier to maintain imho. If there
is no stringent need to save space or speed go with C.

Peter

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\09\14@174729 by Dale Botkin

flavicon
face
On Sat, 14 Sep 2002, Peter L. Peres wrote:

> On Sat, 14 Sep 2002, Magnus von Rosen wrote:
>
> >The state-machine approach seems like a good alternative
>
> Ah, now you say that. You can move the larger part of the state machine
> into a timer ISR (and drop the delay() part).

Funny you should mention that:

http://www.botkin.org/dale/led_pwm_control.htm

I have used this exact approach on a project I did that involved 160 or so
LEDs.  I used row & column addressing to turn LEDs on or off, and a
software PWM to control the brightness of the whole array.  Oh, did I
mention I did it in C?  8-)

Dale

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


More... (looser matching)
- Last day of these posts
- In 2002 , 2003 only
- Today
- New search...