leds fading in and out
Archiver
Posts: 46,084
Hi all...
I have project on the go that is making 16 leds fade in and out using
pwm through a darlington array (one pin controling all 16). The
trouble is that the fade is not very smooth and I need to be able to
adjust the time it takes to fade in and out. (not in real time, but
just when we are setting it up). The goal is to replicate the
pulsating effect seen on the new apple ibooks when they are asleep.
at the moment I am going straight into the darlington array from the
IO pin. Is there a way to buffer the output from the IO pin? or is
there some better way altogether?
many thanks
Chris
I have project on the go that is making 16 leds fade in and out using
pwm through a darlington array (one pin controling all 16). The
trouble is that the fade is not very smooth and I need to be able to
adjust the time it takes to fade in and out. (not in real time, but
just when we are setting it up). The goal is to replicate the
pulsating effect seen on the new apple ibooks when they are asleep.
at the moment I am going straight into the darlington array from the
IO pin. Is there a way to buffer the output from the IO pin? or is
there some better way altogether?
many thanks
Chris
Comments
software or hardware...
A properly sized cap from the stamp's output pin to ground might help. Set the
RC constant to some fraction of your "fade in" time. For example, if you want
to fade from off to on in 500 msec (in 50 msec steps), set RC to something like
250 msec. But let's see that code.
Clark Hughes
untestedchris wrote:
>
> Hi all...
code is as follows
(lightsTimer is worked out by monitoring the amount of daylight when
it gets dark the lights come on for an equivalent amount of time)
for Reps = 1 to lightsTimer
'fade in leds
for PWM_reps = 30 to 170
pwm darlingtonPin,PWM_reps,20
next
'fade out leds
for PWM_reps = 170 to 30
pwm darlingtonPin,PWM_reps,20
next
next
Does that mean you see it getting brighter and brighter in discrete steps, and
ditto on dimming? Is this a BS2? If so, it looks like the routine will take
about 3 seconds to fade on, 3 seconds to fade off. Is this what you're seeing?
I don't follow what you are doing with "lightsTimer" -- it looks like that just
sets the number of fade-in fade-out cycles. Do you have any capacitance from
the stamp's output pin to ground? I'm thinking 10 uF would help if you don't
have anything there currently.
Clark Hughes
untestedchris wrote:
>
> thanks for the quick response
>
> code is as follows
>
> (lightsTimer is worked out by monitoring the amount of daylight when
> it gets dark the lights come on for an equivalent amount of time)
>
> for Reps = 1 to lightsTimer
> 'fade in leds
> for PWM_reps = 30 to 170
> pwm darlingtonPin,PWM_reps,20
> next
> 'fade out leds
> for PWM_reps = 170 to 30
> pwm darlingtonPin,PWM_reps,20
> next
> next
>
darlington so I'll add a cap. Should I have a resister too?
and the discrete steps are a lot more evident at the lower voltages.
and lightstimer just repeats the fade in/out sequence... and one fade
in /out cycle is indeed 6 seconds.
Chris
--- In basicstamps@y..., "J. Clark Hughes" <jchughes@a...> wrote:
> Ok. And what exactly is the symptom? You said "the fade is not
very smooth."
> Does that mean you see it getting brighter and brighter in discrete
steps, and
> ditto on dimming? Is this a BS2? If so, it looks like the routine
will take
> about 3 seconds to fade on, 3 seconds to fade off. Is this what
you're seeing?
> I don't follow what you are doing with "lightsTimer" -- it looks
like that just
> sets the number of fade-in fade-out cycles. Do you have any
capacitance from
> the stamp's output pin to ground? I'm thinking 10 uF would help if
you don't
> have anything there currently.
and it is that apparent resistance that you need to consider as you calculate
the time constant. Good luck.
Clark
untestedchris wrote:
>
> its a BS2e, I've currently got nothing between the pin and the
> darlington so I'll add a cap. Should I have a resister too?
>
> and the discrete steps are a lot more evident at the lower voltages.
>
> and lightstimer just repeats the fade in/out sequence... and one fade
> in /out cycle is indeed 6 seconds.
>
> Chris
I'm not sure what you mean by, "at the moment I am going straight
into the darlington array from the
IO pin". There are several possible circuit configurations, even
using just one transistor in the array.
My inclination would be to hook the transistor up as an emitter
follower, with the leds and resistors in parallel in the emitter
circuit of the darlington.
+9
|/
P0 ----| npn common collector
|\,
\-/\/\-->|----ground
|-/\/\-->|----
|-...
R leds
The transistor in the circuit can operate in a mode where it turns on
and off very fast and transfers the PWM directly to the LED circuit,
or the transistor can operate in a mode where it averages the PWM to
force an average voltage across the leds. This depends on the
intrinsic speed of the transistor. Darlingtons are notoriously slow
acting as switches, but they still might be fast enough for this
circuit. If the transistors are fast, the response to PWM will be
smooth right from zero PWM up to maximum. With a slow transistor,
the circuit will tend to average the current, which should be okay,
but I think there will be more of a threshold effect (not quite as
linear). Adding a capacitor from the base to ground will definitely
put the circuit into the averaging mode.
Of course, one transistor can drive only a limited number of leds,
due to its power and current ratings. Use more transistors from the
array to drive more leds.
To see the smooth pwm effect with the PWM or freqout command, connect
the led directly to a stamp pin, with a series resistor:
P0 ----/\/\-->|----ground
220 led
freqout 0,5000,1000,1001 ' nice 1 hertz beat effect, pulsing led at 1 hz.
If you have the transistor hooked up as a common emitter switch, I
think there would be trouble...
R leds
|-...
|-/\/\--|<----+9
|-/\/\--|<----
/
|/
P0 -/\/\-| npn common emitter
|\,
|
ground
I doubt if the darlingtons could respond fast enough in that circuit
to switch the leds and you would see a rather abrupt transition from
off to on. A faster transistor or mosfet switch would work, but you
have to remember that the PWM pulses are quite a high in the
frequency spectrum (4 microsecond time slots). The common emitter
configuration is the slowest configuration, and darlington
transistors are the slowest transistors. A capacitor on the base in
this circuit will only make things worse.
Another circuit is an current sink. This is similar to the last one,
except you put a resistor in the emitter circuit:
leds
|---|<--|<--|<- +12
/
|/
P0
| npn common base
|\,
e|--/\/\-ground
100
The 200 ohm resistor between the emitter and ground causes the
current in the leds to be switched from 0 ma to 20 ma. As above,
this can happen either at the PWM rate, or the PWM can be averaged by
the darlington transistor itself or with a capacitor from the base to
ground, to give an average current. This circuit is shown with
several leds in series (all carry the same current, and note the
higher power supply voltage.)
I hope those alternatives help...
-- regards,
Tracy Allen
electronically monitored ecosystems
mailto:tracy@e...
http://www.emesystems.com
>Hi all...
>
>I have project on the go that is making 16 leds fade in and out using
>pwm through a darlington array (one pin controling all 16). The
>trouble is that the fade is not very smooth and I need to be able to
>adjust the time it takes to fade in and out. (not in real time, but
>just when we are setting it up). The goal is to replicate the
>pulsating effect seen on the new apple ibooks when they are asleep.
>
>at the moment I am going straight into the darlington array from the
>IO pin. Is there a way to buffer the output from the IO pin? or is
>there some better way altogether?
>many thanks
>Chris
fading LED problem.
I thought I'd let you know what I ended up doing.
Firstly thanks to Tracy for the great description of what the
darlington array was up to. I've now replaced this with a single
transistor.
My main problem however was the PWM from the stamp which I
was unable to filter enough across the full range of the fade. I
am now using the DS1267 digital pot which is fantastic and
allows me to have greater control of the fade.
if any one needs a true analog output I would recommend the
DS1267, and Scott Edwards' nuts and volts article is a superb
starting point.
cheers
Chris