6 ChapterSix (1)

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

CHAPTER 6

ENCODER, DECODER
& CODE CONVERSION

Objectives

ƒ Encoder and decoder

ƒ Priority Encoder

ƒ Display decoder

ƒ Application of decoder
88

6.1 Code Converter

Code converter circuit is a general category of circuits used to perform the


operation of converting from one code to another. Code conversion is
performed by encoder, decoder and code converter circuits. For example,
code conversion takes place each time a key is pressed on a computer
keyboard, telephone pad, a microwave oven keypad or any similar device
where input values are entered into a system for processing. Code
conversion is required to operate the electronic displays that show
numbers or letters on calculators and clocks.

Consider the block diagram of a simple calculator. The input device is a


keyboard where you enter numbers. Between the keyboard and the CPU
is an encoder. The encoder translates the decimal number pressed on the
keyboard into a binary code such as BCD code. The CPU performs its
operation in binary and puts out a binary code. The decoder translates
the binary code from the CPU to a seven-segment display.

789
456
123 Enkoder Pemproses Dekoder
0

6.2 Encoder

Encoders are used extensively in keyboard applications where activation


of a single key must produce a unique binary code to represent its value.
Encoders have several inputs, but it converts only one input at a time into
a binary code. Encoders are usually specified by the number of inputs to
outputs such as 4:2, 8:3 ,10:4 or 16:4 encoders.

The job of the encoder in the calculator is to translate a 0


decimal input to a BCD number. A block diagram for a 1
2
decimal-to-BCD or 10:4 encoder is shown below. The encoder 3 A
MSB
has 10 inputs on the left and 4 outputs on the right. The 4 B
5 C
6 D LSB
7
8
9
89

encoder may have one active input and produces a unique output.

The diagram show below is a truth table for a 10:4 encoder, with active-
high inputs. The inputs are normally low. If a decimal input 4 is activated
(active high), the output is 0100.

Input Output
0 1 2 3 4 5 6 7 8 9 A B C D
1 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0 0 0 0 1
0 0 1 0 0 0 0 0 0 0 0 0 1 0
0 0 0 1 0 0 0 0 0 0 0 0 1 1
0 0 0 0 1 0 0 0 0 0 0 1 0 0
0 0 0 0 0 1 0 0 0 0 0 1 0 1
0 0 0 0 0 0 1 0 0 0 0 1 1 0
0 0 0 0 0 0 0 1 0 0 0 1 1 1
0 0 0 0 0 0 0 0 1 0 1 0 0 0
0 0 0 0 0 0 0 0 0 1 1 0 0 1

We can write the output expressions and obtained the logic circuit as
shown below.

A =8+9 1 2 3 4 5 6 7 8 9

B = 4+5+6+7
A
C = 2+3+ 6+ 7
D = 1+ 3 + 5 + 7 + 9
B

D
90

Example 1:

Design a 4:2 encoder, where only one input is active at any one time.

0 Input Output
1 A 0 1 2 3 A B
2 B
3 1 0 0 0 0 0
0 1 0 0 0 1
0 0 1 0 1 0
0 0 0 1 1 1

The 4:2 encoder truth table can be written in full as follows. We may
consider an output X, for inputs other than 0000, 0100, 0010 and 0001.

Input Output
0 1 2 3 A B
0 0 0 0 0 0
0 0 0 1 1 1
0 0 1 0 1 0
0 0 1 1 X X
0 1 0 0 0 1
0 1 0 1 X X
0 1 1 0 X X
0 1 1 1 X X
1 0 0 0 0 0
1 0 0 1 X X
1 0 1 0 X X
1 0 1 1 X X
1 1 0 0 X X
1 1 0 1 X X
1 1 1 0 X X
1 1 1 1 X X

The output expressions are


1 2 3

A = 2+3
A
B = 1+ 3
B
91

6.3 Priority Encoder

The simple 10:4 encoder in 6.2 identifies a drawback when more than one
input is activated. If the input 3 and 5 are activated simultaneously, the
output is 0111 (7), which is not a correct.

A modified version of this circuit, called priority encoder, includes the


necessary logic to ensure that when 2 or more inputs are activated, the
output code will correspond to the highest numbered input. For example,
when both 3 and 5 are activated, the output code will be 0101 (5).
Similarly if 3, 4, 5 and 8 are activated, the output code will be 1000 (8).

The 10:4 priority encoder with active-high inputs is shown below.

Input Output
0 1 2 3 4 5 6 7 8 9 A B C D
X 0 0 0 0 0 0 0 0 0 0 0 0 0
X 1 0 0 0 0 0 0 0 0 0 0 0 1
X X 1 0 0 0 0 0 0 0 0 0 1 0
X X X 1 0 0 0 0 0 0 0 0 1 1
X X X X 1 0 0 0 0 0 0 1 0 0
X X X X X 1 0 0 0 0 0 1 0 1
X X X X X X 1 0 0 0 0 1 1 0
X X X X X X X 1 0 0 0 1 1 1
X X X X X X X X 1 0 1 0 0 0
X X X X X X X X X 1 1 0 0 1
92

