Module 3 (Combinational Logic Circuit) Modified
Module 3 (Combinational Logic Circuit) Modified
Kananbala Ray
KIIT, Deemed to be University
Block diagram
An Adder is a device that can add binary bits. Half adder is a type of
digital circuit that performs the operation of additions of two number.
It is mainly designed for the addition of binary number, but they can
be used in various other applications like binary code
decimal, address decoding, table index calculation, etc. There are two
types of Adder, One is Half Adder, and another one is known as
Full Adder. The detail explanation of the two types of the adder is
given below.
Half Adder
There are two inputs and two outputs in a Half Adder. Inputs are
named as A and B, and the outputs are named as Sum (S) and Carry
(C). The Sum is X-OR of the input A and B. Carry is AND of the
input A and B. With the help of half adder, one can design a circuit
that is capable of performing simple addition with the help of logic
gates.
Block diagram
Let us first take a look at the addition of single bits.
0+0=0
0+1=1
1+0=1
1 + 1 = 10
These are the least possible single bit combinations. But the result for
1 + 1 =10. This problem can be solved with the help of an EX – OR
gate. The sum results can be re-written as a 2-bit output. Thus the
above combination can be written as
0 + 0 = 00
0 + 1 = 01
1 + 0 = 01
1 + 1 = 10
Here the output “1” of “10” becomes the carry-out. SUM is the
normal output and the CARRY is the carry-out.
Inputs Outputs
A B Sum Carry
0 0 0 0
0 1 1 0
1 0 1 0
1 1 0 1
HDL implementation: Verilog code of half adder in data flow
level
Application of Half Adder
Half Adder is used in the arithmetic logic unit of the processor of the
computer system for performing arithmetic operations of input.
Besides, it is also used in calculators for the addition of number, in
address decoding in processors, calculation of table indices etc.
The reason these simple binary adders are called Half Adders is that
there is no scope for them to add the carry bit from previous bit. This
is a major limitation of half adders when used as binary adders
especially in real time scenarios which involves addition of multiple
bits. To overcome this limitation, full adders are developed.
Full Adder
The full adder is a little more difficult to implement than a half adder.
The main difference between a half adder and a full adder is that the
full adder has three inputs and two outputs. The two inputs are A and
B, and the third input is a carry input CIN. The output carry is
designated as COUT, and the normal output is designated as S(SUM).
Block diagram
Inputs Outputs
0 0 0 0 0
0 0 1 0 1
0 1 0 0 1
0 1 1 1 0
1 0 0 0 1
Inputs Outputs
1 0 1 1 0
1 1 0 1 0
1 1 1 1 1
Thus, a full adder circuit can be implemented with the help of two
half adder circuits. The first half adder circuit will be used to add A
and B to produce a partial sum. The second half adder logic can be
used to add CIN to the sum produced by the first half adder circuit.
Finally, the output S is obtained.
If any of the half adder logic produces a carry, there will be an output
carry. Thus, COUT will be an OR function of the half adder CARRY
outputs.
SUM(S) =A̅B̅CIN+A̅BC̅IN+AB̅C̅IN+ABCIN
= A̅(B̅CIN+ BC̅IN)+A(B̅C̅IN+BCIN)
= A̅(B̅CIN+ BC̅IN)+A(B̅CIN+ BC̅IN)'
= A ⊕ B ⊕ CIN
Carry(COUT) = A̅BCIN+AB̅CIN+ABC̅IN+ABCIN
=AB(C̅IN+CIN)+ CIN (A̅B+AB̅)
=AB + (A ⊕ B). CIN
= AB + ( A̅. B + A. B̅). CIN
= AB + A̅. BCIN + A. B̅. CIN
= B (A + A̅. CIN) + A. B̅. CIN
= B [(A+ A̅) (A + CIN)] + A. B̅. CIN
= AB + BCIN + A. B̅. CIN
= AB + CIN (B + A. B̅)
= AB + CIN [(B + A) (B + B̅)]
= AB + BCIN + ACIN
Full adder using logic gates
Full Adder using two half adders
Block diagram
Circuit diagram
HDL implementation: Verilog code for full adder in data flow level
module full_adder( input a,b,c, output sum,cout );
assign sum = (a ^ b ^ c );
assign cout = (a & b ) | (b & c) | (a & c); //cout=a & b | (a^b) & c;
endmodule
Hardware It consists of one EX-OR gate and It consists of two EX-OR, two AND
components one AND gate. gate and one OR gate.
The Full Adder is capable of adding only two single digit binary
number along with a carry input. But in practical we need to add
binary numbers which are much longer than just one bit. To add two
n-bit binary numbers we need to use the n-bit parallel adder. It uses a
number of full adders in cascade. The carry output of the previous full
adder is connected to carry input of the next full adder.
input [3:0]a;
input [3:0]b;
output [4:0]sum;
wire cout0,cout1,cout2;
full_adder full_adder_0(a[0],b[0],0,sum[0],cout0);
full_adder full_adder_1(a[1],b[1],cout0,sum[1],cout1);
full_adder full_adder_2(a[2],b[2],cout1,sum[2],cout2);
full_adder full_adder_3(a[3],b[3],cout2,sum[3],sum[4]);
endmodule
input a;
input b;
input cin;
output sum;
output cout;
assign sum = (a ^ b ^ cin );
assign cout = (a & b ) | (b & cin) | (a & cin); //cout=a & b | (a^b) & cin;
endmodule
Half Subtractor
A B D (Difference) b(Borrow)
0 0 0 0
0 1 1 1
1 0 1 0
1 1 0 0
Circuit Diagram
HDL implementation: Verilog code for half subtractor in data
flow level
module half_sub(d, bout, a, b);
input a,b;
output d,bout; // difference and borrow
assign d = a^b;
assign bout = (~a & b) ;
endmodule
Implementation of Half Subtractor using NAND gates :
Implementation of Half Subtractor using NOR gates :
Full Subtractor
The disadvantage of a half subtractor is overcome by full subtractor.
The full subtractor is a combinational circuit with three inputs A,B,C
and two output D and C'. A is the 'minuend', B is 'subtrahend', C is the
'borrow' produced by the previous stage, D is the difference output
and C' is the borrow output.
assign d = (a ^ b ^ bin );
assign bout = (~a & b ) | (~a & bin) | (b & bin); //bout=~a & b |
~(a^b) & bin;
endmodule
Block diagram
Code converters
BCD to seven segment decoders
Nixie tube decoders
Relay actuator
2 to 4 Line Decoder
Block diagram
HDL implementation: Verilog code for 2 to 4 line active high
decoder using data flow modeling
module decoder_2_4(a,b,w,x,y,z);
output w,x,y,z;
input a,b;
assign w = (~a) & (~b);
assign x = (~a) & b;
assign y = a & (~b);
assign z = a & b;
endmodule
Test Bench
module decoder_2_4_test;
reg a,b;
wire w,x,y,z;
decoder_2_4 decoder_2_4_test(a,b,w,x,y,z);
initial
begin
a=0; b=0;
#20 a=0; b=1;
#20 a=1; b=0;
#20 a=1; b=1;
end
endmodule
Active LOW decoder
In many applications, decoders are designed with active low output.
In such a case AND gates are replaced by NAND gates. Fig. shows
the active LOW 2 to 4 line decoder.
One of these four outputs will be ‘1’ for each combination of inputs
when enable, E is ‘1’. The Truth table of 2 to 4 decoder is shown
below
Enable Inputs Outputs
E A1 A 0 Y 3 Y 2 Y 1 Y 0
0 x x 0 0 0 0
1 0 0 0 0 0 1
1 0 1 0 0 1 0
1 1 0 0 1 0 0
1 1 1 1 0 0 0
From Truth table, we can write the Boolean functions for each output
as Y3=E.A1.A0
Y2=E.A1.A0′
Y1=E.A1′.A0
Y0=E.A1′.A0′
Each output is having one product term. So, there are four product
terms in total. We can implement these four product terms by using
four AND gates having three inputs each & two inverters. The circuit
diagram of 2 to 4 decoder is shown in the following figure.
2 to 4 line Active-low Decoder using enable i/p
Truth Table:
endmodule
3 to 8 line Decoder
A 3 to 8 decoder has three inputs (A,B,C) and eight outputs (DO
to D7).
Based on the 3 inputs one of the eight outputs is selected.
The truth table for 3 to 8 decoder is shown in table
From the truth table, it is seen that only one of eight outputs
(DO to D7) is selected based on three select inputs.
From the truth table, the logic expressions for outputs can be
written as follows:
Truth table of 3 to 8 decoder.
| Inputs | Outputs
A B C D0 D1 D2 D3 D4 D5 D6 D7
0 0 0 1 0 0 0 0 0 0 0
0 0 1 0 1 0 0 0 0 0 0
0 1 0 0 0 1 0 0 0 0 0
0 1 1 0 0 0 1 0 0 0 0
1 0 0 0 0 0 0 1 0 0 0
1 0 1 0 0 0 0 0 1 0 0
1 1 0 0 0 0 0 0 0 1 0
1 1 1 0 0 0 0 0 0 0 1
Priority encoders
Decimal to BCD encoder
Octal to binary encoder
Hexadecimal to binary encoder
4 : 2 Encoder –
A1 = Y3 + Y2
A0 = Y3 + Y1
Truth Table –
D7 D6 D5 D4 D3 D2 D1 D0 X Y Z
0 0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 1 0 0 0 1
0 0 0 0 0 1 0 0 0 1 0
0 0 0 0 1 0 0 0 0 1 1
0 0 0 1 0 0 0 0 1 0 0
0 0 1 0 0 0 0 0 1 0 1
0 1 0 0 0 0 0 0 1 1 0
1 0 0 0 0 0 0 0 1 1 1
As seen from the truth table, the output is 000 when D0 is active; 001
when D1 is active; 010 when D2 is active and so on.
Implementation –
From the truth table, the output line Z is active when the input octal
digit is 1, 3, 5 or 7. Similarly, Y is 1 when input octal digit is 2, 3, 6 or
7 and X is 1 for input octal digits 4, 5, 6 or 7. Hence, the Boolean
functions would be:
X = D4 + D5 + D6 + D7
Y = D2 +D3 + D6 + D7
Z = D1 + D3 + D5 + D7
Hence, the encoder can be realised with OR gates as follows:
Priority Encoder–
From the truth table, we see that when all inputs are 0, our V bit or the
valid bit is zero and outputs are not used. The x’s in the table show
the don’t care condition, i.e, it may either be 0 or 1. Here, D3 has
highest priority, therefore, whatever be the other inputs, when D3 is
high, output has to be 11. And D0 has the lowest priority, therefore
the output would be 00 only when D0 is high and the other input lines
are low. Similarly, D2 has higher priority over D1 and D0 but lower
than D3 therefore the output would be 10 only when D2 is high and
D3 are low (D0 & D1 are don’t care).
Truth Table –
D3 D2 D1 D0 X Y V
0 0 0 0 x x 0
0 0 0 1 0 0 1
0 0 1 x 0 1 1
0 1 x x 1 0 1
1 x x x 1 1 1
X=D3+D̅3D2=D3+D2
Y=D3+D̅3D̅2D1=D3+D̅2D1
V = D0 + D1 + D2 + D3
Implementation –
It can clearly be seen that the condition for valid bit to be 1 is that at
least any one of the inputs should be high. Hence,
X= D3+ D2
Y = D3+ D̅2 D1
Hence, the priority 4-to-2 encoder can be realized as follows:
Uses of Encoders –
Multiplexers
Block diagram
Input Output
I0 I1 S Out
0 0 0 0
0 0 1 0
0 1 0 0
0 1 1 1
1 0 0 1
1 0 1 0
1 1 0 1
1 1 1 1
HDL implementation: Verilog code for 2:1 MUX using gate-level
modeling
module mux2x1(out,I0,I1,s);
input I0,I1,s;
wire and_1,and_2,s_c;
output out;
not (s_c,s);
and (and_1,I0,s_c);
and (and_2,I1,s);
or (out,and_1,and_2);
endmodule
4x1 Multiplexer
4x1 Multiplexer has four data inputs I3, I2, I1 & I0, two selection lines
s1 & s0 and one output Y. The block diagram of 4X1 MUX is shown
below.
From Truth table, we can directly write the Boolean function for
output, Y=S1′S0′I0+S1′S0I1+S1S0′I2+S1S0I3
input i0,i1,i2,i3,s1,s0;
output out;
wire mux1,mux2;
mux2x1 mux_1(mux1,i0,i1,s0);
mux2x1 mux_2(mux2,i2,i3,s0);
mux2x1 mux_3(out,mux1,mux2,s1);
endmodule
Test Bench code for 4×1 Mux
i0 i1 i2 i3 S1 S0 out
1 0 1 1 0 1 0
0 1 0 0 0 1 1
0 0 1 0 1 0 1
0 0 0 1 1 1 1
1 0 0 0 0 0 1
timescale 1ns/1ns
module mux4x1_tb;
wire t_out;
reg t_a, t_b, t_c, t_d, t_s1, t_s0;
mux4x1 my_4x1_mux( t_a, t_b, t_c, t_d, t_s1, t_s0, t_out );
initial
begin
// 1
t_a = 1'b1;
t_b = 1'b0;
t_c = 1'b1;
t_d = 1'b1;
t_s1 = 1'b0;
t_s0 = 1'b1;
#5 //2
t_a = 1'b0;
t_b = 1'b1;
t_c = 1'b0;
t_d = 1'b0;
t_s1 = 1'b0;
t_s0 = 1'b1;
#5 //3
t_a = 1'b0;
t_b = 1'b0;
t_c = 1'b1;
t_d = 1'b0;
t_s1 = 1'b1;
t_s0 = 1'b0;
#5 //4
t_a = 1'b0;
t_b = 1'b0;
t_c = 1'b0;
t_d = 1'b1;
t_s1 = 1'b1;
t_s0 = 1'b1;
#5 //5
t_a = 1'b1;
t_b = 1'b0;
t_c = 1'b0;
t_d = 1'b0;
t_s1 = 1'b0;
t_s0 = 1'b0;
end
endmodule
Example-
The output logic equation Y of the 4×1 multiplexer shown in figure is:
Solution:
= A’C(B’+B) + AC’(B’+B)
= A’C + AC’
= A ⊕ C
Function implementation using multiplexers:
1 : 2 demultiplexer
1 : 4 demultiplexer
1 : 8 demultiplexer
1 : 16 demultiplexer
1-to-2 Demultiplexer
A 1-to-2 demultiplexer consists of one input line, two output lines and
one select line. The signal on the select line helps to switch the input
to one of the two outputs. The figure below shows the block diagram
of a 1-to-2 demultiplexer with additional enable input.
In the figure, there are only two possible ways to connect the input to
output lines, thus only one select signal is enough to do the
demultiplexing operation. When the select input is low, then the input
will be passed to Y0 and if the select input is high then the input will
be passed to Y1.
From the above truth table, the logic diagram of this demultiplexer
can be designed by using two AND gates and one NOT gate as shown
in below figure. When the select lines S=0, 1st AND gate is enabled
while 2nd AND gate is disabled.
Then, the data from the input flows to the output line Y0. Similarly,
when S=1, 2nd AND gate is enabled and 1st AND gate is disabled,
thus data is passed to the Y1 output.
1-to-4 Demultiplexer
A 1-to-4 demultiplexer has a single input (D), two selection lines (S1
and S0) and four outputs (Y0 to Y3). The input data goes to any one
of the four outputs at a given time for a particular combination of
select lines.
The truth table of this type of demultiplexer is given below. From the
truth table it is clear that, when S1=0 and S0= 0, the data input is
connected to output Y0 and when S1= 0 and s0=1, then the data input
is connected to output Y1.
Similarly, other outputs are connected to the input for other two
combinations of select lines.
Truth Table
From the table, the output logic can be expressed as min terms and are
given below.
Where D is the input data, Y0 to Y3 are output lines and S0 & S1 are
select lines.
Using the above truth table the logic diagram of the demultiplexer is
implemented using eight AND and three NOT gates. The different
combinations of the select lines select one AND gate at given time,
such that data input will be seen at a particular output.
Applications of Demultiplexer
Since the demultiplexers are used to select or enable the one signal
out of many, these are extensively used in microprocessor or
computer control systems such as
Multiplexer Demultiplexer
Multiplexer processes the Demultiplexer receives digital
digital information from information from a single source
various sources into a single and converts it into several
source. sources
It is known as Data Selector It is known as Data Distributor
Multiplexer is a digital
Demultiplexer is a digital circuit
switch
It follows combinational It also follows combinational
logic type logic type
It has n data input It has single data input
It has a single data output It has n data outputs
Multiplexer Demultiplexer
It works on many to one It works on one to many
operational principle operational principle
In time division In time division Multiplexing,
Multiplexing, multiplexer is demultiplexer is used at the
used at the transmitter end receiver end
Difference between Decoder and Demultiplexer: