Digital Logic Design · Lab 8 · read before the labAll labsGo to the lab →

Decoders: one line for every code.

A decoder reads an n bit binary code and activates exactly one of its 2ⁿ output lines. Add a gate after it and the same chip builds any logic function of its inputs.

01

What a decoder does

A decoder is a combinational circuit with n inputs and up to 2ⁿ outputs. For every input code exactly one output is active, and every other output is inactive. If the active level is 1 the outputs are called active HIGH; if it is 0, as on the 74138, they are active LOW.

3 to 8

Three input bits select one of eight lines. This is also called a binary to octal decoder.

4 to 10

A BCD decoder turns one decimal digit (0 to 9) into one of ten lines.

address

In a computer, a decoder reads the upper address bits and enables the one memory or input output chip they point to.

02

The 74138 truth table

The 74138 has three select inputs, C (pin 3, the most significant bit), B (pin 2) and A (pin 1, the least significant bit), and eight active LOW outputs Y0 to Y7. With the chip enabled, the output whose number matches the code C B A goes to 0 and the rest stay at 1. Try it below, then read the table.

Y0=1Y1=1Y2=1Y3=1Y4=1Y5=0Y6=1Y7=1

Select 5: only Y5 is LOW (its lamp is dark).

CBAY0Y1Y2Y3Y4Y5Y6Y7
00001111111
00110111111
01011011111
01111101111
10011110111
10111111011
11011111101
11111111110

The table is a diagonal of zeros: code 000 pulls Y0 LOW, code 101 pulls Y5 LOW, and so on. The pin numbers of every chip used on this page are in the viewer below.

741383-to-8 line decoder / demultiplexer1A2B3C4G2A5G2B6G17Y78GND9Y610Y511Y412Y313Y214Y115Y016VCC

Hold the chip with its notch on the left. Pin 1 is at the bottom left, the pins count up to the right, then continue along the top from right to left. Most 14 pin chips have VCC on pin 14 and GND on pin 7, but not all: check every new chip.

03

Enable inputs

The 74138 has three enable inputs: G1 (pin 6) is active HIGH, while G2A (pin 4) and G2B (pin 5) are active LOW. The decoder works only when G1 = 1 and G2A = G2B = 0. In every other case all eight outputs are 1, whatever the select inputs say.

G1G2AG2BDecoderOutputs
0XXdisabledall 1
X1Xdisabledall 1
XX1disabledall 1
100enabledselected line 0

Tie G1 to +5 V and both G2 pins to GND. Never leave them floating: an open TTL input behaves like a 1, and a 1 on G2A or G2B turns the decoder off. The enables have two more uses. Two 74138 chips with opposite enables on a fourth address bit make a 4-to-16 decoder, and a data signal on G2B turns the decoder into a demultiplexer (see the multiplexer lab).

04

Functions from minterms

A minterm is one row of a truth table. Because output Yn of an enabled 74138 goes LOW for minterm n and for nothing else, the decoder hands you every minterm of three variables on its own pin. To build a function, collect the lines of the rows where the function is 1.

Worked example, the full adder. Put A on C, B on B and Cin on A. The truth table shows which decoder line belongs to each row:

RowABCinSCoutLine
000000Y0
100110Y1
201010Y2
301101Y3
410010Y4
510101Y5
611001Y6
711111Y7
SumS = Σm(1, 2, 4, 7)rows where S = 1
CarryCout = Σm(3, 5, 6, 7)rows where Cout = 1
With OR gatesS = Y1' + Y2' + Y4' + Y7'invert each LOW line, then OR

With a 7404 and 7432 this takes one inverter per line and three 2-input OR gates per output.

05

The NAND shortcut

De MorganY1' + Y2' + Y4' + Y7' = (Y1 . Y2 . Y4 . Y7)'an OR of inverted lines equals a NAND of the lines
SumS = NAND(Y1, Y2, Y4, Y7)one gate of a 7420
CarryCout = NAND(Y3, Y5, Y6, Y7)the other gate of the same 7420

A NAND output is 1 whenever any of its inputs is 0. Since exactly one decoder line is LOW at a time, the NAND gives 1 precisely when the active line is one of the function's minterms. One 7420 therefore replaces the inverters and all six OR gates of the full adder. A function with three minterms would use a 3-input NAND (7410), and one with two minterms a 2-input NAND (7400).

06

Worked example: full subtractor

The full subtractor computes A minus B minus Bin. Its difference D is 1 when an odd number of inputs are 1, exactly like the sum of an adder. Its borrow Bo is 1 when A is smaller than B plus Bin.

RowABBinDBo
000000
100111
201011
301101
410010
510100
611000
711111
DifferenceD = Σm(1, 2, 4, 7)NAND of Y1, Y2, Y4, Y7
BorrowBo = Σm(1, 2, 3, 7)NAND of Y1, Y2, Y3, Y7
SharedD and S matchonly the second output changes

This is the design task of the bench. Try to reach these equations yourself from the truth table before you look here.

07

Common mistakes

  • All eight LEDs stay lit for every code: an enable is wrong. Check G1 on +5 V and G2A, G2B on GND.
  • The wrong LED goes dark: C and A are swapped. C is the most significant select input.
  • The function output is inverted: an AND gate was used where a NAND is needed, or an inverter is missing before the OR gates.
  • A chip does nothing: its VCC (pin 16 on the 74138, pin 14 on the gate chips) or GND (pin 8 or pin 7) is not wired.
08

Questions and answers

Q1The decoder is enabled and C B A = 110. Which output is LOW?

Y6, because 110 in binary is 6.

Q2Every LED stays on whatever the switches do. What is the likely cause?

The decoder is disabled: G1 is LOW, or G2A or G2B is HIGH or left open.

Q3Which 74138 lines feed the NAND gate for Cout of a full adder?

Y3, Y5, Y6 and Y7.

Q4Why is a NAND gate used and not an AND gate?

The lines are active LOW. A NAND of them is 1 whenever one of the chosen lines is LOW, which is the OR of those minterms.

Q5How many 74138 chips make a 4-to-16 decoder?

Two. The fourth bit enables one chip through G1 and the other through G2A, so only one chip is active at a time.

I am ready, go to the lab →