As an example, suppose if any of the input 0, 1 or 2 is activated, the


output is 2. This is shown on the truth table as:
0 1 2 3 4 5 6 7 8 9 A B C D
X X 1 0 0 0 0 0 0 0 0 0 1 0

that represent

0 1 2 3 4 5 6 7 8 9 A B C D
0 0 1 0 0 0 0 0 0 0 0 0 1 0
0 1 1 0 0 0 0 0 0 0 0 0 1 0
1 0 1 0 0 0 0 0 0 0 0 0 1 0
1 1 1 0 0 0 0 0 0 0 0 0 1 0

The output expressions for 10:4 priority encoder can be written as:

A = 8.9 + 9
B = 4.5.6.7.8.9 + 5.6.7.8.9 + 6.7.8.9 + 7.8.9
C = 2.3.4.5.6.7.8.9 + 3.4.5.6.7.8.9 + 6.7.8.9 + 7.8.9
D = 1.2.3.4.5.6.7.8.9 + 3.4.5.6.7.8.9 + 5.6.7.8.9 + 7.8.9 + 9

This can be further simplified as:

A =8+9
B = 4.8.9 + 5.8.9 + 6.8.9 + 7.8.9
C = 2.4.5.8.9 + 3.4.5.8.9 + 6.8.9 + 7.8.9
D = 1.2.4.6.8 + 3.4.6.8. + 5.6.8 + 7.8 + 9
93

Example 2:

Design a 4:2 priority encoder.

Input Output
0
1 A 0 1 2 3 A B
2 B
X 0 0 0 0 0
3
X 1 0 0 0 1
X X 1 0 1 0
X X X 1 1 1

From the truth table, the expressions can be written as


A = 2.3 + 3
B = 1.2.3 + 3

This can be simplified using Boolean algebra

A = 2.3 + 3
= (2 + 3)(3 + 3)
= 2+3

B = 1.2.3 + 3
= (1.2 + 3)(3 + 3)
= 1.2 + 3
94

The 4:2 priority encoder truth table can be written in full as follows.

Input Output
0 1 2 3 A B
0 0 0 0 0 0
0 0 0 1 1 1
0 0 1 0 1 0
0 0 1 1 1 1
0 1 0 0 0 1
0 1 0 1 1 1
0 1 1 0 1 0
0 1 1 1 1 1
1 0 0 0 0 0
1 0 0 1 1 1
1 0 1 0 1 0
1 0 1 1 1 1
1 1 0 0 0 1
1 1 0 1 1 1
1 1 1 0 1 0
1 1 1 1 1 1

The expressions can also be simplified using Karnaugh Map as:

A = 2+3
B = 1.2 + 3

The 74147 and 74148 are two common IC encoders. The 74147 is a 10:4
priority encoder that performs the code conversion from decimal to BCD.
The 74147 has active-low inputs and active-low outputs. Although the
74147 is classified as 10:4 encoder, the IC itself has only 9 inputs for
values 1 to 9. The 0 input is assumed when no other keys are pressed.

The 74148 is an 8:3 priority encoder for performing the code conversion
from octal to binary. It has 8 input for values 0-7 and 3 outputs A0,A1
and A2. Both the inputs and outputs are active-low.

74147 74148
I9 EI GS
I8
I7 A3 I7
I6 A2 I6 A2
I5 A1 I5 A1
I4 A0 I4 A0
I3 I3
I2 I2
I1 I1
I0 EO
95

6.4 Decoder

A decoder may be thought of as the opposite of an encoder. To reverse the


process in section 6.2 would produce a decoder that translate from the
BCD code to decimals. The BCD codes form the input and the 10 output
lines. Only one output line will be activated at any one time. A BCD 0011
input would activate the output 3. We can write the output expressions
and as shown below.
Input Output
A B C B 0 1 2 3 4 5 6 7 8 9
0

1 0 0 0 0 1 0 0 0 0 0 0 0 0 0
2
A

B 4:10
3

4
0 0 0 1 0 1 0 0 0 0 0 0 0 0
0 0 1 0 0 0 1 0 0 0 0 0 0 0
C Decoder 5

D 6

7
8

9
0 0 1 1 0 0 0 1 0 0 0 0 0 0
0 1 0 0 0 0 0 0 1 0 0 0 0 0
0 1 0 1 0 0 0 0 0 1 0 0 0 0
0 1 1 0 0 0 0 0 0 0 1 0 0 0
0 1 1 1 0 0 0 0 0 0 0 1 0 0
A B C D
1 0 0 0 0 0 0 0 0 0 0 0 1 0
A' 0 1 0 0 1 0 0 0 0 0 0 0 0 0 1
B'

C' 1

D'
2

0 = A.B.C.D
3
1 = A.B.C.D
4 2 = A.B.C.D
3 = A.B.C.D
5 4 = A.B.C.D
5 = A.B.C.D
6
6 = A.B.C.D
7 = A.B.C.D
7
8 = A.B.C.D
8 9 = A.B.C.D

9
96

Example 1:

Design a 2:4 decoder.

A 2:4 decoder has 2 inputs and 4 outputs.

