Beruflich Dokumente
Kultur Dokumente
Verilog II 2
Gate-level Modeling
Predefined primitives
12 basic gates
and, nand, or, nor, xor, xnor, not,
buf others
Most are n-input, 1-output
buf and not are single-input n-output primitives
A single input can be connected to multiple lines
not( in, out1, out2, out2)
Verilog II 3
I. Gate-level Modeling
Verilog II 4
Logic Values
x (for unknown)
Verilog II 5
Table 4.9 Truth Table for Predefined Primitive Gates
Digital Design: With an Introduction to the Verilog HDL, 5e Copyright 2013 by Pearson Education, Inc.
M. Morris Mano Michael D. Ciletti All rights reserved.
Vectors
Multi-bit widths are called vectors.
output [0:3] D;
Output vector D, 4 bits wide, numbered 0 thru 3.
The first number (on the left) is the index of the most significant bit (MSB).
Verilog II 7
Example 4.1
not
G1 (Anot, A), // note syntax: list of gates
G2 (Bnot, B), // separated by ,
G3 (enableNot, enable);
nand
G4 (D[0], Anot, Bnot, enableNot ),
G5 (D[1], Anot, B, enableNot ),
G6 (D[2], A, Bnot, enableNot ),
G7 (D[3], A, B, enableNot );
endmodule
Verilog II 8
FIGURE 4.19 Two-to-four-line decoder with enable-low input
Digital Design: With an Introduction to the Verilog HDL, 5e Copyright 2013 by Pearson Education, Inc.
M. Morris Mano Michael D. Ciletti All rights reserved.
Example 4.2 Ripple-carry Adder
// Description of half adder (see Fig 4-5b)
module halfadder (S, C, x, y);
input x, y;
output S, C;
Verilog II 10
Example 4.2 Ripple-carry Adder (continued)
Verilog II 11
FIGURE 4.5 Implementation of half adder
Digital Design: With an Introduction to the Verilog HDL, 5e Copyright 2013 by Pearson Education, Inc.
M. Morris Mano Michael D. Ciletti All rights reserved.
FIGURE 4.8 Implementation of full adder with two half adders and an OR gate
Digital Design: With an Introduction to the Verilog HDL, 5e Copyright 2013 by Pearson Education, Inc.
M. Morris Mano Michael D. Ciletti All rights reserved.
FIGURE 4.9 Four-bit adder
Digital Design: With an Introduction to the Verilog HDL, 5e Copyright 2013 by Pearson Education, Inc.
M. Morris Mano Michael D. Ciletti All rights reserved.
Test Bench for Adder
module testAdder;
reg [3:0] A;
reg [3:0] B;
reg carryIn;
wire [3:0] Sum;
wire carryOut;
initial
begin
A = 4'b1001; B = 4'b1011; carryIn = 1'b0;
#10
$display( " %b", A );
$display( " %b", B );
$display( "%b %b", carryOut, Sum );
end
initial
#20 $finish;
endmodule
Verilog II 15
Test
1001
1011
1 0100
Verilog II 16
Three-state Gates
Verilog gates:
bufif1
Output is z when control is 0
Output is same as input when control is 1
bufif0
Output is z when control is 1
Output is same as input when control is 0
notif1
Output is z when control is 0
Output is inverted input when control is 1
notif0
Output is z when control is 1
Output is same as input when control is 0
Verilog II 17
FIGURE 4.32 Three-state gates
Digital Design: With an Introduction to the Verilog HDL, 5e Copyright 2013 by Pearson Education, Inc.
M. Morris Mano Michael D. Ciletti All rights reserved.
Mux implemented with 3-state Gates
bufif1(m_out, A, select );
bufif0(m_out, B, select );
endmodule
Other net types are wire, supply1, and supply0 (and others).
Verilog II 19
FIGURE 4.33 Two-to-one-line multiplexer with three-state buffers
Notetri
connection
Digital Design: With an Introduction to the Verilog HDL, 5e Copyright 2013 by Pearson Education, Inc.
M. Morris Mano Michael D. Ciletti All rights reserved.
II. Dataflow modeling
Verilog II 21
Dataflow Modeling
Verilog II 22
Operators
Digital Design: With an Introduction to the Verilog HDL, 5e Copyright 2013 by Pearson Education, Inc.
M. Morris Mano Michael D. Ciletti All rights reserved.
Dataflow description of 2-to-4 enable-low decoder
assign
D[0] = ! ( !A && !B && !enable ),
D[1] = ! ( !A && B && !enable ),
D[2] = ! ( A && !B && !enable ),
D[3] = ! ( A && B && !enable );
endmodule
Verilog II 25
Dataflow description 4-bit Adder
assign {C4, S} = A + B + C0 ;
endmodule
Verilog II 26
Conditional Operator
Verilog II 27
III. Behavioral Modeling
Verilog II 28
Behavioral Modeling
Verilog II 29
always
All of the initial blocks start up and run to the end of the block
and then stop (although there may be time delays inside) .
All of the always blocks start up looking at their control expression and are
triggered whenever it is true, then run to the end of the block,
then start waiting to be triggered again.
Verilog II 30
loop
always
begin // Always begins executing at time 0 and NEVER stops
clk = 0; // Set clk to 0
#1; // Wait for 1 time unit
clk = 1; // Set clk to 1
#1; // Wait 1 time unit
end
// Keeps executing - so continue back at the top of the begin
Verilog II 31
Mux Example
(Notetypoinbook:p.175,line8ofprogram,change5to=)
Verilog II 32
case Example
Verilog II 33
FIGURE 4.25 Four-to-one-line multiplexer
Test Benches
Verilog II 35
Test Bench
Verilog II 36
Time Delays
initial
begin
A = 0; B = 0;
#10 A = 1;
#20 A = 0; B = 1;
end
Verilog II 37
repeat
initial
begin
D = 3b000;
repeat(7)
#10 D = D + 3b001;
end
Verilog II 38
Usual Form
module testBenchName;
// declare local reg and wire identifiers
// instantiate the circuit module, binding local
// identifiers to modules identifiers
// generate a sequence of stimulus values
// using always and initial
// display the output of the module
endmodule
Test modules usually have no inputs nor outputs, but create inputs for
the circuit under test and display that circuits outputs.
Verilog II 39
FIGURE 4.34 Interaction between stimulus and design modules
Digital Design: With an Introduction to the Verilog HDL, 5e Copyright 2013 by Pearson Education, Inc.
M. Morris Mano Michael D. Ciletti All rights reserved.
System Tasks
Verilog II 41