Module 2
Module 2
Module_Name
Parameters
(Optional)
● Port list and port declarations are present only if the module has any ports to
interact with the external environment.
output Q, Qbar;
input Sbar, Rbar;
Component II
Behaviour model
Instantiate Lower
Data Flow model always or initial
modules
block
○ Variable declarations
Instantiate
Data Flow Behaviour
○ Dataflow statements (assign) Lower
modules
model model
Rbar Qbar
Sbar
Q
Example - SR latch
Case-2: Sbar=0, Rbar=1 (S=1, R=0) –
● As Sbar=0, the output of 1st NAND gate,
Q = 1(SET state). In 2nd NAND gate, as
Q and Rbar inputs are 1, Qbar=0. Rbar Qbar
Sbar Nextstate
state: 1: 1
Next
00 Q
● As Sbar=0, the output of 1st NAND 1
gate, Q = 1. In 2nd NAND gate, as Q
and Rbar inputs are 1, Qbar=0
1 1 1
Rbar Qbar
Next state : 0
Next state : 0
1
Example - SR latch Sbar
Q
Case-3: Sbar= 1, Rbar= 0 (S=0, R=1) –
● As Rbar=0, the output of 2nd NAND gate,
Qbar= 1. In 1st NAND gate, as Qbar and 1 0
Sbar inputs are 1, Q=0(RESET state). 0
Rbar Qbar
Next state : 1
Qbar
Rbar Qbar
Components of SR Latch
module SR_latch(Q, Qbar, Sbar, Rbar);
output Q, Qbar;
input Sbar, Rbar;
nand n1(Q, Sbar, Qbar);
nand n2(Qbar, Rbar, Q);
endmodule
Verilog SR Latch
module SR_latch(Q, Qbar, Sbar, Rbar);
output Q, Qbar;
input Sbar, Rbar;
nand n1(Q, Sbar, Qbar);
Module name and port nand n2(Qbar, Rbar, Q);
list of
SR_latch module endmodule
Verilog SR Latch
module SR_latch(Q, Qbar, Sbar, Rbar);
output Q, Qbar;
input Sbar, Rbar;
nand n1(Q, Sbar, Qbar);
nand n2(Qbar, Rbar, Q);
Port
endmodule
declarations
Verilog SR Latch
Wires are connected in a
module SR_latch(Q, Qbar, Sbar, Rbar);
cross-coupled fashion.
output Q, Qbar;
input Sbar, Rbar;
nand n1(Q, Sbar, Qbar);
nand n2(Qbar, Rbar, Q);
Instan
tiate endmodule
lower
-leve
modu l
les
SR Latch stimulus module
module Top;
wire q, qbar;
reg set, reset;
SR_latch m1(q, qbar, ~set, ~reset);
initial
begin
$monitor($time, " set = %b, reset= %b, q= %b\n",set,reset,q);
set = 0; reset = 0;
#5 reset = 1;
#5 reset = 0;
#5 set = 1;
end
endmodule
SR Latch stimulus module
module Top;
wire q, qbar;
reg set, reset;
SR_latch m1(q, qbar, ~set, ~reset);
initial
begin
Declarations $monitor($time, " set = %b,
Of variables reset= %b, q= %b\n",set,reset,q);
set = 0; reset = 0;
#5 reset = 1;
#5 reset = 0;
#5 set = 1;
end
endmodule
SR Latch stimulus module
module Top;
wire q, qbar;
reg set, reset;
Instan initial
tiate begin
lower
-leve $monitor($time, " set = %b, reset=
modu l %b, q= %b\n",set,reset,q);
les - S
R set = 0; reset = 0;
Latch #5 reset = 1;
#5 reset = 0;
#5 set = 1;
end
endmodule
SR Latch stimulus module
module Top;
wire q, qbar;
reg set, reset;
SR_latch m1(q, qbar, ~set, ~reset);
initial
begin
$monitor($time, " set = %b, reset=
Beha %b, q= %b\n",set,reset,q);
viora
l set = 0; reset = 0;
block #5 reset = 1;
#5 reset = 0;
#5 set = 1;
end
endmodule
Ports
● A Verilog HDL module consist of two major parts:
○ The interface
○ The internal (body)
● Ports provide interface to communicate with external environment.
● The internals of the module are not visible to the environment.
● The environment can interact with the module only through its ports.
● Ports are also referred to as terminals.
List of Ports
● “No” port declaration is required if do
not need to communicate with other
module, such as Top module
■ Output Port
❑ Internal view-declared as a reg or
wire
❑ External view-only be connected to a
wire
Port Connection Rules
■ Inout Port
❑ Viewed as a wire/net regardless of
internal or external module
Port Connection Rules
❏ Width matching: Mismatch of internal and external port
connections
❏ Simulation will issue a warning for this condition
● The signals to be connected must have the same order as in the port list.