0
A 1 Input Output
B 2 A B 0 1 2 3
3
0 0 1 0 0 0
0 1 0 1 0 0
1 0 0 0 1 0
1 1 0 0 0 1

The output expressions and the logic circuit is shown below.


0 = A.B A B
A'
1 = A.B 0

2 = A.B B'
1
3 = A.B

The 7442 is a BCD-to-decimal decoder. The small bubbles attached to


logic symbol indicate that the outputs are active low. They normally float
High except when activated. A BCD 0011 will activate the decimal output
3 to Low state. The inverter complements this output to a High state.
97

74LS42
9
8
7
6
5
4
A3 3
A2 2
A1 1
A B C D A0 0
0V 0V 5V 5V

0 1 2 3 4 5 6 7 8 9

6.5 Decoder Applications

We can construct a Boolean expression using a decoder and logic gates. A


two variable Boolean expression for Y = A.B + A.B + A.B can be constructed
using a 2:4 decoder and an OR gate.

Y = A.B + A.B + A.B


A.B
0
A 1 A.B
Y
= ∑ (3,2,0) B 2 A.B

3 A.B

A three variable Boolean expression can be constructed using a 3:8


decoder and an OR gate.

Y = A.B + A.B.C + A.B.C 0


1
= A.B(C + C) + A.B.C + A.B.C A 2
B 3
= A.B.C + A.B.C + A.B.C + A.B.C C 4 Y
5
∑ (4,5,6,7) 6
7
98

6.6 Display Decoder

A common output device used to display decimal numbers is the seven-


segment display. The seven-segments are labelled with standard letters
from a to g. For instance, if the segment a, b, c, d and g lights on, a
decimal 3 appears.

Input Output
A B C D a b c d e f g
0 0 0 0 1 1 1 1 1 1 0
0 0 0 1 0 1 1 0 0 0 0
0 0 1 0 1 1 0 1 1 0 1
0 0 1 1 1 1 1 1 0 0 1
0 1 0 0 0 1 1 0 0 1 1
0 1 0 1 1 0 1 1 0 1 1
0 1 1 0 1 0 1 1 1 1 1
0 1 1 1 1 1 1 0 0 0 0
1 0 0 0 1 1 1 1 1 1 1
1 0 0 1 1 1 1 1 0 1 1

Each segment contains a light emitting diode (LED). The LEDs can be
connected either common-cathode or common-anode. In the common-
cathode display, all the cathodes of the LEDs are connected together. The
cathodes are then connected to 0 volt or ground.
99

Common seven-segment display decoders are 7446, 7447, 7448 and


7449. The 7448 circuit is designed to drive the common-cathode display.
Suppose the inputs to the decoder are 0011, this will activate the segment
a, b, c, d and g to display the number 3.
100

Exercises

1. The diagram show below is a 4:2 encoder.

Input Output
0 1 2 3 A B
0
1 A 1 0 0 0 0 0
2 B
3 0 1 0 0 0 1
0 0 1 0 1 0
0 0 0 1 1 1

Prove that output expressions are:


1 2 3
A=2+3
B=1+3
A

The truth table in full can be written as:

Input Output
0 1 2 3 A B
0 0 0 0 0 0
0 0 0 1 1 1
0 0 1 0 1 0
0 0 1 1 X X
0 1 0 0 0 1
0 1 0 1 X X
0 1 1 0 X X
0 1 1 1 X X
1 0 0 0 0 0
1 0 0 1 X X
1 0 1 0 X X
1 0 1 1 X X
1 1 0 0 X X
1 1 0 1 X X
1 1 1 0 X X
1 1 1 1 X X
101

2. a. Derive the 8:3 encoder (Octal-to-binary encoder).


b. Write the output expressions.
0
1
2 A
3 B
4 C
5
6
7

3. The diagram shown below is a 4:2 priority encoder.

0 Input Output
1 A
2 B
0 1 2 3 A B
3 X 0 0 0 0 0
X 1 0 0 0 1
X X 1 0 1 0
X X X 1 1 1

Prove that the output expressions are:


A= 2+3
B = 1.2 + 3 .

The truth table can be written in full as:

Input Output
0 1 2 3 A B
0 0 0 0 0 0
0 0 0 1 1 1
0 0 1 0 1 0
0 0 1 1 1 1
0 1 0 0 0 1
0 1 0 1 1 1
0 1 1 0 1 0
0 1 1 1 1 1
1 0 0 0 0 0
1 0 0 1 1 1
1 0 1 0 1 0
1 0 1 1 1 1
1 1 0 0 0 1
1 1 0 1 1 1
1 1 1 0 1 0
1 1 1 1 1 1
102

4. The expressions for a 4:2 priority encoder are:


A = 2.3 + 3
B = 1.2.3 + 3

Simplify the expression using Boolean algebra.


A = 2+3
B = 1.2. + 3

5. a. Derive the 3:8 decoder truth table.


b. Derive the output expression.

0
1
A 2
B 3
C 4
5
6
7

6. Draw the following expressions using a decoder and an OR gate.

a. Y = A.B + B( A + C)
b. Y = A.B.C.D + A.B.C.D + A.B.C.D + A.D

You might also like