18EC56 Verilog HDL Module 2 2020
18EC56 Verilog HDL Module 2 2020
Module 2
Basic Concepts,
Modules and Ports
Dinesh M.A.
[email protected]
•
/dinesh.ajay
/prof.dineshma
VISION OF THE DEPARTMENT
• Define the logic value set and data types such as nets, registers, vectors,
numbers, simulation time, arrays, parameters, memories, and strings.
• Identify useful system tasks for displaying and monitoring information, and
for stopping and finishing the simulation.
• Value Set: Verilog supports four values levels and eight strengths to
model the functionality of real hardware
• In addition to logic values, strength levels are often used to resolve
conflicts between drivers of different strengths in digital circuits.
• If two signals of unequal strengths are driven on a wire, the stronger
signal prevails. For example, if two signals of strength strong1 and
weak0 contend, the result is resolved as a strong1.
• If two signals of equal strengths are driven on a wire, the result is
unknown. If two signals of strength strong1 and strong0 conflict, the
result is an x.
• Strength levels are particularly useful for accurate modeling of signal
contention, MOS devices, dynamic MOS, and other low-level devices.
Verilog HDL 03/06/2023 22
Data Types
• Registers can also be declared as signed variables. Such registers can be used for
signed arithmetic.
reg signed [63:0] m; // 64 bit signed value
integer i; // 32 bit signed value
• System Tasks
• Verilog provides standard system tasks for certain routine
operations.
• All system tasks appear in the form $<keyword>.
• Operations such as displaying on the screen, monitoring values
of nets, stopping, and finishing are done by system tasks.
• `define
• The `define directive is used to define text macros in Verilog.
• The Verilog compiler substitutes the text of the macro wherever it encounters a
`<macro_name>.
• This is similar to the #define construct in C.
• The defined constants or text macros are used in the Verilog code by preceding them
with a ` (back tick).
• `include
• The `include directive allows you to include entire contents of a Verilog source file in
another Verilog file during compilation.
• This works similarly to the #include in the C programming language.
• This directive is typically used to include header files, which typically contain global or
commonly used definitions.
• Various data types are available in Verilog. There are four logic values, each with
different strength levels. Available data types include nets, registers, vectors, numbers,
simulation time, arrays, memories, parameters, and strings. Data types represent
actual hardware elements very closely.
• Compiler directive `define is used to define text macros, and `include is used to include
other Verilog files.
Verilog HDL 03/06/2023 52
Modules
module Top;
wire q, qbar;
reg set, reset;
input [3:0] a, b;
input c_in;
...
endmodule
Port Declaration (cont’d)
• General syntax
<module_name> <instance_name>(port connection list);
• Example:
// assuming module ripple_carry_counter(q, clk, reset);
ripple_carry_counter cntr1(wire_vec1, wire2, wire3);
Port Connection Rules
• Width matching
• Legal to connect items of different sizes
• A warning may be issued by Verilog simulator
• Unconnected ports
• Allowed in Verilog
• Example:
// module fulladd4(sum, c_out, a, b, c_in);
fulladd4 fa0(SUM, , A, B, C_IN); // output port c_out is unconnected
Port Connection Rules (cont’d)
• Example of illegal port connection
module Top;
// Declare connection variables
reg [3:0] A, B;
reg C_IN;
reg [3:0] SUM;
wire C_OUT;
...
endmodule // Top
Connecting Ports to External Signals
module Top;
// Declare connection variables
reg [3:0] A, B;
reg C_IN;
wire [3:0] SUM;
wire C_OUT;
module Top;
// Declare connection variables
reg [3:0] A, B;
reg C_IN;
wire [3:0] SUM;
wire C_OUT;
• Hierarchical design
• An identifier for every signal, variable, or module instance
• The same identifier can be used in different levels of the hierarchy
• Hierarchical name referencing
• Unique name to every identifier in the hierarchy
• Syntax:
<top-module-name>.<instance-name>.<identifier>
Hierarchical Names (cont’d)
Stimulus
m1
S
set q
Q
qbar
reset R Qbar
Hierarchical Names (cont’d)
module stimulus;
Stimulus
wire q, qbar;
reg set, reset;
SR_latch m1(q, qbar, ~set, ~reset);
m1
initial S
...
set q
Q
endmodule
module SR_latch(Q, Qbar, S, R);
output Q, Qbar;
input S, R; qbar
nand n1(Q, S, Qbar); reset R Qbar
nand n2(Qbar, R, Q);
endmodule
• Hierarchical names
stimulus stimulus.q
stimulus.qbar stimulus.set
stimulus.reset stimulus.m1
stimulus.m1.Q stimulus.m1.Qbar
stimulus.m1.S stimulus.m1.R
stimulus.n1 stimulus.n2
Text