How does logic work? Decoders and Demultiplexers

teardownit 🛠️ 🔬 ✍️
6 min readSep 10, 2024

--

Greetings to all the fans of microcontrollers and digital chips! Today, we will get acquainted with decoders and demultiplexers that allow one to expand microcontroller ports, transfer a lot of data over a few wires, create stunning lighting effects, and much more.

In the post about the CD4017 decimal counter-decoder, we’ve put together the running fire effect. The chip counted from zero to nine and lit the corresponding LED, which created a nice, dynamic image.

The picture becomes even better, more dynamic, and more varied if you take two CD4017s: one lighting the LEDs horizontally and the other vertically.

Today’s scheme of ring running lights is different from the previous one, firstly, as the CD4017 is clocked not by the NE555 timer but by a symmetrical transistor multivibrator.

The multivibrator consists of two stages with a common emitter on transistors Q1 and Q2. These two stages are exactly the same, making the multivibrator symmetrical.

The input of each stage is connected to the output of the other through an electrolytic capacitor.

A capacitor stores electrical charge. The voltage between the plates of a capacitor is proportional to the charge (in coulombs) it has accumulated.

The larger the capacity, the more charge the capacitor needs to accumulate for the voltage across it to increase by one volt. For example, 1 microfarad means that charging a capacitor at 1 volt requires 1 microcoulomb of electricity.

Resistors limit the current. The current through a resistor equals the voltage divided by the resistance. For example, at a voltage of 1 volt, a current of 1 milliamp flows through a resistor with a resistance of 1 kilohm.

Current refers to the amount of electricity passing through a conductor, resistor, or anything else per unit of time. One milliamp is equal to one millicoulomb per second.

So, a capacitor with a capacity of 1 microfarad will charge or discharge 1 volt with a current of 1 milliamp in one millisecond. And a current of 1 milliamp will flow through a resistor with a resistance of 1 kilohm if the voltage across the resistor is 1 volt.

You can see where I’m going with this: capacitors and resistors can set the time and, accordingly, the frequency of oscillations if we have a threshold element that switches at a certain voltage value.

In our multivibrator, the role of these elements is played by transistors. For the bipolar transistor to open, current must flow through the base. And for current to flow, the voltage between the base and emitter must reach the direct drop level at the p-n junction.

Now, let’s see how we have the LEDs hooked up. Each of the ten channels is designed the same way. To avoid unnecessary clutter, the diagram shows just one.

When the voltage level at the Q0 output of the CD4017 chip is high, the electrolytic capacitor C3 is quickly charged through the diode D1 to a voltage just below the voltage of the power supply. Transistor Q3 opens, and LED1 and LED2 get lit.

At the start, Q3 is in saturation mode, and the current through the LEDs is determined by the resistance of resistor R6; the voltage across it is equal to the supply voltage minus the sum of the LEDs’ operating voltage and the transistor’s UCE.

When the next clock pulse arrives from the multivibrator, the logical one moves to the following output of the CD4017 microcircuit. Subsequently, a logical zero appears at its output Q0. Still, capacitor C3 can’t discharge through diode D1 because the diode does not conduct current in the opposite direction.

However, C3 is gradually discharged through resistor R7 by the base current Q3. This current is equal to the difference in voltage across C3 and Ube of transistor Q3 divided by the resistance R7.

As capacitor C3 discharges, the voltage across it decreases gradually, and the base current decreases accordingly. As soon as the product of the base current and the transistor current gain h21e becomes lower than the current through resistance R7, the collector current, also known as the LED current, will begin to decrease.

Thus, each LED flashes brightly and then dims down to zero when C3 discharges to voltage Ube and the transistor turns off.

Depending on the clock frequency, tuned by variable resistor R4, the LED will go out completely or continue to glow dimly until a complete counting cycle has passed, and the circuit that lights this LED has again reached a logical one.

In the video example, I’ve been using different color LEDs, which glowed with varying brightness levels and went out at different speeds.

The following circuit does almost the same thing but with a few quirks.

First, instead of the decimal CD4017 counter, I used binary CD4060. It is already familiar to us since I devoted a separate post.

The CD4060 has a built-in clock generator, which requires only one capacitor and two resistors to operate. Therefore, this circuit does not need a transistor multivibrator or NE555.

To get running lights, we need a decoder that, at b000 at the input, will light the zero LED, at b001 — the first, at b010 — the second, and so on, up to the seventh LED at 111.

The 74HC138 chip, a 3:8 binary decoder-demultiplexer, executes this function in our circuit.

Each of the 3-input AND gates processes possible combinations from 000 to 111. To handle logic zeros, inputs have inverters.

The outputs of the microcircuit are also connected through inverters. So, unlike the CD4017, where a logic one moves between ten outputs, the 74HC138 will have a low level at the output, corresponding to the input value, and the other seven outputs will be high.

Or all eight outputs could be high if the decoder is disabled. For the decoder to work, inputs ¬G0 and ¬G1 must have logic zeros, and G2 must have one.

From the counter outputs Q7, Q8, and Q9, numbers from b000 to b111 are supplied to the decoder data inputs A0, A1, and A2. And the signal from Q10 is supplied to the control input E3.

It turns out that the LED lighting cycles will alternate with empty cycles when pulses are not supplied to the LED control units, and the brightness gradually decreases.

Please note that here, we have the chip facing the diode’s cathode and not the anode. Transistors use PNP structures, which are opened with a negative signal, rather than NPN, which is opened with a positive one.

The electrolytic capacitor here is charged by the base current of the transistor and discharged through the diode and the chip’s output. As you can see, this upside-down scheme also works.

The program memory controller in our homemade processor unit was the 4:16 74HC154 decoder-demultiplexer. It differs from the 74HC138 in one additional input bit. This doubles the number of outputs!

Multiplexers can be cascaded. Two 74HC154s will make a 5:32 decoder. This would take four 74HC138 chips to perform the same function.

The three least significant bits, N0, N1, and N2, are equally supplied to the inputs of both decoders. And the most significant bit turns off the first decoder and turns on the second.

This means that values from b0000 to b0111 are handled by eight corresponding outputs of the first chip, and from b1000 to b1111, the second one comes in with its eight lines.

Those simple means help us perform different tasks provided by trusty logic chips.

--

--