Verilog
Verilog
Verilog HDL
Edited by Chu Yu
http://ece.niu.edu.tw/~chu/
(2007/2/26)
<##>
1
Edited by Chu Yu
Verilog HDL
<##>
2
Edited by Chu Yu
Verilog HDL
Verilog HDL
<##>
3
Edited by Chu Yu
Verilog HDL
Verilog HDL
z
Edited by Chu Yu
Verilog HDL
Programming
LanguageHDL
V.S. Verilog HDL
Verilog
Programming Language
if (a>b)
compiler
{
sub a, b
assembler
(C code)
(asm code)
Computer
(CPU)
Verilog HDL
if (a>b)
begin
end
(Verilog code)
I0
I1
synthesizer
In
a
b
out
a>b
(logic circuit)
(cell library)
<##>
5
Edited by Chu Yu
Verilog HDL
Verilog HDL
z
<##>
6
Edited by Chu Yu
Verilog HDL
Et
An event Et at time t
Schedules another event
at time t + 2
t
t+1
t+2
Edited by Chu Yu
Verilog HDL
Switch Level
A model that describes the transistors and the interconnections
between them.
<##>
8
Edited by Chu Yu
Verilog HDL
Switch Level
// AND gate of u2
pmos p0(VDD, nand, A),
p1(VDD, nand, B);
nmos n0(nand, wire1, A),
n1(wire1, GND, B);
U0
U1
hs
A
B
Sum
U2
U3
1
U4
3
hc1
3
2
Co
hc0
Cin
<##>
9
Edited by Chu Yu
Verilog HDL
<##>
10
Edited by Chu Yu
Verilog HDL
Behavioral Modeling
sum = a + b;
Behavior Model
(Verilog HDL or C language)
Verification
(Verilog-XL)
always @( a or b or c)
{carry, sum} = a+b+c;
RTL Modeling
RTL Model
(Verilog HDL)
Verification
(Verilog-XL)
<##>
11
Edited by Chu Yu
Verilog HDL
Logic Synthesis
(Synopsys)
xo03d1 u0(sum,a,b,c);
an02d1 u1(g2,a,b);
Verification
(Verilog-XL)
Physical Design
(CELL3 Ensemble)
ASIC Libraries
(Compass cell library)
GDS II
<##>
12
Edited by Chu Yu
Verilog HDL
Verilog-HDL Simulators
VCS (Synopsys)
Platform
Windows NT/XP, SUN Solaris (UNIX), Linux.
Modelsim (Mentor)
Platform
Windows NT/XP, SUN Solaris (UNIX), Linux.
NC-Verilog (Cadence)
Platform
Windows NT/XP, SUN Solaris (UNIX), Linux.
Verilog-XL (Cadence)
Platform
SUN Solaris (UNIX).
Other Simulators
MAX+PLUS II, Quartus II (Altera)
Active HDL (Aldec), Silos (Silvaco),
<##>
13
Edited by Chu Yu
Verilog HDL
<##>
14
Edited by Chu Yu
Verilog HDL
Example of Adder
z
A Full Adder
module name
a
b
cin
sum
U0
a
b
U1
w0
cin
U2
w1
U4
carry
b
cin
U3
w2
endmodule
logic circuit description
instantiation
<##>
15
Edited by Chu Yu
Verilog HDL
A Full Adder
module adder (carry, sum, a, b, cin);
output carry, sum;
input a, b, cin;
reg
sum, carry;
a
b
cin
a
b
sum
U0
U1
w0
a
cin
U2
w1
U4
carry
b
cin
U3
w2
<##>
16
Edited by Chu Yu
Verilog HDL
Identifiers of Verilog
z Identifiers are user-provided name for Verilog objects
within a description.
z Legal characters in identifiers:
a-z, A-Z, 0-9, _, $
Edited by Chu Yu
Verilog HDL
Escaped Identifiers
z Escaped Identifiers start with a backslash (\) and end
with a white space.
z They can contain any printable ASCII characters.
z Backslash and white space are not part of the
identifiers.
Example:
module \2:1mux(out, a, b, sel);
not u0(\~out, in);
<##>
18
Edited by Chu Yu
Verilog HDL
Case Sensitivity
z Verilog is a case-sensitive language.
z You can run Verilog in case-insensitive mode by
specifying u command line option.
Example:
module inv(out, in);
endmodule
endmodule
<##>
19
Edited by Chu Yu
Verilog HDL
Verilog Module
Modules are basic building blocks in hierarchy.
Every module description starts with module
name(output_ports, input_ports), and ends with
endmodule.
Module Ports
Module ports are equivalent to the pins in hardware.
Declare ports to be input, output, or inout (bidirectional)
in the module description.
<##>
20
Edited by Chu Yu
Verilog HDL
Edited by Chu Yu
Verilog HDL
Registers
z More Examples
reg
mem1[127:0]; //128-bit memory with 1-bit wide
reg
mem2[63:0];
reg [7:0] mem3[127:0]; //128-bit memory with 8-bit wide
M
mem2=0; // illegal syntax
mem2[5] = mem1[125];
mem2[10:8] = mem1[120:118];
mem3[11]=0; //8-bit zero value
<##>
22
Edited by Chu Yu
Verilog HDL
Functionality
wire, tri
wand, triand
trireg
tri1
tri0
supply1
supply0
<##>
23
Edited by Chu Yu
Verilog HDL
Example of Nets
z Example I
<##>
24
Edited by Chu Yu
Verilog HDL
Example of Nets
z Example II
<##>
25
Edited by Chu Yu
Verilog HDL
<##>
26
Edited by Chu Yu
Verilog HDL
and
nand
nor
or
xor
xnor
not
buf
bufif0
bufif1
notif0
notif1
pullup
pulldown
MOS Switches
and Bidirectional
Transistors
nmos
pmos
cmos
rnmos
rpmos
rcmos
tran
tranif0
tranif1
rtran
rtranif0
rtranif1
Nets
wire
wand
wor
tri
triand
trior
trireg
supply0
supply1
trireg
tri1
tri0
<##>
27
Edited by Chu Yu
Verilog HDL
in
out
out
ctl
pMOS (unidirectional)
in
pctl
cMOS (unidirectional)
in
out
nctl
<##>
28
Edited by Chu Yu
Verilog HDL
<##>
29
Edited by Chu Yu
Verilog HDL
<##>
30
Edited by Chu Yu
Verilog HDL
<##>
31
Edited by Chu Yu
Verilog HDL
<##>
32
Edited by Chu Yu
Verilog HDL
Operators
Unary Operator
assign a = ~b;
Binary Operator
assign a = b&c;
Ternary Operator
assign out = sel ? a: b; //2-to-1 multiplexer
Comments
One Line Comment
// this is an example of one line comment
Multiple Line Comment
/* this is an example of
multiple line comment */
Error Comment Remarks
/* Error comment remark */ */
<##>
33
Edited by Chu Yu
Verilog HDL
Edited by Chu Yu
Verilog HDL
Literal Numbers
z Literal integers are interpreted as decimal numbers in
the machine word size (32 bits) by default.
z Size and base my be explicitly specified
<size>'<base><value>
<size>: size in bits as a decimal number.
<base>: b(binary), o(octal), h(hex), d(decimal).
<value>: 0-9, a-f, x, z, ? (must be legal number in
<base>)
Four types of logic value
0 (logical 0), 1 (logical 1), x (unknown), z (high impedence)
<##>
35
Edited by Chu Yu
Verilog HDL
12
8'd45
10'hF1
1'B1
32'bz
6'b001_010
32-bit decimal
8-bit decimal
10-bit hex (left-extended with zero)
1-bit binary
32-bit Z
6-bit binary with underscore for readability.
Edited by Chu Yu
Verilog HDL
Block Statement
z Block statement are used to group two or more
statements together.
z Two Types of Blocks
Sequential Block
- Enclosed by keyword begin and end.
Parallel Block
- Enclosed by keyword fork and join.
<##>
37
Edited by Chu Yu
Verilog HDL
#<delay>
: Simple delay.
@(<signal>) : Event control with edge-trigger and level-sensitive controls.
wait(<expr>) : Level-sensitive control.
z Edge-Trigger Control
posedge: positive edge. EX: always @(posedge clk)
negedge: negative edge. EX: always @(negedge clk)
z Examples
always @(posedge clk)
begin
#5 q=d;
#1 qb=~d;
end
posedge clk?
y
#5 q=d
#1 qb=~d
q
qb
t=0
d
~d
t=5 t=6
<##>
38
Edited by Chu Yu
Verilog HDL
read
initial
begin
read=0;
wait(en1|en2) read=1;
#5 read=0;
end
t=0
read=1
t=n t=n+5
#5 read=0
set
negedge clk?
clk
q
set=1?
always wait(set)
begin
@(negedge clk);
#3 q=1;
#1 q=0;
wait(!set);
end
t=0
#3 q=1
#1 q=0
<##>
n
set=1?
39
Edited by Chu Yu
Verilog HDL
Syntax of Verilog
z C-like structural language
<##>
40
Edited by Chu Yu
Verilog HDL
forever loop
example
example
while(val[index]==1'b0)
index=index-1;
repeat loop
for loop
example
example
repeat(mem_depth)
begin
mem[address]=0;
address=address+1;
end
for(index=0;index<size;
index=index+1)
if(val[index]==1'bx)
$display(''found an x'');
<##>
41
Edited by Chu Yu
Verilog HDL
Edited by Chu Yu
Verilog HDL
Continuous Assignment
z Continuous assignment provide a means to abstractly
model combinational hardware driving values onto nets.
An alternate version of the 1-bit full adder is shown blow:
module FA(Cout, Sum, a, b, Cin);
output Cout, Sum;
input
a, b, Cin;
assign Sum = a ^ b ^ Cin,
Cout = (a & b) | (b & Cin) | (a & Cin);
endmodule
<##>
43
Edited by Chu Yu
Verilog HDL
Procedural Assignments
z Assignments made within procedural blocks are known as
procedural assignments.
z The left-hand side of procedural assignment must be a
data type in the register class.
Example
initial
begin
out=0;
#10 en1=~net23;
#5 set=(r1|en1)&net4;
end
<##>
44
Edited by Chu Yu
Verilog HDL
<##>
45
Edited by Chu Yu
Verilog HDL
a = #10 b;
begin
temp = b;
@ (posedge clk) a = temp;
end
a = @(posedge clk) b;
begin
temp = b;
@ (posedge clk)
@ (posedge clk)
@ (posedge clk) a = temp;
end
a = repeat(3)@(posedge clk) b;
<##>
46
Edited by Chu Yu
Verilog HDL
Edited by Chu Yu
Verilog HDL
Current
Simulation
Time
M
$display() assign logic 1 to a
t = 10
t = 11
t=0
t=10
$display a
<##>
48
Edited by Chu Yu
Verilog HDL
evaluate at time = 0, a = x
t=0
t=1
Current
Simulation
Time
M
assign logic 1 to a
a
t=0
$display a
t = 10
t = 11
t=10
<##>
49
Edited by Chu Yu
Verilog HDL
Hierarchical Design
z Top-Down Design Methodology
module CPA4b(Cout, Sum, a,b,Cin);
output
Cout;
output [3:0] Sum;
input [3:0] a,b;
input
Cin;
wire [2:0] c;
adder
fa0(c[0], Sum[0], a[0], b[0], Cin); //by position mapping
adder
fa1(.a(a[1]), .b(b[1]), .cin(c[0]), .carry(c[1]), .sum(Sum[1])); //by name mapping
adder
fa2(c[2], Sum[2], a[2], b[2], c[1]);
adder
fa3(Cout, Sum[3], a[3], b[3], c[2]);
4-bit
endmodule
adder
module adder (carry, sum, a, b, cin);
output carry, sum;
input a, b, cin;
1-bit
1-bit
1-bit
1-bit
assign {carry, sum} = a + b + cin;
adder
adder
adder
adder
endmodule
<##>
50
Edited by Chu Yu
Verilog HDL
<##>
51
Edited by Chu Yu
Verilog HDL
<##>
52
Edited by Chu Yu
Verilog HDL
Edited by Chu Yu
Verilog HDL
Edited by Chu Yu
Verilog HDL
0 ps
1 ps
`timescale 100ns/1ns
module m2();
2 ps
3 ps
`timescale 1ps/1ps
module m3();
4 ps
<##>
55
Edited by Chu Yu
Verilog HDL
Compiler Directives
z All Verilog compiler directives are preceded by the
accent sign (`).
z Compiler directives remain active until they are
overridden or deactivated.
z The `resetall compiler directive resets all the compiler
directives to their default values (only if there is a
default value).
Example:
`define s0 2b00
`include lib.v
`timescale 10ns/100ps
<##>
56
Edited by Chu Yu
Verilog HDL
Compiler Directives
z The `define compiler directive provides a simple textsubstitution facility.
Syntax: define <macro_name> <text_string>
<text_string> will substitute <macro_name> at compile time.
<##>
57
Edited by Chu Yu
Verilog HDL
Compiler Directives
z Use `include compiler directive to insert the contents
of an entire file.
`include lib.v
`include dir/lib.v
<##>
58
Edited by Chu Yu
Verilog HDL
Parameters
z Parameters are constants rather than variables.
z Typically parameters are used to specify delays and
width of variable.
Example:
module varmux(out, I0, I1, sel);
parameter width=2, delay=1;
output [width-1:0] out;
input [width-1:0] I0, I1;
input sel;
assign #delay out=sel? I1:I0;
endmodule
<##>
59
Edited by Chu Yu
Verilog HDL
that
Example:
module top;
endmodule
Top.u0.width=2
Top.u0.delay=1
Top.u1.width=4
Top.u1.delay=2
<##>
60
Edited by Chu Yu
Verilog HDL
Edited by Chu Yu
Verilog HDL
Examples of Verilog-HDL
z 2-to-1 Multiplexer
module mux(out, I0, I1, sel);
output [3:0] out;
input [3:0] I0, I1;
input sel;
reg
[3:0] out;
I0
I1
0
4
Out
sel
//The output value will be changed when one of I0, I1, and sel input signals is
changing.
<##>
62
Edited by Chu Yu
Verilog HDL
Example of Verilog-HDL
z 2-to-1 Multiplexer
module mux(out, I0, I1, sel);
output [3:0] out;
input [3:0] I0, I1;
input sel;
I0
I1
assign out=sel?I1:I0;
0
4
Out
sel
endmodule
<##>
63
Edited by Chu Yu
Verilog HDL
Example of Verilog-HDL
z 4-to-1 Multiplexer
module mux(out, I3, I2, I1, I0, sel);
output [3:0] out;
input [3:0] I3, I2, I1, I0;
input [1:0] sel;
reg
[3:0] out;
always @(I3 or I2 or I1 or I0 or sel)
case (sel)
2b00: out=I0;
2b01: out=I1;
2b10: out=I2;
2b11: out=I3;
default: out=4bx;
endcase
endmodule
I0
I1
I2
I3
sel
0
4
1
4
Out
2
4
<##>
64
Edited by Chu Yu
Verilog HDL
Example of Verilog-HDL
z 4-to-1 Multiplexer
module mux(out, I3, I2, I1, I0, sel);
output [3:0] out;
input [3:0] I3, I2, I1, I0;
input [1:0] sel;
assign out = (sel==2b00)?I0:
(sel==2b01)?I1:
(sel==2b10)?I2:
(sel==2b11)?I3:
4bx;
endmodule
I0
I1
I2
I3
sel
0
4
1
4
Out
2
4
<##>
65
Edited by Chu Yu
Verilog HDL
Example of Verilog-HDL
z 3-to-1 Multiplexer
module mux(out, I3, I1, I0, sel);
output [3:0] out;
input [3:0] I3, I1, I0;
input [1:0] sel;
reg
[3:0] out;
always @(I3 or I1 or I0 or sel)
case (sel) //synopsys full_case -> If condition 2b10 is impossible
to appear.
2b00: out=I0;
2b01: out=I1;
2b11: out=I3;
endcase
endmodule // Require latches to synthesis the priority encoder circuit
if the remark synopsys full_case is not assigned.
<##>
66
Edited by Chu Yu
Verilog HDL
Example of Verilog-HDL
z Compound Logic
module complogic1(F, x, y, z);
output F;
input x, y, z;
assign F = (x&~y)|(y|z);
endmodule
module complogic2(F, x, y, z);
output F;
input x, y, z;
x
y
z
yp
xy
F
yz
<##>
67
Edited by Chu Yu
Verilog HDL
Example of Verilog-HDL
z casex I
module top(R1, R2, R3, I2, I1, I0);
output R1, R2, R3;
input I2, I1, I0;
reg
R1, R2, R3;
always @(I2 or I1 or I0)
casex ({I2, I1, I0})
3b1??: {R1, R2, R3}=3b100;
3b?1?: {R1, R2, R3}=3b010;
3b??1: {R1, R2, R3}=3b001;
endcase
endmodule
// ? = {0, 1}
// ? != {x, z}
<##>
68
Edited by Chu Yu
Verilog HDL
Example of Verilog-HDL
z casex II
module top(R1, R2, R3, I2, I1, I0);
output R1, R2, R3;
input I2, I1, I0;
reg
R1, R2, R3;
always @(I2 or I1 or I0)
casex (1b1)
I0: {R1, R2, R3}=3b100;
I1: {R1, R2, R3}=3b010;
I2: {R1, R2, R3}=3b001;
endcase
endmodule
<##>
69
Edited by Chu Yu
Verilog HDL
Example of Verilog-HDL
z casez
module top(R1, R2, R3, I2, I1, I0);
output R1, R2, R3;
input I3, I1, I0;
reg
R1, R2, R3;
always @(I2 or I1 or I0)
casez ({I2, I1, I0})
3b1??: {R1, R2, R3}=3b100;
3b?1?: {R1, R2, R3}=3b010;
3b??1: {R1, R2, R3}=3b001;
endcase
endmodule
// ? = {0, 1, x, z}
<##>
70
Edited by Chu Yu
Verilog HDL
Example of Verilog-HDL
z Comparator
module comparator(large, equal, less, a, b);
output
large, equal, less;
input [3:0] a, b;
assign large = (a > b);
assign equal = (a == b);
assign less = (a < b);
endmodule
<##>
71
Edited by Chu Yu
Verilog HDL
Hierarchical Modules
z 4-bit carry-propagate adder
module CPA(Cout, Sum, a,b,Cin);
output
Cout;
output [3:0] Sum;
input [3:0] a,b;
input
Cin;
wire [2:0] c;
adder
fa0(c[0],Sum[0],a[0],b[0],Cin);
adder
fa1(c[1],Sum[1],a[1],b[1],c[0]);
adder
fa2(c[2],Sum[2],a[2],b[2],c[1]);
adder
fa3(Cout,Sum[3],a[3],b[3],c[2]);
endmodule
fa3
Cout
Full
Adder
fa2
Full
Adder
fa1
Full
Adder
fa0
Full
Adder
Cin
Edited by Chu Yu
Verilog HDL
Example of Verilog-HDL
z Resource Sharing
module top1(out, a, b, c, sel);
output [4:0] out;
input [3:0] a, b, c;
input
sel;
reg
[4:0] out;
always @ (a or b or c or sel)
if (sel) out=a+b;
else out=a-c;
always @ (a or b or c or sel)
if (sel) out=a+b;
else out=a+c;
Edited by Chu Yu
Verilog HDL
Example of Verilog-HDL
z 1-bit latch
module Latch(q, d, rst, enable);
output q;
input d, enable, rst;
d
Latch
assign q=(rst==0)?0:
(enable==1)?d:q;
enable
rst
endmodule
<##>
74
Edited by Chu Yu
Verilog HDL
Example of Verilog-HDL
z 1-bit register with a synchronous reset
module D_FF(q, d, clk, load, rst);
output q;
input d, clk, load, rst;
reg
q;
always @(posedge clk)
if (rst==1b0) q=0;
else if (load==1b1) q=d;
d
clk
DFF
load
rst
endmodule
<##>
75
Edited by Chu Yu
Verilog HDL
Example of Verilog-HDL
z 1-bit register with a asynchronous reset
module D_FF(q, d, clk, load, rst);
output q;
input d, clk, load, rst;
reg
q;
always @(posedge clk or negedge rst)
if (rst==1b0) q=0;
else if (load==1b1) q=d;
d
clk
DFF
load
rst
endmodule
<##>
76
Edited by Chu Yu
Verilog HDL
Example of Verilog-HDL
z 4-bit up counter with load and enable signals
module counter(q, in, load, enable, rst, clk);
output [3:0] q;
input [3:0] in;
in
input
clk, load, rst, enable;
clk
reg [3:0] q;
enable
always @(posedge clk or negedge rst)
load
if (rst==1b0) q=0;
rst
else if (load==1b1) q=in;
else if (enable==1b1) q=q+1;
4-bit
counter
endmodule
<##>
77
Edited by Chu Yu
Verilog HDL
Example of Verilog-HDL
z Register with Combination Logic
module DFFE(Out, A, B, CLR, CLK);
output Out;
input A, B, CLR, CLK;
reg
Out;
always @(posedge CLK or negedge CLR)
if (CLR==1b0) Out=0;
else Out=(A&Out)|B;
A
B
CLK
Out
clr
CLR
endmodule
<##>
78
Edited by Chu Yu
Verilog HDL
<##>
79
Edited by Chu Yu
Verilog HDL
z Moore Machine
0
0
module moore(out, in, rst, clk);
output
out;
s1/0
s2/0
s3/1
1 s0/0
input
in;
0
1
0
input
clk, rst;
reg
out;
1
1
reg
[1:0] state;
parameter s0=2d0, s1=2d1, s2=2d2, s3=2d3;
always @(posedge clk or negedge rst)
if (rst==0) begin state=s0; out=0; end
else begin
case (state)
s0: begin out=0; if (in==0) state=s1; else state=s0; end
s1: begin out=0; if (in==0) state=s1; else state=s2; end
s2: begin out=0; if (in==0) state=s3; else state=s0; end
s3: begin out=1; if (in==0) state=s1; else state=s2; end
default: state=s0;
endcase
end
endmodule
<##>
80
Edited by Chu Yu
Verilog HDL
z RAM
module RAM(out, in, addr, RW, CS);
output [7:0] out;
input [7:0] in;
input [3:0] addr;
input
RW,CS;
reg
[7:0] out;
reg
[7:0] DATA[15:0];
in
addr
out
RAM
RW
CS
81
Edited by Chu Yu
Verilog HDL
z ROM
module ROM_Qe(out, addr, CS);
output [15:0] out;
input [3:0] addr;
input
CS;
reg
[15:0] out;
reg
[15:0] ROM[15:0];
addr
out
RAM
CS
<##>
82
Edited by Chu Yu
Verilog HDL
z I/O read/write
reg clk, rst, start;
reg buffer[255:0];
reg
clk, rst;
integer f2;
parameter D=10;
M
initial
begin
clk=0; rst=0; start=0;
$readmemb("c:/temp/in.dat",buffer);
#10 rst=1;
#30 start=1;
M
end
initial
begin
clk=0;rst=0;
#D #D #D rst=1;
f2=$fopen(c:/lss.dat");
$fdisplay(f2,"%d", out);
$fclose(f2);
$stop; $finish;
end
endmodule
<##>
83
Edited by Chu Yu
Verilog HDL
<##>
84
Edited by Chu Yu
Verilog HDL
symbol
Interpretation
0
1
x
?
b
(vw)
*
r
f
p
n
Logic 0
Logic 1
Unknown
Iteration of 0, 1, and x
Iterayion of 0 and 1
No change
Change of value from v to w
Same as (??)
Same as (01)
Same as (10)
Iteration of (01), (0x), and (x1)
Iteration of (10), (1x), and (x0)
input field
input field
output field
Any value change on input
Rising edge on input
Falling edge on input
Positive edge including x
Negative edge including x
<##>
85
Edited by Chu Yu
Verilog HDL
UDP Definition
z Pure combinational Logic
primitive mux(o,a,b,s);
output o;
input a,b,s;
table
// a b s : o
0 ? 1 : 0;
1 ? 1 : 1;
? 0 0 : 0;
? 1 0 : 1;
0 0 x : 0;
1 1 x : 1;
endtable
endprimitive
<##>
86
Edited by Chu Yu
Verilog HDL
<##>
87
Edited by Chu Yu
Verilog HDL
<##>
88
Edited by Chu Yu
Verilog HDL
<##>
89
Edited by Chu Yu
Verilog HDL
<##>
90
Edited by Chu Yu
Verilog HDL
<##>
91
Edited by Chu Yu
Verilog HDL
<##>
92
Edited by Chu Yu
Verilog HDL
z Example
not (weak1, strong0) u0(Y, A);
not (strong0, strong1) u1(Y, A);
Edited by Chu Yu
Verilog HDL
Specify Blocks
z What is a specify block?
Specify block let us add timing specifications to
paths across a module.
a
b
cin
Full Adder
sum
carry
Tlh_b_to_Sum = 1.5
Thl_b_to_Sum = 2.2
Tlh_a_to_Sum = 1.2
Thl_a_to_Sum = 2.0
<##>
94
Edited by Chu Yu
Verilog HDL
q
DFF
clk
UDP_DFF
specify
specparam
InCap$d = 0.024, Tsetup$d_cp = 0.41, Thold$d_cp = 0.2;
endspecify
endmodule
<##>
95
Edited by Chu Yu
Verilog HDL
UNIX Environment
verolog <command_line_options> <design file>
Example 1:
unix> verilog adder.v
Example 2:
unix> verilog file1.v file2.v file3.v
or
unix> verilog f file4
file4 content in the text mode:
file1.v
file2.v
file3.v
<##>
96
Edited by Chu Yu
Verilog HDL
a
b
cin
Full Adder
sum
carry
Response
Generation
and
Verification
z Test the full adders Verilog model by applying test patterns and
observing its output responses.
Stimulus and control: Changes on device inputs, simulation finish
time, ... etc.
Device under test: Behavior, gate, or switch level modules.
Response generation and verification: Which signals to
save/display, verification of generated response.
<##>
97
Edited by Chu Yu
Verilog HDL
Circuit Description
module add4(sum, carry, A, B, Cin);
output [3:0] sum;
endmodule
Testfixture
module testfixture;
reg [3:0] A, B;
endmodule
Verilog Simulation
Verilog Parser
Simulation Engine
User Interface
0.00 ns in = 0 out = x
16.00 ns in = 0 out = 1
100.00 ns in = 1 out = 1
<##>
98
Edited by Chu Yu
Verilog HDL
A Full Adder
module adder (carry, sum, a, b, cin);
output carry, sum;
input a, b, cin;
wire w0, w1, w2;
module testfixture;
reg a, b, cin;
wire sum, carry;
adder u0 (carry, sum, a, b, cin);
initial begin
$monitor($time, a=%b b=%b
cin=%b sum=%b carry=%b,
a, b, cin, sum, carry);
a=0; b=0; cin=0;
#10 a=0; b=0; cin=1;
#10 a=0; b=1; cin=0;
#10 a=0; b=1; cin=1;
#10 a=1; b=0; cin=0;
#10 a=1; b=0; cin=1;
#10 a=1; b=1; cin=0;
#10 a=1; b=1; cin=1;
#10 $stop; #10 $finish;
end
endmodule
Edited by Chu Yu
Verilog HDL
z Monitoring Commands
Text Format Output
$monitor($time,''a=%d, b=%b,...\n'',a,b);
Graphic Output
$gr_waves(''<signal_label>'',<signal>, ...);
$SimWave: $shm_open(<file_name>), $shm_probe( )
<##>
100
Edited by Chu Yu
Verilog HDL
%d or %D
%o or %O
%b or %B
%c or %C
%v or %V
%n or %N
%m or %M
%s or %S
display as a string
%t or %T
Edited by Chu Yu
Verilog HDL
SimWave
z Using system tasks to save the circuit state into
waveform database.
z You can use SimWave to view the signal waveforms
after Verilog-XL simulation.
z Example
module testfixture;
initial begin
$shm_open(adder.shm);
$shm_probe(A);
Edited by Chu Yu
Verilog HDL
SimWave Window
<##>
103
Edited by Chu Yu
Verilog HDL
Trouble Shooting
z If a=b is triggered by some event, a must be declared as
reg.
z A bus signal must be declared as wire.
z The negative value should be sign-extended.
z The port size and number of a module should match
anywhere it is referred.
<##>
104