CH4 Combinational Logic
CH4 Combinational Logic
https://youtu.be/OKtkWVhKLXg
Combinational Circuits
• Consists of input variables, logic gates, and output variables
• Outputs are determined from the present combination of inputs.
• A combinational circuit with n input can be specified with 2n entry
truth table.
• It can also be described by a number of Boolean functions equivalent
to the number of output variables.
Boolean Function
• Analysis of a combinational circuit requires that we determine the
function that the circuit implements.
• Label all gate outputs with arbitrary symbols based on inputs or other
assigned symbols. Determine their Boolean function.
• Repeat the above process until output of the circuit is obtained.
• By repeated substitution of previously defined function, obtain the output
Boolean functions in terms of input variables
Truth Table
• To obtain the truth table directly from the logic diagram w/o going
through the derivation of Boolean function:
• Determine the number of input variables
• For n inputs, list binary numbers from 0 to 2n – 1 in a table
• Label the outputs of selected gates with arbitrary symbols
• Obtain the truth table for the outputs of those gates that are a function of the
input variables only
• Proceed to obtain the truth table for the outputs of those gates that are a
function of previously defined values until the columns for all outputs are
determined
TT w/o Boolean function
Design Procedure
• From the specification of the circuit, determine the required number
of inputs and outputs and assign a symbol to each.
• Derive the truth table that defines the required relationship between
inputs and outputs.
• Obtain the simplified Boolean functions for each output as a function
of the input variables.
• Draw the logic diagram and verify the correctness of the design.
Example: BCD to Excess-3
• Inputs: A, B, C, D
• Outputs: w, x, y, z
• Truth Table
• K-map
• Boolean Functions
w = A + BC + BD = A + B(C + D)
x = B’C + B’D + BC’D’ = B’(C + D) + B(C + D)’
y = CD + C’D’ = CD + (C + D)’
z=D
TT
SH
x S x SF
HA HA CH HA
y C y z
CF
Block diagram of FA
x y Ai Bi
x
S
y FA C z FA C CIN FA COUT
z
S Si
Binary Adder (4-bit RCA)
A3 B3 A2 B2 A1 B1 A0 B0
COUT = C4 C3 C2 C1 C0 = CIN
FA FA FA FA
S3 S2 S1 S0
Ai Bi Ai Bi
Si Si
Example
4-bit Adder (CLA)
• Carry propagation path is the longest delay path in RCA.
• Carry Look Ahead (CLA) adder help solve the delay problem by
generating the carry for all 4-bits at the same time.
• CLA utilizes carry generate (Gi) and carry propagate (Pi) which are
defined as:
Pi Ai Bi Gi Ai Bi
• Sum (S) and Carry (C) for CLA can be defined using Gi and Pi as:
S i Pi Ci Ci 1 Gi Pi Ci
CLA
CLA Generator
• Boolean functions for the carry outputs of each stage:
C0 input carry
C1 G0 P0 C0
C2 G1 P1C1 G1 P1G0 P1 P0C0
C3 G2 P2C2 G2 P2 G1 P2 P1G0 P2 P1 P0C0
C3 G2 P2C2 G2 P2 G1 P2 P1G0 P2 P1 P0C0
B3 B2 B1 B0 M
● ● ● ●
A3 A2 A1 A0
COUT = C4 C3 C2 C1
● FA FA FA FA
C0
S3 S2 S1 S0
over
flow
Overflow
• An addition overflows if the signs of the addends are the same and
the sign of the sum is different from the addend’s sign.
• OR, an addition overflows if the carry in and carry out of the sign bit
are different.
• Same rule applies to subtraction.
BCD Adder
• Use 4-bit binary adder to add the digits of two BCD number.
• Result requires correction if the sum of the two digits is larger than 9
• Add six to make the sum comply with the BCD format.
• Why six ?
https://youtu.be/j6NkCO_WY98
Binary Multiplier
• Array Multiplier B1 B0
A0 A0
B1 B 0 + +
S S
A1 A 0 C C P0
B1 B0
B1A0 B0A0 A1 A1
+ +
B1A1 B0A1 S S
P1
C C
P3 P2 P1 P0
Adders
P3 P2
4-bit by 3-bit Multiplier
A0 ● ● ●
B3 B2 B1 B0
A1 ● ● ●
B3 B2 B1 B0
Addend Augend
A2 ● ● ●
B3 B2 B1 B0 4-bit adder
Addend Augend
4-bit adder
P6 P5 P4 P3 P2 P1 P0
Magnitude Comparator
• Magnitude comparator compares two numbers, A (A3A2A1A0) and B (B3B2B1B0), to
determine if A>B, A=B or A<B
• A = B if each positional bits of A and B are equal i.e. A3=B3 and A2=B2 and A1=B1
and A0=B0
xi = AiBi + Ai’Bi’ for i = 0, 1, 2, 3
• (A = B) = x3x2x1x0
• (A > B) = A3B3’ + x3A2B2’ + x3x2A1B1’ + x3x2x1A0B0’
• (A < B) = A3’B3 + x3A2’B2 + x3x2A1’B1 + x3x2x1A0’B0
https://youtu.be/1ee9VJktMq8
Comparator Circuit
A3
x3
B3
A2
B2
x2
A<B
A1
B1
x1
A>B
A0 x0
B0
A=B
Decoder
• Decoder converts binary information from n input lines to a maximum
of 2n unique output lines, each representing one of the minterms of
the n input variables.
• A decoder may operate with complemented or un-complemented
outputs.
• Decoders are usually called n-to-m line decoder where m ≤ 2n. For
example:
3-to-8 decoder, 2-to-4 decoder etc.
• Enable line(s) may be used to control outputs.
• When disabled, all outputs become high (1) or low (0)
2-to-4 decoder without enable
D0
2x4
decoder D1
D2
Fig: Block diagram
D3
X Y Outputs
0 0 D0
Fig: Logic diagram
0 1 D1
1 0 D2
1 1 D3
Fig: Truth Table https://youtu.be/84hi88pH9pY
3-to-8 Decoder without enable
3-to-8 Decoder without enable
2-to-4 Decoder
B /Y3
A
/Y2
/Y1
E
/Y0
MSB ?
A
B
/Y0 /Y4
/Y1 /Y5
/Y2 /Y6
/Y3 /Y7
Decoder Expansion
• When w=0, the top decoder is enabled and the other is disabled.
The bottom decoder outputs are all 0’s, and the top eight outputs
generate minterms 0000 to 0111.
• When w =1, the enable conditions are reversed: The bottom
decoder outputs generate minterms 1000 to 1111, while the outputs
of the top decoder are all 0’s.
Example
Implement F1, F2, F3 using a decoder with NAND gates and NAND or
AND gates connected to the decoder outputs.
F1=∑(2,4,7)
F2=∑(0,3)
F3=∑(0,2,3,4,7)
Decoder/Demultiplexer
• Demultiplexer circuit receives data from a single line and directs it to
one of 2n output lines controlled by n selection lines.
• A decoder with enable input can function as a demultiplexer.
• Enable is taken as data input line which is directed to one of 2n output lines
selected by n input variables of the decoder.
Logic by Decoders
• Implement combinational logic circuits using decoders.
• Use a 3-to-8 decoder to implement FA
• S(x, y, z) = Σ(1, 2, 4, 7)
• C(x, y, z) = Σ(3, 5, 6, 7)
Encoders
• Performs inverse operation of a decoder
• Encoder has ≤ 2n inputs and n outputs
Example: Octal-to-binary encoder:
Inputs Outputs
D0 D1 D2 D3 D4 D5 D6 D7 x y z
1 0 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0 1
0 0 1 0 0 0 0 0 0 1 0
0 0 0 1 0 0 0 0 0 1 1
0 0 0 0 1 0 0 0 1 0 0
0 0 0 0 0 1 0 0 1 0 1
0 0 0 0 0 0 1 0 1 1 0
0 0 0 0 0 0 0 1 1 1 1
Encoder Example
• Boolean Functions of octal-to-binary encoder:
z = D 1 + D3 + D5 + D7
y = D 2 + D 3 + D 6 + D7
x = D 4 + D5 + D6 + D7
• Can be implemented with 3 OR gates.
• Only one input can be active at any given time.
• If two inputs are active simultaneously, the output
produces an undefined combination
• To resolve this ambiguity, encoder circuits must
establish an input priority to ensure that only one
input is encoded.
Priority Encoder
• Priority encoder includes D0
Inputs
D1 D2 D3 x
Outputs
y V
the priority function 0 0 0 0 X X 0
• Input having the highest 1 0 0 0 0 0 1
x = D 2 + D3 y = D3 + D1 D ‘2
Priority Encoder
x = D2 + D3
y = D3 + D1 D’2
V = D0 + D1 + D2 + D3
D3 ●
D2 ● y
D1 ●
● x
D0 V
Multiplexer (MUX)
• Has many (≤ 2n) input lines, only one output line and n selection lines.
• n selection lines select 1 of the (≤ 2n) input lines to be transferred to the single
output line.
• Selection lines choose which input will go to the output line
• Also known as the data selector.
• May operate with primed or unprimed inputs/outputs.
• They are usually called m-to-1 line MUX where m ≤ 2n, n is the number of select
lines. For example:
8-to-1 multiplexer, 2-to-1 multiplexer etc.
• Enable line(s) may be used to control outputs.
• When disabled, the output becomes inactive.
2-to-1 & 4-to-1 MUX
I0
Sel f
Sel
f 0 I0
I1 1 I1
f=I0Sel’+I1Sel
I0 S1 S0 f
S1
I1
0 0 I0
S0 f
0 1 I1
I2 1 0 I2
I3
1 1 I3
4-to-1 MUX
I0
I0
I1 ● I1
f
f I2
I2
● I3
I3 S1
●
S1 ● ● S0
S0 ●
Quadruple 2-to-1 MUX
E S B3 B2 B1 B0 A3 A2 A1 A0
Y3 Y2 Y1 Y0
Logic by MUX
Combinational logic circuits using MUX
– Use a 4-to-1 MUX to implement the function:
• F(x, y, z) = Σ(1, 2, 6, 7)
x y z F
4X1 MUX
0 0 0 0
F=z y S0
0 0 1 1
x S1
0 1 0 1
F = z’
0 1 1 0
F
1 0 0 0 z I0
F=0
1 0 1 0 z’ I1
1 1 0 1 0 I2
F=1
1 1 1 1 1 I3
Boolean Function implementation using MUX
• First n - 1 variables in the table are applied to the
selection inputs of the multiplexer.
• For each combination of the selection variables, we
evaluate the output as a function of the last variable. This
function can be 0, 1, the variable, or the complement of
the variable.
• These values are then applied to the data inputs in the
proper order.
Logic by MUX
Use an 8-to-1 MUX to implement the function:
• F(A, B, C, D) = Σ(1, 3, 4, 11, 12, 13, 14, 15)
A B C D F
0 0 0 0 0
0 0 0 1 1
0 0 1 0 0
0 0 1 1 1
0 1 0 0 1
0 1 0 1 0
0 1 1 0 0
0 1 1 1 0
1 0 0 0 0
1 0 0 1 0
1 0 1 0 0
1 0 1 1 1
1 1 0 0 1
1 1 0 1 1
1 1 1 0 1
1 1 1 1 1
Three-State Gates
• A 3-state gate is a digital circuit that exhibits three states:
• Logic 0, logic 1 and high-impedance (hi-Z) states
• High-impedance state behaves like an open circuit.
• 3-state gates may perform any logic such as AND or NAND but most
common usage is buffer.
Three-State Gates
• Each 3-state gate has a control input i.e. Enable (En) signal in addition
to normal inputs/outputs.
• When En is asserted, 3-state gates acts normally i.e. output depends
on the inputs.
• When En is unasserted, output of 3-state gates become hi-Z
irrespective of the value of the inputs.
Three-State Buffers
• Output = LOW, HIGH, or Hi-Z.
• Different Flavors.
MUX using 3-State Gates
2-to-1 MUX 4-to-1 MUX
I0 ● Y I0 ● Y
I1 ●
I1
S ●
I2 ●
I3
S1 0
Select S0 2-to-4 1
decoder 2
Enable En 3
HDL
• Verilog module can be described in any of the following modeling
techniques:
• Gate level modeling using instantiation of primitive gates and user defined
modules.
• Dataflow modeling using continuous assignment statements with keyword
assign.
• Behavioral modeling using procedural assignment statements with keyword
always.
• Used to describe digital systems at a higher level of abstraction.
Gate Level Modeling
• Specifies circuit by its logic gates and their interconnections.
• Provides textual description of schematic diagram.
• Verilog recognizes 12 basic gates as predefined primitives.
and, nand, or, nor, xor, xnor, not, buf
4 are tri-state type: bufif1, bufif0, notif1, notif0
• Output is listed first, followed by inputs.
Primitive Gates
• Two more logic values other than 0 and 1
• Unknown (x)
• Unassigned or ambiguous value
• High Impedance (z)
• Unconnected wire or output of a disabled tri-state gate
0 0 0 0 0 0 0 1 x x 0 0 1 x x 0 1
1 0 1 x x 1 1 1 1 1 1 1 0 x x 1 0
x 0 x x x x x 1 x x x x x x x x x
z 0 x x x z x 1 x x z x x x x z z
Example
// gate level description of a 2-to-4 decoder
Net represents the data types of wire, wor, wand, tri, suply1 and supply0
wire takes values of 0 or 1 tri takes values of 0, 1 or z
wor is wired-OR wand is wired-AND
supply1 is power supply supply0 is ground
Verilog HDL Operators
Operator Operation Operator Operation
Symbol Symbol
Type Performed Type Performed
+ Addition >> Shift Right
– Subtraction Shift << Shift Left
Arithmetic * Multiplication {,} Concatenation
/ Division > Greater than
% Modulus < Less than
~ Complement == Equality
Logic
& AND != Inequality
(reduction) Relational
| OR Greater than
(bit-wise) >=
^ XOR or equal
! Negation Less than or
<=
Logical && AND equal
|| OR Conditional ?:
Dataflow Modeling
// description of a 2-to-4 decoder // description of a 4-bit adder
module decoder_2to4 (Yb, A, B, E); module _4bit_adder (S, C4, A, B, C0);
input A, B, E; input [3:0] A, B;
output [3:0] Yb; input C0;
assign Yb[0] = ~(~A & ~B & ~E), output [3:0] S;
Yb[1] = ~(~A & B & ~E), output C4;
Yb[2] = ~(A & ~B & ~E), assign S = A ^ B ^ C0,
Yb[3] = ~(A & B & ~E); C4 = A&B | B&C0 | C0&A;
endmodule endmodule
https://youtu.be/1ee9VJktMq8
Test Bench
• module testname.
• declare local reg and wire identifiers.
• instantiate the design module under test.
• generate stimulus using initial and always statements.
• display the output response.
• endmodule
initial initial
begin begin
A = 0; B = 0; D = 3’b000;
#10 A = 1; repeat (7)
#20 A = 0; B = 1; #10 D = D + 3’b001;
end end
Test Bench System Tasks
• Built in system functions begin with the symbol $
• System tasks useful for display are:
$display
• display values of variables or strings and goes to next line
$write
• Same as $display w/o going to next line
$monitor
• Display variables whenever a value changes
$time
• Displays simulation time
$finish
• Terminates the simulation
Test Bench
// stimulus for mux_2to1
module testmux;
reg TA, TB, TS; // inputs for mux
wire Y; // output from mux Simulation log
// instantiate mux
mux_2to1 mx (TA, TB, TS, Y); select = 1 A = 0 B = 1 Y = 0 time = 0
initial select = 1 A = 1 B = 0 Y = 1 time = 10
begin select = 0 A = 1 B = 0 Y = 0 time = 20
TS = 1; TA = 0; TB = 1; select = 0 A = 0 B = 1 Y = 1 time = 30
#10 TA = 1; TB = 0;
#10 TS = 0;
#10 TA = 0; TB = 1;
end
initial
$monitor(“select = %b A = %b B = %b Y = %b time = %0d”,
TS, TA, TB, Y, $time);
endmodule
Test Bench
Assuming design module for circuit of Fig 4-2 is defined as:
module analysis (F1, F2, A, B, C);