|
Digital Logic with Transistors
It was a sunny beautiful day in Seattle. While Hurricane Irene
pounded the eastern seaboard, soaking my relatives and threatening
to wash their home away, I, callous cretin that I am, sat outside
on my porch with a notepad, a breadboard, a 9 volt battery, a
couple LEDs, a bag of 2N3904 NPN transistors, and a handful of
1K resistors and built some logic circuits just for the satisfaction
of making some LEDs blink in accordance with certain rules.
In one of their simplest configurations, an NPN transistor with its
emitter tied to ground and its collector tied to +V via a resistor
can be used as a NOT gate. When no voltage is applied to the base,
the transistor is off, and the voltage at the collector goes high
via the resistor. When a positive voltage applied to the base switches
the transistor on, current starts to flow between the emitter and the
collector and the voltage at the collector drops to about .7 volts
with the remainder being dropped across the collector resistor.
If something else, like an LED or the base of another transistor,
is connected to the collector pin, it appears to it as if the collector
just got tied to ground via a resistor.
An OR gate doesn't really even need a transistor. If you connect
two 1K resistors together in series and apply two inputs to the far
ends, the middle where the two resistors meet are the OR output.
Two grounds output a ground. Two positive voltages output a
positive voltage. If one end is grounded and the other end is
a positive voltage, the output will be a positive voltage. It'll
only be one half of the supply voltage, but if that's enough to
turn on a transistor that does something else, that's all it'll take
to use two resistors as an OR gate. It's a big deal because if you
can make a NOT gate and an OR gate, you can make anything. The
schematic for the AND gate below was initially a NAND with only
2 transistors, but then I added another NOT to light an output LED.
Note that it is made of two NOTs OR'd together with the aforementioned
resistor arrangement.
Those 1K resistors on the far left, between the input switches and the
transistor bases, are important. Just as you need a resistor in series
with an LED to keep it from smoking, you need some resistance in series
with an emitter-base or emitter-collector junction between ground and +V
to limit current and protect the junction. A silicon junction always
winds up dropping about .7 volts across it. You can think of it like a
variable resistor that adjusts itself to whatever value results in a
voltage drop of .7 volts. However, if the overall supply is at 9 volts
and there's no other resistance to drop the remaining 8.3 volts on,
then current will rise until the supply voltage drops or the junction is
destroyed.
Here's a Set/Reset Flip Flop. The idea here is that one of the two inputs
is toggled to +V and back to ground, which causes its transistor to turn
on and the other one to turn off. The transistors remain fixed in whatever
their last state was, thus remembering which input was the last one to
input +V. It's a single-bit memory. Your computer probably has more than
8 billion of them.
I didn't actually breadboard this one, so it's untested and might
have some horribly embarrassing bug. If you try it and it doesn't
work, just roll your eyes and mutter "Well, he tried his best..."
It's an XOR gate, or an Exclusive-OR, where the output is true only if
the two inputs are different from each other.
Here's what I was really after with that XOR exercise. It's a 1-of-2 multiplexer.
It has two outputs, Y0 and Y1, and you select which one of them you want to go
high with the input D. If D is low, then Y0 is selected, and if D is high, then
Y1 is selected. However, the selected Y output doesn't actually go high until
A goes high. Conceptually, the multiplexer is like one fourth of a 74LS157 chip.
When I combined this circuit with the S/R flip flop circuit, I got the D-type
transparent latch shown at the top of this page. The output tracks D while
"CLK" is high. It's very similar to one fourth of a 74LS75 chip.
The geek endorphin rush I got when it worked made this brief flicker of conscious
awareness of reality that I find myself experiencing seem pretty sweet, and
caused me to not regret having spent the afternoon building circuits and
neglecting yardwork.
It is my hope that this'll remove some transistor mystery for one or two
Arduino or Propeller or PIC or Atmel tinkerers out there. Practical logic
applications may not extend much beyond occasionally inverting a signal
when all you need is a fraction of a 74LS04 inverter, but even that has
actually been useful to me before.
|