Ncku 4
Ncku 4
Combinational Logic
Combinational Circuits
Logic circuits for digital systems may be combinational
or sequential.
Combinational logic circuits
consist of logic gates
outputs = present combination of inputs
Sequential logic circuits
employ storage elements & logic gates
outputs are a function of the inputs & the state of
storage elements (a function of previous inputs)
Block Diagram of Combinational Circuit
A combinational circuits
2 possible combinations of input values
n
sequential
No feedback path
a set of Boolean functions
a truth table
a possible explanation of the circuit operation
Analysis Procedure
Step 1. Make sure that the given circuit is
a combinational circuit
the circuit has logic gates
without feedback
without memory elements
Step 2. Obtain
the Boolean functions, or
the truth table (one by one)
A Straight-Forward Procedure
F2 = AB+AC+BC
T1 = A+B+C
T2 = ABC
T3 = F2'T1
F1 = T3+T2
A B C F2 F2’ T1 T2 T3 F1 F2
0 0 0 0 1 0 0 0 0 0
0 0 1 1 0
0 1 0 1 0
0 1 1 0 1
1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 1
Truth Table
w = A+BD+BC
K-map
x = B’D+B’C+BC’D
Karnaugh-map y = C’D’+CD
minimization z=D
Example: BCD Î Excess-3 (3/3)
Logic diagram (not unique implementation)
w = A+BD+BC
x = B’D+B’C+BC’D’
y = C’D’+CD
z=D
Adder
half adder
addition
↓
the most basic
full adder (FA)
arithmetic operation
↓… ↓ n
binary adder
n-bit binary adder (n FAs in
half adder cascade)
addition of 2 bits ↓
full adder subtractor (complementing
circuit)
addition of 3 bits
↓
(2 bits & a previous
adder-subtractor
carry)
Half Adder (1/2)
Half adder (sum of two input bits)
0 + 0 = 0 ; 0 + 1 = 1 ; 1 + 0 = 1 ; 1 + 1 = 10
two input variables: x, y
two output variables: C (carry), S (sum)
truth table
S = x'y+xy'=x y (XOR)
C = xy (AND)
Half Adder (2/2)
carry sum
S = x'y+xy'
C = xy
1. Specifications
2. Determine the inputs and
outputs
3. Derive the truth table
4. K-map minimization
5. Draw the logic diagram
One-bit adder
Full Adder (2/3)
S C
S = x’y’z + x’yz’
+xy’z’ + xyz
C = xy + xz + yz
Full Adder (3/3)
S = x'y'z+x'yz'+ xy'z'+xyz
C = xy + xz + yz
S = z⊕ (x⊕y)
= z'(xy'+x'y)+z(xy'+x'y)'= …
= xy'z+x'yz+ xy a half adder
another implementation
a full adder == 2 half adders + 1 OR gate
A 4-bit Binary Adder
Don’t use the truth table
C3 C2 C1 C0 with 29 entries
4-bit binary
ripple-carry adder
Why?
C4 C3 C2 C1
C1 C3
C0
C2 a full adder
a full adder
A1 S1 A3
B1 B3
C2
C1 C3
a full adder a full adder
Binary Ripple-Carry Adder
Carry propagation time
2 gate levels for each FA
2n gate levels for an n-bit binary ripple-carry
adder
low speed !
Improvements
Employ faster gates to reduce delays
Carry lookahead scheme (more cost, less delay)
Circuit complexity (cost) v.s. delay time (speed)
Reduction of Carry Propagation Delay
employ faster gates
look-ahead carry (more complex mechanism,
yet faster)
carry propagate: Pi = Ai⊕Bi
carry generate: Gi = AiBi
sum: Si = Pi⊕Ci
carry: Ci+1 = Gi+PiCi Ci+1 must wait for Ci
C1 = G0+P0C0 Î break this waiting-data dependency
= G1+P1G0+P1P0C0
all depend on C0 only
v=0
V=0 Î no overflow
A=3, B=7;
A=0011, B=0111
A-B 1 If M=0, calculate A+B (adder)
011
0011
v=0
1000
If M=1, calculate A+(-B)=A+(1’s of B+1)
01100 =A-B (subtractor)
Signed Binary Numbers
Decimal
Decimal Signed-mag.
Signed-mag. Signed-2’s
Signed-2’s C.
C. Signed-1’s
Signed-1’s C.
C.
+7
+7 0111
0111 0111
0111 0111
0111
+6
+6 0110
0110 0110
0110 0110
0110
+5
+5 0101
0101 0101
0101 0101
0101
+4
+4 0100
0100 0100
0100 0100
0100
+3
+3 0011
0011 0011
0011 0011
0011
+2
+2 0010
0010 0010
0010 0010
0010
+1
+1 0001
0001 0001
0001 0001
0001
+0
+0 0000
0000 0000
0000 0000
0000
-1
-1 1001
1001 1111
1111 1110
1110
-2
-2 1010
1010 1110
1110 1101
1101
-3
-3 1011
1011 1101
1101 1100
1100
-4
-4 1100
1100 1100
1100 1011
1011
-5
-5 1101
1101 1011
1011 1010
1010
-6
-6 1110
1110 1010
1010 1001
1001
-7
-7 1111
1111 1001
1001 1000
1000
(2’s complement)
Overflow (1/2)
The storage space is limited (ex. n-bit register)
Add two positive numbers and obtain a
negative number (overflow)
Add two negative numbers and obtain a
positive number (overflow)
V = 0, no overflow; V = 1, overflow
8-bit register (1-bit for sign and 7-bit for magnitude, +127 ~ -128 )
9 inputs
1 1 1 1
x x x x
1 1 1 1 x x x x
Z8
1 1 x x x x
Z1
C = K+Z8Z4+ Z8Z2
S8 S4 S2 S1= Z8 Z4 Z2 Z1+6
BCD Adder
C = K+Z8Z4+ Z8Z2
C
If the binary sum > 9,
BCD sum= 6+ binary sum.
if C = 1, S = Z + 0110
if C = 0, S = Z + 0000
Fig. 4.15
Two-bit by two-bit binary multiplier.
4-bit by 3-bit Binary Multiplier
B3 B2 B1 B0
A2 A1 A0
A0B3 A0B2 A0B1 A0B0
A1B3 A1B2 A1B1 A1B0
A2B3 A2B2 A2B1 A2B0
C6 C5 C4 C3 C2 C1 C0
Four-bit by three-bit
binary multiplier
Magnitude Comparator
The comparison of two n-bit numbers
outputs: A>B, A=B, A<B
Design Approaches
the truth table (2n inputs, 3 outputs)
2n inputs Æ
2n possible combinations in the
0 1
D1
x yz 00 01 11 10
0 1
… D7 8 K-maps
too cumbersome !!
Decoder with An Enable
The decoder is
enabled when E is
equal to 0
(active-low enable)
is disabled when E
is 1
Two-to-four-line decoder
0
with enable input
4x16 Decoder
3X8
w x y z D0 D1 D2 D3
0 0 0 0 1 0 0 0 ……..0
0 0 0 1
0 0 1 0
0 0 1 1
0 1 0 0
0 1 0 1
0 1 1 0
0 1 1 1
1 0 0 0
1 0 0 1
1 0 1 0
1 0 1 1
1 1 0 0
1 1 0 1 Extend to 4 inputs 16 outputs directly
1 1 1 0
1 1 1 1 D0=w’x’y’z’ D1=w’x’y’z …….
4x16 Decoder: Two 3X8 decoders
w x y z D0 D1 D2 D3
Enable when w=0
0 0 0 0 1 0 0 0 ……..0
0 0 0 1
0 0 1 0
0 0 1 1
0 1 0 0
0 1 0 1
0 1 1 0
0 1 1 1
1 0 0 0
1 0 0 1
1 0 1 0
1 0 1 1
1 1 0 0
1 1 0 1
1 1 1 0
1 1 1 1 Enable when w=1
Combination Logic Implementation
each output of a decoder= a minterm
use a decoder (“minterm generator”) and an external OR
gate to implement any Boolean function of n input variables
A full-adder
S(x,y,x)=Σ(1,2,4,7) 1,2,4,7
001, 010
100, 111, S=1
C(x,y,z)=Σ(3,5,6,7)
011, 101
3,5,6,7
110, 111, C=1
Encoders
The inverse operation of a decoder
only one input = 1 at any given time
y D2+D3+D6+D7
z D1+D3+D5+D7
Priority Encoder
resolve the ambiguity of illegal inputs (more inputs
are equal to 1)
only one of the input is encoded
line
2-to-1-line multiplexer
S Y
0 I0
1 I1
(don’t use K-map)
4-to-1-line multiplexer
Controllability
AND gate
I
Y
S
S=0, Y=0 (block input)
S=1, Y=I (pass input)
OR gate
I Y
S
S=1, Y=1 (block input)
S=0, Y=I (pass input)
Quadruple Two-to-One-Line Multiplexer
E
E S output Y
1 X all 0’s
0 0 select A
0 1 select B
A three-state buffer
S Y
0 D0
1 D1
Bus need three-state gates
IC Industry in Taiwan
邏 粒 切
Why Verilog ?
1. Choice of many design teams
2. Most of us are familiar with C- like syntax/semantics
Verilog Features
Features:
Procedural constructs for conditional, if-else, case and
looping operations
Arithmetic, logical, bit-wise, and reduction operations for
expression
Timing control
endmodule
Verilog Module (2/2)
Verilog Module: basic building block
Structural description:
1. module OR_AND_STRUCTURAL(IN,OUT);
5. endmodule
NOTE:
What is the difference between C and Verilog ?
5. always @(IN)
6. begin
7. OUT = (IN[0] | IN[1]) & (IN[2] | IN[3]);
8. end
9. endmodule
Activate OUT while any voltage transition
(0 1 or 1 0) happens at signal IN
Behavioral (RTL) Description (2/2)
Behavioral description #2
module or_and(IN, OUT);
input [3:0] IN; output OUT; reg OUT; (Note)
Truth Table always @(IN)
IN[0] IN[1] IN[2] IN[3] OUT
0 0 0 0 0 begin
0 0 0 1 0 case(IN)
0 0 1 0 0 4'b0000: OUT = 0; 4'b0001: OUT = 0;
0 0 1 1 0
0 1 0 0 0 4'b0010: OUT = 0; 4'b0011: OUT = 0;
0 1 0 1 1 4'b0100: OUT = 0; 4'b0101: OUT = 1;
0 1 1 0 1
4'b0110: OUT = 1; 4'b0111: OUT = 1;
0 1 1 1 1
1 0 0 0 0 4'b1000: OUT = 0; 4'b1001: OUT = 1;
1 0 0 1 1 4'b1010: OUT = 1; 4'b1011: OUT = 1;
1 0 1 0 1
1 0 1 1 1
4'b1100: OUT = 0; 4'b1101: OUT = 1;
1 1 0 0 0 4'b1110: OUT = 1; default: OUT = 1;
1 1 0 1 1 endcase
1 1 1 0 1 Synthesized and
1 1 1 1 1 end
optimized by tools
endmodule
Half Adder (1/5)
sum= a ⊕ b
c_out = ab
Half Adder (2/5)
Structural description
always @ (a or b)
begin
sum = a ^ b;
c_out = a & b;
end
endmodule
Half Adder (5/5)
Behavioral description #2
module Add_half(sum, c_out, a, b);
input a, b; 2'b10:begin
output sum, c_out; sum = 1; c_out = 0;
reg sum, c_out; end
always @(a or b) default:begin
begin sum = 0; c_out = 1;
case({a,b}) end
2'b00:begin endcase a\b 0 1
sum = 0;c_out = 0; end 0 0 1 sum
end endmodule 1 1 0
2'b01:begin
a\b 0 1
sum = 1; c_out = 0;
end 0 0 0 c_out
1 0 1