CH 02
CH 02
Digital Design
Chapter 2:
Combinational Logic Design
We start with the Verilog designing of combinational circuits which contains logic gates.
The three fundamental logic gates are AND gate, OR gate and NOT gate.
• Note that input ports above are separated into two declarations for clarity
• In one line u have data inputs (I3, I2, I1, I0)
• In the next line, u have control inputs (S1, S0)
• However, u can write data inputs and control inputs in a single
line.
input X, Y; input X;
output F; output F;
reg F; reg F;
endmodule endmodule
Simulator
Verilog for Digital Design
Copyright © 2007 10
Frank Vahid and Roman Lysecky vldd_ch2_And2.v
AND/OR/NOT Gates
Simulation and Testbenches — A First Look
• Instead of drawing test vectors, user can describe them with HDL
• Different values of inputs can be written in the program
endmodule
"#10" –
Tells simulator to keep present values
for 10 ns, before executing the next
statement
Idea: Create new "Testbench" module that provides test vectors to component's inputs
`timescale 1 ns/1 ns
Testbench module Testbench();
procedure
initial begin
// Test all possible input combinations
• HDL testbench Y_s <= 0; X_s <= 0;
#10 Y_s <= 0; X_s <= 1;
• Module with no ports #10 Y_s <= 1; X_s <= 0;
• Declare reg variable for each input #10 Y_s <= 1; X_s <= 1;
end
port, wire for each output port
endmodule
• Instantiate module, map variables to More information
on next slides
ports (more in next section)
• Set variable values at desired times
Note: CompToTest short for Component To Test
Verilog for Digital Design
Copyright © 2007 12
Frank Vahid and Roman Lysecky vldd_ch2_And2TB.v
AND/OR/NOT Gates
Simulation and Testbenches
1 initial begin
X_s // Test all possible input combinations
0 Y_s <= 0; X_s <= 0;
1 #10 Y_s <= 0; X_s <= 1;
Y_s #10 Y_s <= 1; X_s <= 0;
0 #10 Y_s <= 1; X_s <= 1;
end
1
F_s
endmodule
0
time
10 20 30 (ns)
Simulator
Verilog for Digital Design
Copyright © 2007 14
Frank Vahid and Roman Lysecky vldd_ch2_And2TB.v
Recap
• So far:
– Definition of a module (declaration in Verilog)
– Working/functionality of a module (behavior of the module in Verilog)
– Testing of a module by using testbench
– You have used three very simple examples of AND, OR and NOT gates.
• Next:
– Now you will use the aforementioned concepts
for combinational circuit (structure)
X
F X F
Y K
P And2_1 N1
“BeltWarn” example: Turn on
W
N2 And2_2
warning light (w=1) if car key is
S
in ignition (k=1), person is
Inv_1
seated (p=1), and seatbelt is not
fastened (s=0) BeltWarn
vldd_ch2_BeltWarnStruct.v
Verilog for Digital Design
Copyright © 2007 17
Frank Vahid and Roman Lysecky
Combinational Circuits
Module Instantiations
input K, P, S;
output W;
And2 And2_1(K, P, N1);
wire N1, N2;
Note: Ports ordered
as in original And2 And2 And2_1(K, P, N1);
module definition Inv Inv_1(S, N2);
And2 And2_2(N1, N2, W);
Connects instantiated module's
endmodule
ports to nets and variables
Inv_1 BeltWarn
`timescale 1 ns/1 ns
And2_2 endmodule
3. Create module instances
Inv_1
and connect ports S0
X_s
X CompToTest reg
reg K_s,
X_s, P_s,
Y_s; S_s;
Y_s F_s
Y (And2) F wire
wire W_s;
F_s;
BeltWarn CompToTest(K_s,
And2 CompToTest(X_s, Y_s,P_s, S_s, W_s);
F_s);
initial
initial begin
begin
Testbench K_s <= 0;all
// Test P_spossible
<= 0; S_s <= 0;
input combinations
#10
Y_s K_s <= X_s
<= 0; 0; P_s <= 1; S_s <= 0;
<= 0;
K_s #10
#10 K_s
Y_s <=
<= 1;
0; P_s
X_s <=
<= 1;
1; S_s <= 0;
procedure
K #10
#10 K_s
Y_s <=
<= 1;
1; P_s
X_s <=
<= 1;
0; S_s <= 1;
P_s CompToTest W_s end #10 Y_s <= 1; X_s <= 1;
P (BeltWarn) W end
S_s S
endmodule
endmodule
K BeltWarn
P W
Verilog for Digital Design
Copyright © 2007 S 20
Frank Vahid and Roman Lysecky
vldd_ch2_BeltWarnTB.v
Combinational Circuit Structure
Simulating the Circuit
• Next:
– Top-Down Design
• Combinational Behavior to Structure
Verilog for Digital Design
Copyright © 2007 23
Frank Vahid and Roman Lysecky
Top-Down Design – Combinational Behavior to Structure
• In the previous slides, u have seen that how to write the Verilog code if the structure (circuit) is given.
However, in some cases the structure is not known and only the behavior/functionality is given. In other
words, designer may initially know system behavior, but not the structure. For example, consider the
following behavior which has three inputs (K, P and S) and only a single output (W).
– BeltWarn: W = KPS'
• Top-down design
– Capture the behavior, and simulate
– Capture structure (circuit), simulate again
– Gets behavior right first, unfettered by complexity of creating structure
K_s
Capture P_s
Simulate S_s
behavior
W_s
Should be
K_s the same
Capture P_s
Simulate S_s
structure
W_s
input A, B, C;
output F, G;
reg F, G;
vldd_ch2_TwoOutputBeh.v
vldd_ch2_BeltWarnBehIf.v
BeltWarn
Display
WindowLock
X BeltWarn
F
Y