Introduction To Verilog
Introduction To Verilog
Introduction To Verilog
www.pld.com.cn
Course Objectives
www.pld.com.cn
Course Outline
n Verilog Overview
n Basic Structure of a Verilog Model
n Components of a Verilog Module
– Ports
– Data Types
– Assigning Values and Numbers
– Operators
– Behavioral Modeling
• Continuous Assignments
• Procedural Blocks
– Structural Modeling
n Summary: Verilog Environment
www.pld.com.cn
Verilog
Overview
www.pld.com.cn
What is Verilog?
www.pld.com.cn
Verilog History
www.pld.com.cn
Verilog Structure
www.pld.com.cn
Terminology
www.pld.com.cn
Behavior Modeling
www.pld.com.cn
Structural Modeling
n Functionality and structure of the circuit
n Call out the specific hardware
n For the purpose of synthesis
Higher-level Component
input1 output1
Lower-level
Component1
Lower-level
Component1
inputn outputn
www.pld.com.cn
More Terminology
www.pld.com.cn
RTL Synthesis
always @(a or b or c or d or sel)
inferred
a
begin b mux_out
case (sel) c
2’b00: mux_out = a; d
2b’01: mux_out = b; sel
2b’10: mux_out = c; 2
2’b11: mux_out = d;
endcase
Translation
d
d
Optimization
www.pld.com.cn
Verilog vs. Other HDL Standards
n Verilog
– “Tell me how your circuit should behave and I will give you
the hardware that does the job.”
n VHDL
– Similar to Verilog
n ABEL, PALASM, AHDL
– “Tell me what hardware you want and I will give it to you”
www.pld.com.cn
Verilog vs. Other HDL Standards
n Verilog
– “Give me a circuit whose output only changes when there is
a low-to-high transition on a particular input. When the
transition happens, make the output equal to the input until
the next transition.”
– Result: Verilog Synthesis provides a positive edge-triggered
flipflop
n ABEL, PALASM, AHDL
– “Give me a D-type flipflop.”
– Result: ABEL, PALASM, AHDL synthesis provides a D-type
flipflop. The sense of the clock depends on the synthesis
tool.
www.pld.com.cn
Typical Synthesis Design Flow
Verilog Technology
Model Library
Synthesis
Compiler
Text Output
Test
Simulation Vectors
Waveform
www.pld.com.cn
Typical Simulation Design Flow
Verilog Verilog
Model TestBench
Optional
Simulation
Compiler
Simulation Test
Model Vectors
Waveform Verilog
Text Output
Simulation
www.pld.com.cn
Verilog
Modeling
www.pld.com.cn
Verilog - Basic Modeling Structure
n CASE-sensitve
module module_name (port_list); n All keywords are
port declarations lowercase
n Whitespace is used for
data type declarations readability.
n Semicolon is the
circuit functionality statement terminator
n Single line comment: //
timing specifications n Multi-line comment: /* */
endmodule n Timing specification is
for simulation
www.pld.com.cn
Components of a Verilog Module
Timing Specifications
endmodule
www.pld.com.cn
Schematic Representation - MAC
adder_out out
ina
+ D Q
mult_out clk
X
inb
CLRN
clr
www.pld.com.cn
Verilog Model: Mulitiplier-Accumulator (MAC)
`timescale 1 ns/ 10 ps assign adder_out = mult_out + out;
module mult_acc (out, ina, inb, clk, clr); always @ (posedge clk or posedge clr)
begin
input [7:0] ina, inb; if (clr)
input clk, clr; out = 16'h0000;
output [15:0] out; else
out = adder_out;
wire [15:0] mult_out, adder_out; end
reg [15:0] out;
multa u1(.in_a(ina), .in_b(inb), .m_out(mult_out));
parameter set = 10;
parameter hld = 20; specify
$setup (ina, posedge clk, set);
$hold (posedge clk, ina, hld);
$setup (inb, posedge clk, set);
$hold (posedge clk, inb, hld);
endspecify
endmodule
www.pld.com.cn
Let’s take a look at:
module mult_acc (out, ina, inb, clk, clr); always @ (posedge clk or posedge clr)
begin
input [7:0] ina, inb; if (clr)
out = 16'h0000;
input clk, clr; else
output [15:0] out; out = adder_out;
end
wire [15:0] mult_out, adder_out;
reg [15:0] out; multa u1(.in_a(ina), .in_b(inb), .m_out(mult_out));
endmodule
www.pld.com.cn
Data Types
n Net Data Type - represent physical interconnect between
processes (activity flows)
process process
Functional Functional
nets Block:
nets Block:
nets
MUX Adders
(nets) (nets)
www.pld.com.cn
Net Data Type
n Bus Declarations:
– <data_type> [MSB : LSB ] <signal name> ;
– <data_type> [LSB : MSB] <signal name> ;
n Examples:
– wire <signal name> ;
– wire [15:0] mult_out, adder_out;
www.pld.com.cn
Net Data Types
Supported by
Net Data Type Functionality Synthesis
www.pld.com.cn
Register Data Types
n Bus Declarations:
– <data_type> [MSB : LSB ] <signal name> ;
– <data_type> [LSB : MSB] <signal name> ;
n Examples:
– reg <signal name> ;
– reg [7 : 0] out ;
www.pld.com.cn
Register Data Types
Register Supported by
Data Type Functionality Synthesis
www.pld.com.cn
Memory
instr = mem[2];
www.pld.com.cn
Parameter
parameter size = 8;
reg [size-1:0] a, b;
www.pld.com.cn
Data Type
www.pld.com.cn
Data Types: Declaration
`timescale 1 ns/ 10 ps assign adder_out = mult_out + out;
module mult_acc (out, ina, inb, clk, clr); always @ (posedge clk or posedge clr)
begin
input [7:0] ina, inb; if (clr)
input clk, clr; out = 16'h0000;
output [15:0] out; else
out = adder_out;
wire [15:0] mult_out, adder_out; end
reg [15:0] out; multa u1(.in_a(ina), .in_b(inb), .m_out(mult_out));
endmodule
www.pld.com.cn
Assigning Values - Numbers
and
Operators
www.pld.com.cn
Assigning Values - Numbers
www.pld.com.cn
Numbers
www.pld.com.cn
Numbers
n Extended
– If MSB is 0, x, or z, number is extended to fill MSBs with 0, x,or
z, respectively
• Examples: 3’b01 = 3’b001, 3’bx1 = 3’bxx1, 3’bz = 3’bzzz
– If MSB is 1, number is extended to fill MSBs with 0
• Example: 3’b1 = 3’b001
www.pld.com.cn
Short Quiz
n Short Quiz:
– Q: What is the actual value for 4’d017 in binary?
www.pld.com.cn
Answers
n Short Quiz:
– Q: What is the actual value for 4’d017 in binary?
– A: 4’b0001, MSB is truncated (10001)
www.pld.com.cn
Arithmetic Operators
Operator Operation Examples
Symbol Performed ain = 5, bin = 10, cin = 2’b01, din =2’b0Z
www.pld.com.cn
Reduction Operators
Operator Operation Examples
Symbol Performed ain = 5’b10101, bin = 4’b0011
cin = 3’bZ00, din = 3’bX011
& And all bits &ain = 1’b0, &din = 1’b0
~& Nand all bits ~&ain = 1’b1
| Or all bits |ain = 1’b1, |cin = 1’bX
~| Nor all bits ~|ain = 1’b0
^ Xor all bits ^ain = 1’b1
~^ or ^~ Xnor all bits ~^ain = 1’b0
www.pld.com.cn
Equality Operators
Operator Operation Examples
Symbol Performed ain 3’b010, bin = 3’b100, cin=3’b111
din = 3’b01z, ein = 3’b01x
www.pld.com.cn
Logical Operators
Operator Operation Examples
Symbol Performed ain = 3’b101, bin = 3’b000
www.pld.com.cn
Shift Operators
Operator Operation Examples
Symbol Performed ain = 4’b1010, bin = 4’b10X0
www.pld.com.cn
Miscellaneous Operators
Operator Operation Examples
Symbol Performed
www.pld.com.cn
Operator Precedence
n Operators default precedence
+ , - , ! , ~ (unary) Highest Priority
+ , - (Binary)
<< , >>
< , > , <= , >=
== , !=
&
^ , ^~ or ~^
|
&&
||
?: (ternary) Lowest Priority
n ( ) can be used to override default
www.pld.com.cn
Components of a Verilog Module
Continuous Assignment
www.pld.com.cn
Continuous Assignments
www.pld.com.cn
Continuous Assignments: Characteristics
www.pld.com.cn
Continuous Assignments
`timescale 1 ns/ 10 ps // Continuous Assignment
module mult_acc (out, ina, inb, clk, clr); assign adder_out = mult_out + out;
input [7:0] ina, inb; always @ (posedge clk or posedge clr)
input clk, clr; begin
output [15:0] out; if (clr)
out = 16'h0000;
wire [15:0] mult_out, adder_out; else
reg [15:0] out; out = adder_out;
end
parameter set = 10;
parameter hld = 20; multa u1(.in_a(ina), .in_b(inb), .m_out(mult_out));
specify
$setup (ina, posedge clk, set);
$hold (posedge clk, ina, hld);
$setup (inb, posedge clk, set);
$hold (posedge clk, inb, hld);
endspecify
www.pld.com.cn endmodule
Continuous Assignment - Example
endmodule
www.pld.com.cn
Simulation Time
www.pld.com.cn
One Type of Continuous Assignment Delay
n Regular Assignment Delay
Procedural Blocks
www.pld.com.cn
Two Structured Procedures (Blocks)
n initial Block - Used to initialize behavioral statements
for simulation
n always Block - Used to describe the circuit functionality
using behavioral statements
www.pld.com.cn
Two Procedural Blocks
Behavioral Statements
Assignments:
Blocking
Nonblocking
Timing Specifications
www.pld.com.cn
Initial Block
www.pld.com.cn
Initial Block
www.pld.com.cn
Initial Block Example
module system;
Time Statement Executed
reg a, b, c, d;
initial
#20 $finish;
endmodule
www.pld.com.cn
Always Block
n Consists of behavioral statements
n If there are more than one behavioral statement
inside an always block, the statements can be
grouped using the keywords begin and end.
n If there are multiple always blocks, each block
executes concurrently.
www.pld.com.cn
Always Block
www.pld.com.cn
Characteristics
1) Left-hand side (LHS) must be
a register data type: Can be a reg,
integer, real, or time variable or a
memory element
2) LHS can be a bit-select or part-select
3) A concatenation of any of the above
4) Right-hand side (RHS): All operators
can be used in behavioral reg [15:0] out;
expressions
always @ (posedge clk or posedge clr)
begin
if (clr)
out = 16'h0000;
else
out = adder_out;
end
www.pld.com.cn
Always Block - Example
module clock_gen (clk); Time Statement Executed
output clk;
reg clk; 0 clk = 1’b0
initial
#100 $finish;
endmodule
www.pld.com.cn
Always/Initial Blocks
always/initial
blocks
www.pld.com.cn
Procedural Assignments
www.pld.com.cn
Procedural Assignments
www.pld.com.cn
Two types of Procedural Assignments
www.pld.com.cn
Blocking vs. Nonblocking Assignments
5 10 15 5 10 15
www.pld.com.cn
Simulation Time
www.pld.com.cn
3 Delay Controls for Procedural Assignment
www.pld.com.cn
Regular Delay Control
n Regular Assignment Delay
Statement Executed
always/initial
blocks
www.pld.com.cn
Processes and Behavioral Statements
www.pld.com.cn
Sensitivity List
n Sensitivity List:
always @(sensitivity_list)
begin
-- Statement #1
-- … … … … ..
-- Statement #N
end
www.pld.com.cn
Two Types of Processes
• Combinatorial Process
– Sensitive to all inputs used in
the combinatorial logic a
c
• Example b
always @(a or b or sel)
sel
sensitivity list includes all inputs used
in the combinatorial logic
• Clocked Process d D Q q
– Sensitive to a clock or/and
control signals clk
ENA
• Example CLRN
• Combinatorial Process
– Sensitive to all inputs used in
the combinatorial logic a
c
• Example b
always @(a or b or sel)
sel
sensitivity list includes all inputs used
in the combinatorial logic
www.pld.com.cn
Behavioral Statements
n Behavioral Statements
– IF-ELSE statement
– CASE statement
– Loop statements
www.pld.com.cn
If-Else Statements
n Format: n Example:
if (<condition1>) always @(sela or selb or a or b or c)
sequence of statement(s) begin
else if (sela)
if (<condition2>) q = a;
sequence of statement(s) else
if (selb)
. q = b;
. else
else q = c;
sequence of statement(s) end
c
b q
a
selb
www.pld.com.cn sela
If-Else Statements
www.pld.com.cn
Case Statement
n Format: n Example:
case (expression) always @(sel or a or b or c or d)
<condition1> : begin
sequence of statement(s) case (sel)
<condition2> : 2’b00 :
sequence of statement(s) q = a;
2’b01 :
. q = b;
2’b10 :
. q = c;
default :
default :
sequence of statement(s) q = d;
endcase endcase
end
a
b q
c
d
www.pld.com.cn sel
2
Case Statement
www.pld.com.cn
Two Other Forms of Case Statements
n casez casez (encoder)
4’b1??? : high_lvl = 3;
– Treats all ‘z’values
4’b01?? : high_lvl = 2;
in the case 4’b001? : high_lvl = 1;
conditions as don’t 4’b0001 : high_lvl = 0;
cares, instead of default : high_lvl = 0;
logic values endcase
– All ‘z’ values can • if encoder = 4’b1zzz, then high_lvl = 3
also be represented
by ‘?’ casex (encoder)
4’b1xxx : high_lvl = 3;
n casex
4’b01xx : high_lvl = 2;
– Treats all ‘x’ and ‘z’ 4’b001x : high_lvl = 1;
values in the case 4’b0001 : high_lvl = 0;
conditions as don’t default : high_lvl = 0;
cares, instead of endcase
logic values • if encoder = 4’b1xzx, then high_lvl = 3
www.pld.com.cn
Loop Statements
www.pld.com.cn
Forever and Repeat Loops
initial
begin
count = 0; Counts from 0 to 100
while (count < 101) Exits loop at count 101
begin
$display (“Count = %d”, count);
count = count + 1;
end
end
www.pld.com.cn
For Loop
n for loop -
integer i; // declare the index for the FOR LOOP
executes once
at the start of always @(inp or cnt)
the loop and begin
result[7:4] = 0;
then executes result[3:0] = inp;
if expression is if (cnt == 1)
true begin
for (i = 4; i <= 7; i = i + 1)
begin
4-bit Left Shifter
result[i] = result[i-4];
end
result[3:0] = 0;
7 6 5 4 3 2 1 0 end
www.pld.com.cn
Clocked Process
n Let’s now look at:
– Clocked Process Examples
– Functional for synthesis
n Nonblocking assignments (<=) are used for clocked
processes when writing synthesizable code
• Clocked Process d D Q q
– Sensitive to a clock or/and
control signals clk
ENA
• Example CLRN
www.pld.com.cn
Clock Enable
Clock Enable
module clk_enb (d, ena, clk, q) ;
reg q ;
www.pld.com.cn
Functional Counter
module cntr(q, aclr, clk, func, d);
input aclr, clk;
input [7:0] d;
input [1:0] func; // Controls the functionality
output [7:0] q;
reg [7:0]q;
always @(posedge clk or posedge aclr) begin
if (aclr)
q <= 8'h00;
else
case (func)
2'b00: q <= d; // Loads the counter
2'b01: q <= q + 1; // Counts up
2'b10: q <= q - 1; // Counts down
2'b11: q <= q;
endcase
end
endmodule
www.pld.com.cn
Always/Initial Blocks
always/initial
blocks
www.pld.com.cn
Block Execution
www.pld.com.cn
Two Types of Block Executions
www.pld.com.cn
Sequential vs. Parallel Blocks
www.pld.com.cn
Behavioral Modeling
www.pld.com.cn
Components of a Verilog Module
www.pld.com.cn
Create a Function for the multiplier
adder_out out
ina
+ D Q
mult_out clk
X
inb
CLRN
clr
www.pld.com.cn
Function Definition - Multiplier
Function Definition:
function [15:0] mult;
input [7:0] a, b ;
reg [15:0] r;
integer i ;
begin
if (a[0] == 1)
r = b;
else
r=0;
for (i =1; i <=7; i = i + 1)
begin
if (a[i] == 1)
r = r +b <<i ;
end
mult = r;
end
endfunction
www.pld.com.cn
Function Invocation - MAC
`timescale 1 ns/ 10 ps assign adder_out = mult_out + out;
module mult_acc (out, ina, inb, clk, clr); always @ (posedge clk or posedge clr)
begin
input [7:0] ina, inb; if (clr)
input clk, clr; out = 16'h0000;
output [15:0] out; else
out = adder_out;
wire [15:0] mult_out, adder_out; end
reg [15:0] out;
// Function Invocation
parameter set = 10;
parameter hld = 20; assign mult_out = mult (ina, inb);
specify
$setup (ina, posedge clk, set);
$hold (posedge clk, ina, hld);
$setup (inb, posedge clk, set);
$hold (posedge clk, inb, hld);
endspecify
www.pld.com.cn endmodule
Create a Task for the Statemachine Output
RESET
Inputs: Outputs:
reset select
nw Idle first
nxt = 0 nw = 1
first = 0
nxt
nw = 0
Tap1
nw = 1 select = 0
Tap4 first = 1
select = 3
nxt = 1
Tap2
Tap3 select = 1
select = 2 first = 0
www.pld.com.cn
Task Definition - Statemachine Output
task stm_out (nxt, first, sel, filter);
input [2:0] filter;
output nxt, first;
output [1:0] sel;
reg nxt, first;
reg [1:0] sel;
parameter idle=0, tap1=1, tap2=2, tap3=3, tap4=4;
begin
nxt = 0; first = 0;
case (filter)
tap1: begin sel = 0; first = 1; end
tap2: sel = 1;
tap3: sel = 2;
tap4: begin sel = 3; nxt = 1; end
default: begin nxt = 0; first = 0; sel = 0; end
endcase
end
endtask
www.pld.com.cn
Task Invocation - Statemachine
module stm_fir (nxt, first, sel, clk, reset, nw);
input clk, reset, nw;
output nxt, first;
output [1:0] sel;
reg nxt, first;
reg [1:0] sel;
reg [2:0] filter;
parameter idle=0, tap1=1, tap2=2, tap3=3, tap4=4;
always @(posedge clk or posedge reset)
begin if (reset) filter = idle;
else case (filter)
idle: if (nw==1) filter = tap1;
tap1: filter = tap2;
tap2: filter = tap3;
tap3: filter = tap4;
tap4: if (nw==1) filter = tap1;
else filter = idle; endcase end
always @(filter)
// Task Invocation
stm_out (nxt, first, sel, filter);
www.pld.com.cn
Differences
Functions Tasks
n Can enable another function but n Can enable other tasks and
not another task functions
n Always executes in zero n May execute in non-zero
simulation time simulation time
n Can not contain any delay, event, n May contain delay, event, or
or timing control statements timing control statements
n Must have at least one input n May have zero or more input,
argument output, or inout arguments
n Always return a single value n Returns zero or more values
n Can not have output or inout
arguments
www.pld.com.cn
Review - Behavioral Modeling
Continuous Assignment Procedural Block
module full_adder4(fco, fsum, cin, a, b); module fll_add4(fco, fsum, cin, a, b);
endmodule endmodule
www.pld.com.cn
Structural
Modeling
www.pld.com.cn
Levels of Abstraction
Behavioral Modeling
Behavioral Models input1, .., inputn
if (input1)
output1, .., outputn
www.pld.com.cn
Stuctural Modeling
www.pld.com.cn
Verilog Structural Modeling
www.pld.com.cn
Verilog Structural Modeling
www.pld.com.cn
Instantiation of Gate Primitives
n Instantiation Format:
<gate_name> #<delay> <instance_name> (port_list);
www.pld.com.cn
Connecting ports by ordered list
n For Verilog gate primitives, the module half_adder (co, sum, a, b);
first port on the port list is the output,
followed by the inputs. output co, sum;
– <gate_name> input a, b;
• and
• xor parameter and_delay = 2;
– #delay - OPTIONAL
parameter xor_delay = 4;
• 2 time unit for the and gate
and #and_delay u1(co, a, b);
• 4 time unit for the xor gate
xor #xor_delay u2(sum, a, b);
– <instance_name> - OPTIONAL
• u1 for the and gate endmodule
• u2 for the xor gate
– (port_list) a co
• (co, a, b) - (output, input, input)
• (sum, a, b) - (output, input, input)
b sum
www.pld.com.cn
User-Defined Primitives (UDP)
www.pld.com.cn
UDP - Latch
primitive latch (q, clock,data); // Level sensitive, active low
output q;
reg q;
input clock, data;
initial q = 1'b0; // Output is initialized to 1'b0.
// Change 1'b0 to 1'b1 for power up Preset
table
// clock data current state next state
0 1 :?: 1;
0 0 :?: 0;
1 ? :?: -; // ‘-’= no change
endtable
endprimitive
www.pld.com.cn
UDP - Register
primitive d_edge_ff (q, clock,data); //edge triggered, active high
output q;
reg q;
input clock, data;
initial q = 1'b0; //Output is initialized to 1'b0.
//Change 1'b0 to 1'b1 for power up Preset
table
// clk data state next
(01) 0 :?: 0;
(01) 1 :?: 1;
(0x) 1 :1: 1;
(0x) 0 :0: 0;
(?0) ? :?: -; // ignore negative edge of the clock
? (??) :?: -; // ignore data changes on clock levels
endtable
endprimitive
www.pld.com.cn
Instantiation of lower-level Components
n Instantiation Format:
www.pld.com.cn
Connecting ports by ordered list or by name
n For user-created lower-level module full_adder(fco, fsum, cin, a, b);
components, the port connection is
defined by the module declaration’s output fco, fsum;
port list order. input cin, a, b;
wire c1, s1, c2;
module half_adder (co, sum, a, b);
– Therefore for the first half_adder : half_adder u1(c1, s1, a, b);
– The ports are connected by ordered list half_adder u2(.a(s1), .b(cin),
– The order of the port connection does .sum(fsum), .co(c2));
matter or u3(fco, c1, c2);
• co -> c1, sum -> s1, a -> a, b -> b
endmodule
n For the second half_adder:
– The ports are connected by name c1
a u3
u1 s1 c2 fco
– The order of the port connection does b u2
not matter cin fsum
• a -> s1, b -> cin, sum -> fsum, co ->c2
www.pld.com.cn
Port Connection Rules
Port connections when modules
are instantiated within other
modules
driving
output
into a
Ports consist of 2 units: reg or net net
input
1) internal to the module
driving from a net
2) external to the module inout
reg or net
net driving
from/into a
net
www.pld.com.cn
Defparam
n Used to change the value of a lower-level component
parameter(s)
module full_adder(fco, fsum, cin, a, b);
endmodule
www.pld.com.cn
Simulation Time
www.pld.com.cn
Gate Delays
www.pld.com.cn
Min/Typ/Max Values
www.pld.com.cn
Verilog Summary
www.pld.com.cn
Verilog Environment
www.pld.com.cn
Verilog - Design Block
module counter(q, clk, clr, f, in); else
input clk, clr; case (f)
input [1:0] f; 2'b00: q = d; // Loads the counter
input [7:0] d; 2'b01: q = q + 1; // Counts up
output [7:0] q; 2'b10: q = q - 1; // Counts down
reg [7:0] q; 2'b11: q = q;
parameter set = 4, hold = 1; endcase
end
clock_gen #(100, 50) clock(clk);
specify
always @(posedge clk or posedge clr) $setup (d, posedge clk, set);
$hold (posedge clk, d, hold);
begin
endspecify
if (clr)
q = 8'h00;
endmodule
www.pld.com.cn
Verilog - Stimulus Block
module counter_test(clrd, fd, ind, clkd);
input clkd;
output clrd;
output [1:0] fd;
output [7:0] ind;
reg clrd;
reg [1:0] fd;
reg [7:0] ind;
clock_gen #(100, 50) clockd(clkd);
always @(posedge clkd) begin
clrd=1; fd=0; ind=0;
#100 clrd=1; fd=0; ind=0;
#100 clrd=0; fd=0; ind=8’b01010101;
#100 clrd=0; fd=3; ind=8’b11111111;
#100 clrd=0; fd=1; ind=8’b10101010;
#100 clrd=0; fd=2; ind=8’b11001100; end
endmodule
www.pld.com.cn
Verilog - System Stimulus Block
module counter_system;
wire clear, sys_clock;
wire [1:0] func;
wire [7:0] datain, result;
initial begin
$display(“\t\t Time clear sys_clock func datain result”);
$monitor($time,,clear,,,,,,,,,,sys_clock,,,,,,,,,,func,,,,,,,datain,,,,,,result);
endmodule
www.pld.com.cn
Verilog Environment
counter_system
clock_gen
clk sys_clock
counter
counter_test clk
q result
clear
clkd clrd clr
func
fd f
datain
ind in
www.pld.com.cn
Verilog
www.pld.com.cn
Typical Simulation Design Flow
Verilog Verilog
Model TestBench
Optional
Simulation
Compiler
Simulation Test
Model Vectors
Waveform Verilog
Text Output
Simulation
www.pld.com.cn
Typical Synthesis Design Flow
Verilog Technology
Model Library
Synthesis
Compiler
Text Output
Test
Simulation Vectors
Waveform
www.pld.com.cn
Verilog
Synthesis Simulation
n Functionality n Functionality and Timing
module dff ( d, clk, q); module dff ( d, clk, q);
input d, clk ;
input d, clk ;
output q;
output q;
wire d, clk;
wire d, clk; reg q ;
reg q ;
always @(posedge clk)
always @(posedge clk) q=d;
specify
q=d;
$setup (d, posedge clk, set);
endmodule $hold (posedge clk, d, hold);
endspecify
endmodule
www.pld.com.cn
Appendix
www.pld.com.cn
System Tasks and Functions
www.pld.com.cn
Compiler Directives
www.pld.com.cn
Compiler Directives
www.pld.com.cn
Conditional Compilation
// Conditional Compilation
`ifdef TEST // Compile module counter only if text macro TEST is defined
module counter;
…
..
endmodule
`else // Compile the module counter_test as default
module counter_test;
…
…
endmodule
`endif
www.pld.com.cn
Timing Specifications
www.pld.com.cn
Specify Blocks
www.pld.com.cn
Parallel Connection
www.pld.com.cn
Full Connection
is equivalent to
specify
specparam a_to_b = 5;
a => b = a_to_b;
end specify
www.pld.com.cn
Rise, Fall, Turn-off and Min/Typ/Max Values
specify
end specify
www.pld.com.cn
Timing Checks
n $setup task - system task that n $hold task - system task that
checks for the setup time checks for the hold time
$setup(data_event, reference_event, limit); $hold(reference_event, data_event, limit);
– data_event - monitored for – reference_event - establishes
violations a reference for monitoring the
– reference_event - establishes dat_event signal
a reference for monitoring the – data_event - monitored for
dat_event signal violations
– limit - minimum time for setup – limit - minimum time for hold
clock specify
$setup (ina, posedge clk, set);
$hold (posedge clk, ina, hld);
data
$setup (inb, posedge clk, set);
$hold (posedge clk, inb, hld);
setup hold endspecify
time time
www.pld.com.cn
OVI Synthesis Guidelines
www.pld.com.cn
OVI Synthesis Guidelines
www.pld.com.cn
OVI Synthesis Guidelines
www.pld.com.cn
OVI Synthesis Guidelines
www.pld.com.cn