Verilog Chapter 4
Verilog Chapter 4
The SR latch has S and R as the input ports and Q and Qbar as the output ports.
S-R latch Module
// Module name and port list
// SR_latch module
module SR_latch(Q, Qbar, Sbar, Rbar);
//Port declarations
output Q, Qbar;
input Sbar, Rbar;
// Instantiate lower-level modules
// In this case, instantiate Verilog primitive nand gates
// Note, how the wires are connected in a cross-coupled fashion.
nand n1(Q, Sbar, Qbar);
nand n2(Qbar, Rbar, Q);
// endmodule statement
endmodule
.
• Primitive instances
Verilog has several built-in primitives that model gates and switches.
The built-in primitives can be instanced in modules to create a structural description of the
module’.
Thus, module fulladd4 performs an addition for its environment. The module Top is
a top-level module in the simulation and does not need to pass signals to or receive
signals from the environment.
Thus, it does not have a list of ports. The module names and port lists for both
module declarations in Verilog are as shown below.
Notice that the external signals SUM, C_OUT, A, B, and C_IN appear in exactly the
Contd..
Connecting ports by name
For large designs where modules have, say, 50 ports, remembering the order of the
ports in the module definition is impractical and error-prone.
Verilog provides the capability to connect external signals to ports by the port
names, rather than by position.
We could connect the ports by name for full adder example by instantiating the
module fulladd4, as follows.
Contd..
Connecting ports by name
Note that only those ports that are to be connected to external signals must be
specified in port connection by name.
Unconnected ports can be dropped. For example, if the port c_out were to be kept
unconnected, the instantiation of fulladd4 would look as follows. The port c_out is
simply dropped from the port list.
Another advantage of connecting ports by name is that as long as the port name is
not changed, the order of ports in the port list of a module can be rearranged without
changing the port connections in module instantiations.
HIERARCHICAL NAMES
Verilog supports a hierarchical design methodology. Every module instance, signal,
or variable is defined with an identifier.
A particular identifier has a unique place in the design hierarchy. Hierarchical name
referencing allows us to denote every identifier in the design hierarchy with a
unique name.
A hierarchical name is a list of identifiers separated by dots (".") for each level of
hierarchy. Thus, any identifier can be addressed from any place in the design by
simply specifying the complete hierarchical name of that identifier.
The top-level module is called the root module because it is not instantiated
anywhere. It is the starting point. To assign a unique name to an identifier, start from
the top-level module and trace the path along the design hierarchy to the desired
identifier.
Contd…
To clarify this process, the design hierarchy for simulation of SR latch is shown.
Contd…
For this simulation, stimulus is the top-level module. Since the top-level module is
not instantiated anywhere, it is called the root module.
The identifiers defined in this module are q, qbar, set, and reset. The root module
instantiates m1, which is a module of type SR_latch. The module m1 instantiates
nand gates n1 and n2.
Q, Qbar, S, and R are port signals in instance m1. Hierarchical name referencing
assigns a unique name to each identifier. To assign hierarchical names, use the
module name for root module and instance names for all module instances below
the root module.
Contd…
Given example shows hierarchical names for all identifiers in the above simulation.
Notice that there is a dot (.) for each level of hierarchy from the root module to the
desired identifier.
Each identifier in the design is uniquely specified by its hierarchical path name. To
display the level of hierarchy, use the special character %m in the $display task.