An Introduction to Digital System Designce.sharif.edu/~mohajjel/DSD/s4.pdf · Components of a...

12
M.Mohajjel

Transcript of An Introduction to Digital System Designce.sharif.edu/~mohajjel/DSD/s4.pdf · Components of a...

Page 1: An Introduction to Digital System Designce.sharif.edu/~mohajjel/DSD/s4.pdf · Components of a Verilog Module (cont.) Digital System Design 4 module Top; // Declarations of wire, reg,

M.Mohajjel

Page 2: An Introduction to Digital System Designce.sharif.edu/~mohajjel/DSD/s4.pdf · Components of a Verilog Module (cont.) Digital System Design 4 module Top; // Declarations of wire, reg,

Components of a Verilog Module

Digital System Design 2

Page 3: An Introduction to Digital System Designce.sharif.edu/~mohajjel/DSD/s4.pdf · Components of a Verilog Module (cont.) Digital System Design 4 module Top; // Declarations of wire, reg,

Components of a Verilog Module (cont.)

Digital System Design 3

module SR_latch(Q, Qbar, Sbar, Rbar);

//Port declarations

output Q, Qbar;

input Sbar, Rbar;

// Instantiate lower-level modules

nand n1(Q, Sbar, Qbar);

nand n2(Qbar, Rbar, Q);

endmodule

Page 4: An Introduction to Digital System Designce.sharif.edu/~mohajjel/DSD/s4.pdf · Components of a Verilog Module (cont.) Digital System Design 4 module Top; // Declarations of wire, reg,

Components of a Verilog Module (cont.)

Digital System Design 4

module Top;

// Declarations of wire, reg, and other variables

wire q, qbar;

reg set, reset;

// Instantiate lower-level modules

SR_latch m1(q, qbar, ~set, ~reset);

// Behavioral block, initial

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

Page 5: An Introduction to Digital System Designce.sharif.edu/~mohajjel/DSD/s4.pdf · Components of a Verilog Module (cont.) Digital System Design 4 module Top; // Declarations of wire, reg,

Ports

Provide the interface by which a module can communicate with its environment

module fulladd4(sum, c_out, a, b, c_in);

module Top; // top-level module in simulation

Digital System Design 5

Page 6: An Introduction to Digital System Designce.sharif.edu/~mohajjel/DSD/s4.pdf · Components of a Verilog Module (cont.) Digital System Design 4 module Top; // Declarations of wire, reg,

Ports (cont.)

Port Declaration Input port: input

Output port: output

Bidirectional port: inout

Digital System Design 6

module fulladd4(sum, c_out, a, b, c_in);

output[3:0] sum;

output c_cout;

input [3:0] a, b;

input c_in;

.

.

endmodule

Page 7: An Introduction to Digital System Designce.sharif.edu/~mohajjel/DSD/s4.pdf · Components of a Verilog Module (cont.) Digital System Design 4 module Top; // Declarations of wire, reg,

Ports (cont.)

Port Declaration Input port: input

Output port: output

Bidirectional port: inout

Note: Ports of the type input and inout cannot be declared as reg

Digital System Design 7

module DFF(q, d, clk, reset);

output q;

reg q;

input d, clk, reset;

...

...

endmodule

Page 8: An Introduction to Digital System Designce.sharif.edu/~mohajjel/DSD/s4.pdf · Components of a Verilog Module (cont.) Digital System Design 4 module Top; // Declarations of wire, reg,

Ports (cont.)

Port Connection Rules

Digital System Design 8

Page 9: An Introduction to Digital System Designce.sharif.edu/~mohajjel/DSD/s4.pdf · Components of a Verilog Module (cont.) Digital System Design 4 module Top; // Declarations of wire, reg,

Ports (cont.)

Width matching

Unconnected ports fulladd4 fa0(SUM, , A, B, C_IN); // c_out is unconnected

Illegal Port Connection

Digital System Design 9

module Top;

reg [3:0]A,B;

reg C_IN;

reg [3:0] SUM;

wire C_OUT;

fulladd4 fa0(SUM, C_OUT, A, B, C_IN);

.

.

endmodule

wire [3:0] SUM;

Page 10: An Introduction to Digital System Designce.sharif.edu/~mohajjel/DSD/s4.pdf · Components of a Verilog Module (cont.) Digital System Design 4 module Top; // Declarations of wire, reg,

Ports (cont.)

Connecting Ports to External Signals

Connecting by ordered list fulladd4 fa_ordered(SUM, C_OUT, A, B, C_IN);

Connecting ports by name

fulladd4 fa_byname(.c_out(C_OUT), .sum(SUM), .b(B), .c_in(C_IN), .a(A));

Digital System Design 10

Page 11: An Introduction to Digital System Designce.sharif.edu/~mohajjel/DSD/s4.pdf · Components of a Verilog Module (cont.) Digital System Design 4 module Top; // Declarations of wire, reg,

Hierarchical Names

Digital System Design 11

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

Page 12: An Introduction to Digital System Designce.sharif.edu/~mohajjel/DSD/s4.pdf · Components of a Verilog Module (cont.) Digital System Design 4 module Top; // Declarations of wire, reg,

Reading assignment

Chapter 4

Digital System Design 12