So you have a button and some LEDs. When somebody presses the button,
you want the LEDs to turn on sequentially while the button is being
held. Then, when you release the button, the LEDs that are lit go off in
the opposite order from the one they lit in. The delay between lighting
of subsequent LEDs must be adjustable, and different from the adjustable
delay for turning them off. While the LEDs are turning off, pushing the
button again has no effect until all the LEDs are off, at which time, it
begins to light the LEDs sequentially.
It sounds like the effect you are going for is like a button which fills
up a pool. Hold the button, the pool fills, let it go, the pool drains.
A capacitor to ground is like a pool which holds charge. If you pour
charge in at a fixed rate, the voltage will increase at a fixed rate.
You fill the capacitor from V+, and drain it to V-. Thus, the rate of
filling and draining can be controlled separately.
For this to work, you need three things.
1) A way to accurately add and drain charge from a capacitor.
2) A way to detect that the capactor has reached a partiular voltage
level, and then turn on an LED.
3) A way to prevent the button from working between the time it's been
released, and when the LEDs are all off.
For 1, you use what is called a current source to both fill and drain
the charge. These can easily be built using either discrete transistors,
or voltage regulators. One trick is to make the draining current
'source' about twice as big as the filling one. Then, you can just leave
them on, and when you want to fill, turn off the draining one.
For 2, you need a way to detect that a particular voltage has been
reached, and change something else. A device called a 'comparator' is
used for this. A comparator does what it's name implies, it compares the
voltage on it's two inputs. The two inputs are called V+ and V-. If the
V+ is lower than the V-, it pulls the output to ground. Otherwise, it
lets the output float. This is just what you want. You connect each LED
between the Vcc rail (the high voltage supply) and the output of the
comparator with a resistor to limit the current. Then, you set the V+
input of the comparator to some value using a potentiometer, and connect
the V- to your timing capacitor. When the capacitor reaches the voltage
set by the pot, the LED turns on. When it goes below that voltage, the
LED turns off. You also need a tiny voltage margin, so when the level
changes, the LEDs don't flicker.
For 3, you again need a way to determine if there is some voltage across
the cap, and also need what is called a 'flip-flop'. When you release
the button, it needs to turn off the filling current source until the
voltage on the capacitor gets down to the point where the first LED is lit.
This requires some simple logic gates. There are two conditions you care
about:
A) Whether the button is pressed
B) Whether there is no voltage across the timing capacitor.
Both of these conditions depend on each other; if you assert A, then B
will be turned off at some point soon (the capacitor will start to fill
up). When B is turned off, then clearing A will cause the capacitor to
start discharging until B turns back on. The logic is
Turn on charging when A and B are true.
Turn off charging when A and B are false.
You can build this simple state machine out of a single quad nand gate
and a couple of inverters. The logic is
S = A and B
R = /A and /B
.-----------------.
| |
| __ |
__ '-| \ Fill |
A--------o-------------| \ | )o---. |
| | )o----------|__/ | |
B-----o--)-------------|__/ | |
| | .------------' |
| | |\ __ | |
| '---| >O------| \ | __ |
| |/ | )o------)---| \ Drain |
| .---|__/ | | )o----------'
| |\ | '---|__/
'------| >O--'
|/
(created by AACircuit v1.28 beta 10/06/04
www.tech-chat.de)
The circuit should start out with B high and A low. Push the button, and
A will go high. When the capacitor voltage gets to a predefined voltage,
B goes low. Until that point, changing the value of A will have no effect.
Once B goes low, changing the value of A will turn off "Fill" and turn
on "Drain". Again, changing the value of A after this will have no
effect until the capacitor drains down, and once again B goes high.
For the current sources, a simple scheme is to use a dual transistor
source, such as this:
Vin ------------o-----o--.
| | |
.-. | |
R | |<---' |
Source | | |
'-' |
| |<
o------| PNP
| |\
PNP |------o
/| |
| |
Output .-.
| | 100k
| |
'-'
|
'---- ON/OFF
(created by AACircuit v1.28 beta 10/06/04
www.tech-chat.de)
The value of R determines the current, which is 0.7/R. Adjusting
resistance will change the current, which, along with the size of the
capacitor, will determine how quickly the voltage rises. This is defined
using the formula
Volts/Second = 0.7/(R*C)
If you are going between say 0.7V and 4.3V, and you have 10 LEDs that
should turn on at 0.75 second intervals, then they need to turn on every
0.3 volts, so 0.3/0.75 = 0.7/(R*C), so R*C = 0.57. Thus, with a 1uF
capacitor, you would need a 570k resistor. The drain works the same way.
The current sink is the same circuit, only the PNPs are replaced by
NPNs, and Vin is swapped with ground.
For the source, turn it on by putting the ON/OFF terminal to ground, and
turn it off by putting that terminal to Vin. Vice versa for the sink.
Each of the LEDs (and the 'empty' signal above) must detect the voltage
at the capacitor, and do something. Use a comparator like this:
VCC
+
|
o-------------------------o--------.
| | |
| | - LED
| .-. ^
| | | 10k |
| | | .-.
| '-' | | 1k
| | | |
| |\ | '-'
o-----------)-----------|-\ | |
| | >----------o--------o---o
| .---|+/ |
| | |/ | Lowest goes
.-. | | to empty
Adjust | |<-----o | signal
for each| | | ___ | "B"
LED '-' '---|___|---------'
|
| 1MEG
===
GND
(created by AACircuit v1.28 beta 10/06/04
www.tech-chat.de)
Use the LED that turns on first as the 'B' input for the flipflop
circuit above.
Note that a string of resistors from Vcc to ground might be just what
you want as references instead of the pots. That way, the resistors
would be at equal voltages.
The button is simple. Pushing it needs to bring a signal high. Thus, use
a normally open button, connected on one side to ground through a 100k
resistor, and on the other side to Vcc. Take the signal from the place
where the button connects to the 100k resistor.
That's all the pieces. See what you can do with them.
--
Regards,
Robert Monsen
"Your Highness, I have no need of this hypothesis."
- Pierre Laplace (1749-1827), to Napoleon,
on why his works on celestial mechanics make no mention of God.