Introduction to Basic Verilog Concepts
Introduction to Basic Verilog Concepts
Elazar Sarel
Basic Icons
The non-synthesizable person –
announces that a feature is not
synthesizable.
Basic Verilog
Intel Confidential
Agenda
Introduction
Lexical Rules
Module Structure
Data Types
Structural Modeling
Behavioral Modeling, Statements
Hardware Elements
Compiler Directives & System tasks
State Machines
Simulation
Basic Verilog
Intel Confidential
Goals
Get familiar with the Verilog language.
Gain basic knowledge of different
coding styles (structural and behavioral)
and abstraction levels
Be able to write a simple RTL model in
Verilog
Verilog coding for simulation (delays,IO,
File managing etc…)
Invoking Verilog Simulator
Basic Verilog
Intel Confidential
Basic Verilog
Intel Confidential
What is HDL
Hardware Description Language
A language used to describe digital
hardware elements
Various levels of abstraction:
– Behavioral: flow control, arithmetic operators,
High Small
complex delays
– Register Transfer Level (RTL): description of the
Abst. Level
Code Size
registers
– Gate level: combinatorial logic gates.
– Switch level: layout description of the wires,
Low resistors and transistors (CMOS,PMOS etc…). Large
not described in this course.
If it is easier to write RTL in the Behavioral abstraction
level, why should we
Basic use lower abstraction levels ?
Verilog
Intel Confidential
What is Verilog ?
It is a Hierarchical Hardware Description
Language
It supports all levels of abstraction
Verilog also supports constructs
understood by simulation tools (Non-
synthesizable high level behavioral
code).
Basic Verilog
Intel Confidential
Basic Verilog
Intel Confidential
A Short Example
// Interface
8
module comparator
a (a, b, a_bigger_b);
a_bigger_b
8 Comparator input [7:0] a, b;
b output a_bigger_b;
// Internal Signals
reg a_bigger_b;
// logic
always @(a or b)
begin
if (a > b)
a_bigger_b = 1;
else
a_bigger_b = 0;
end // always @(a or b)
Basic Verilog
endmodule // comparator
Intel Confidential
Verilog History
1984 – Gateway company started to develop the
Verilog language.
1985 – First simulators for Verilog were available.
1990 – Cadence bought Gateway, and started to
push the Verilog language.
Verilog
1990 – the OVI (Open Verilog International) 95
committee has been formed.
1995 –Verilog (+ PLI) has been accepted as an Verilog
IEEE’s standard (IEEE.1364-1995). 2001
2001 – A new Verilog (+ PLI) IEEE standard with SystemVerilog
extended constructs (IEEE.1364-2001). AKA Verilog 2000
Future – System-Verilog a new language based on
Verilog with high level modeling features (structs,
interfaces …)
Basic Verilog
Intel Confidential
Basic Verilog
Intel Confidential
Design Flow
Verilog model
Functional Stage
RTL Simulation
Synthesis
Libraries
Layout Implementation Stage
Basic Verilog
Intel Confidential
Basic Verilog
Intel Confidential
Lexical Conventions
White space consist of the following:
– Blank spaces (\b). - Spaces (‘ ‘)
– Tabs (\t). - New lines (\n)
Verilog ignores white spaces, except
when they separate words
Every Verilog statement ends with
semicolon (;)
Verilog is case sensitive
Basic Verilog
Intel Confidential
Comments
In Verilog there are line comments and
multiple line comments (like in C++)
a = b && c; //this is a line comment
Line comment
/* This is a multiple line
comment */
Multiple lines
/* This is /* an illegal */ comment */ comments
// This is /* an illegal
comment */
Basic Verilog
Intel Confidential
Numbers Specification
Sized numbers are written in the following
specification:
<size>’<base format (b,o,d,h)><number>
Be aware : use right ‘
Unsized numbers are written without the
<size> parameter, using the default size of 32
bits.
– Unsized numbers without the <base format> are decimal ones
Zero padding if the size is greater than the number of
bits specified
– Example : 8’b0 is similar to 8’b00000000
Basic Verilog
Intel Confidential
Numbers Example
5’b10101
5 bit binary number 10101
Sized numbers
Operators
Operators are of three types unary,
binary and ternary
Basic Verilog
Intel Confidential
Arithmetic + Add B/U
1
-
*
Subtract
Multiply
B/U
B
Operators
1
1
/
%
Divide
Modulus
Power
B
B Table
2 ** B
Reduction & Reduction and U
Logical ! Logical negation U
~& Reduction nand U
&& Logical and B
| Reduction or U
|| Logical or B
Relational > Greater than B ~| Reduction nor U
Basic Verilog
Intel Confidential
Logical Operators
If result = 0 false (logical 0)
If result 0 true (logical 1)
reg [3:0] i,j,k;
reg a,b,c;
…
i = 4’b0101;
j = 4’hf;
k = 4’h0;
Verilog
c = !i; // “not true”Basic false 0
Intel Confidential
Concatenation
The concatenation operator provides
mechanism to append multiple
operands
The operands must be sized
The operands can be:
– scalar nets or variables, vector nets or
registers, bit-select, part-select or sized
constants
Basic Verilog
Intel Confidential
Concatenation (continue)
Syntax:
– { operand [, operand]* }
Basic Verilog
Intel Confidential
Replication Concatenation
Replication operator enables us to replicate
an expression
The operands must be sized
Syntax:
– { number { operand } }
Strings
A string is a sequence of characters that
are enclosed by double quotes.
Strings must be on one line.
Examples of strings
Strings are
“This is a string”
“a = x && y;”
not truly
synthesizable
Basic Verilog
Intel Confidential
Basic Verilog
Intel Confidential
Escaped Identifiers
Escaped identifiers begin with the
backslash (\) character and end with
white space.
All characters between the backslash
and the white space are acceptable.
\a+b-c
\**my_name**
\address[10]
Basic Verilog
Intel Confidential
Basic Verilog
Intel Confidential
Summary
Lexical convention of operations,
comments, white space, numbers,
strings and identifiers were discussed.
In the next slides we’ll discuss how to
use those elements in Verilog
Basic Verilog
Intel Confidential
A Short Quiz #1
Write the following numbers :
– 7 in a hexadecimal format (3 bits)
– 9 in a binary format (4 bits)
Basic Verilog
Intel Confidential
Modules
Modules are Verilog design blocks
Modules allow you to create unique
objects:
– Hardware cells
– Hardware blocks with instantiations of
multiple cells
– Test benches for simulation
Basic Verilog
Intel Confidential
Module structure
Definition
– Module name
– Interface
– Ports declaration
– Parameters declaration
Body
– Internal signals declaration
– Assign statements
– Always blocks
– Initial blocks
– Instantiations
Basic Verilog
Intel Confidential
Module Definition
Module name module mymodule(…)
…
…
…
…
endmodule
End of module
Basic Verilog
Intel Confidential
Interface - Ports
Ports are the interface by which a module
communicates with the outside world
Ports are used to connect other modules
3 kinds of port directions:
– input – driven by external module
– output – driven by the current module
– inout – can be used in both modes
Input and inout ports must be nets
Output ports that hold their values must be
“reg”s
Explanation of net and reg will follow
Basic Verilog
Intel Confidential
reg b;
…
endmodule
Basic Verilog
Intel Confidential
Signal values
Each bit of a signal can contain the
following values:
–0
–1
– Z : disconnected net (high impedance)
– X : unknown / contention / propagation or
an unknown/disconnected value
Basic Verilog
Intel Confidential
Basic Verilog
Intel Confidential
Signal types
2 Signal types:
– Net, usually Wire
» do not store value
» Value is valid for as long as it is being driven
» Signal will have the Z value when not driven
– Variable, usually Reg
» The last value that was driven is stored until new
value is assigned
» The signal will have the X value if never driven
Reg is not automatically a register
Basic Verilog
Intel Confidential
module module
0
0 1 5
1 5 a1 Vcc1 b1
a1 Vcc1 b1 2 6
2 6 a2 b2
a2 b2 3 7
3 7 a3 b3
a3 b3 4 8
4 8 a4 GND b4
a4 GND b4
0
0
always SET
assign
D Q
CLR
Q
always
Basic Verilog
Intel Confidential
Net types
wire
– A simple net
– The default signal type
tri
– used for nets with multiple sources
(busses)
tri0/tri1
– has value of 0/1 if not driven
(pulldown/pullup)
Basic Verilog
Intel Confidential
Variable types
reg
– The basic register type
integer
– 2s-complement signed number
– 32 bits long
Basic Verilog
Intel Confidential
Basic Verilog
Intel Confidential
Vectors
A vector (packed vector) is a multi-bit net or
reg
The range is determined using square
brackets:
<signal type> [MSB:LSB] <signal name>
Most significant Least significant
bit index bit index
Vectors - example
module myencoder (in, out);
1 bit length input in;
input wire in;
3 bit length output [2:0] out;
output reg [2:0] out;
Arrays / Memories
Arrays (packed vectors) can be modeled as
an array of variables
Each element of an array is called a word
A word can be one or more bits
Only single words can be approached from a
memory/array element. (sub-arrays can not
be accessed)
An Array can have one dimension in Verilog
95 and an unlimited (1024) number of
dimensions in Verilog 2001
Basic Verilog
Intel Confidential
Arrays - example
Selects
Vector Bit select: Selects one bit of a vector
– Syntax: <vector_name>[<bit_num>]
Vector Part select (slice) : Select a part of a vector
– Syntax: <vector_name>[<bit_num1>:<bit_num2>]
Word Select : selects one word of an array
– Syntax: <array name> [<dim1 num>][<dim2 num>]…
reg [30:0] vec;
reg [200:0] arr1 [100:10];
8 ‘th bit of vec
wire res1 = vec[7];
Bits 16-4 of vec
wire [12:0] res2 = vec[16:4];
Word 20 of arr1 wire [200:0] res3 = arr1[20];
Basic Verilog
Intel Confidential
Parameters
Parameters are constants
Their value are determined at compile
time // state machine possible states
parameter
STATE1 = 1,
Parameters
STATE2 = 2,
declaration
STATE3 = 3;
// myreg width
parameter WIDTH 256;
reg [WIDTH-1:0] myreg;
Basic Verilog
Intel Confidential
A Short Quiz #2
A black box model is a module that has no logic (only
an interface) it is used to represent the full module
before it’s logic is written (It is instantiated instead of
the real model)
Write a module interface representing the following 4
bit clocked adder.
– Module name : a4_bit_clocked_adder
– Interface signals
» in1_or_res : a 4 bit sig. representing the first operand or the addition
result.
» In2 : a 4 bit signal representing the second operand .
» carry_out : a 1 bit signal representing the generated carry out.
» clk : a 1 bit signal representing the system clock.
Basic Verilog
Intel Confidential
Basic Verilog
Intel Confidential
Hierarchies
A module can contain other modules
TOP
DSP
FLOP
MUX
Instances
Hierarchies are created through
instantiations
Instance is the object created inside a
module
Instances are modules
Syntax :
– <module_name> [#(<parameter_values>)]
<instance_name>
– [(<list_of_port_arguments>)];
Basic Verilog
Intel Confidential
Instantiations – example1
module flop (clk, d, q);
input clk, d;
output q;
Instantiations – example2
module buffer (in, out);
parameter WIDTH = 3; // default
input [WIDTH-1 : 0] in;
output [WIDTH-1 : 0] out;
Parameter Values
Module name Instance name Port arguments
Basic Verilog
Intel Confidential
Parameter overloading -
Example
Parameters in design can be changed when
instantiating them.
The instantiated modules parameters can be
assigned by order list. In Verilog 2001 they
also can be assigned by name.
An unassigned parameter keeps its default
value.
Assigning instantiated modules parameters is
a very useful way to reuse code and work
with libraries.
Basic Verilog
Intel Confidential
Parameter overloading
module myflop (d,clk,q,reset);
parameter WIDTH = 256;
parameter RESET_VALUE = 0 Changing WIDTH to be 8
input clk, reset; Reset value is 0
input [WIDTH-1:0] d;
output [WIDTH-1:0] q;
… module mytop;
endmodule wire [7:0] indat8, outdat8;
myflop #(8,0)inst1(indat8,clk,outdat8,reset);
or
myflop #(.RESET_VALUE(0),.WIDTH(8))inst1(…);
or
myflop #(8) inst1(…);
or
myflop #(.WIDTH(8)) inst1(…);
endmodule Basic Verilog
Intel Confidential
Hierarchical names
Unique name for each object:
TOP
DSP
inst1
MUX TOP.inst1
inst2
TOP.inst1.inst2
Basic Verilog
Intel Confidential
Connectivity
Instances are connected to other
modules through their ports
TOP
in out
FLOP
clk
Basic Verilog
Intel Confidential
Connecting by order
module flop (d,clk,q);
…
endmodule
module mytop;
endmodule
Connecting by name
module myflop (d,clk,q);
…
endmodule
module mytop;
endmodule
net input
or reg net
output net
inout net or reg
net net
Basic Verilog
Intel Confidential
A Short Quiz #3
Write the Verilog code for the module “TOP”
TOP
A
A ALU
B ADD O_1
A
B
FLOP
A Q OUT
B
MUX O RES D
ACT A B
SUB O_2 SEL
SEL B CLK
CLK
Basic Verilog
Intel Confidential
Behavioral Modeling
Continuous Assignments
Block Statements (always/initial)
Blocking / Non-blocking Assignment
Delays, Intra delays
Basic Verilog
Intel Confidential
Continuous Assignments
To use for simple combinatorial logics that
drive nets.
Syntax:
– assign <wire_signal> = <expression>;
The value of the wire_signal is evaluated
each time that the value of one of the element
in the right side expression is changed.
Continuous
wire a, b, w; assignment
assign w = a & b;
Basic Verilog
Intel Confidential
Block Statements
Block Statements are used to group a
number of statements
Block statement begins with the keyword
begin and ends with the keyword end
Block statements might be named
Named block may use local signals
Syntax :
begin [: <block name>]
<Statements>*;
end
Basic Verilog
Intel Confidential
Block Statements
reg x,y;
always
begin : DJ_block Block’s name
parameter a = 1;
reg b;
b = a;
end // DJ_block
always
begin
parameter e = 1; Illegal to declare a
x = y; signal in an
end unnamed block
Basic Verilog
Intel Confidential
Syntax:
– Always [@ (<sensitivity_list>) ]
reg_signal = expression;
wire in1, in2;
reg out_a, out_b, out_c, out_d;
always @ (in1 or in2) Combinatorial
out_a = in1 | in2; Element
always @ (posedge clk)
out_b = out_a; Sequential
always begin Element
out_c = out_b;
out_d = ~ out_b; Always to be
end;
Basic Verilog evaluated
Intel Confidential
Initial Statements
All initial statements are executed only once in time
0 of the simulation
All the initial statements are executed concurrently
Inside the initial statement, statements are executed
sequentially
Syntax: initial <statement>;
wire in1, in2; Initial statements
reg out_a,out_b,out_c,out_d; aren’t
initial begin synthesizable
out_a = in1 | in2;
out_b = out_a;
end
initial
Basic Verilog
out_c = 1;
Intel Confidential
Blocking / Non-blocking
Assignment
Assignments can appear in always / initial
statements, functions and tasks. They can not
appear in the module’s global space.
Blocking assignments are executed in the order they
are specified (in a block). They are executed
sequentially
Non-blocking assignments are executed concurrently
Syntax:
– Blocking : operand = expression;
– Non-blocking : operand <= expression;
Basic Verilog
Intel Confidential
Blocking/Non-Blocking Assignments
reg b,c;
c
Blocking
reg b,c; b
Non-Blocking
Delays
Delays control the time between the change
in the right hand of the statement and when
the value is assigned to the left-hand.
Delays are not
synthesizable
Syntax:
– #<number> <statement>
wire w1;
w1, w2, and w3 act the
assign #10 w1 = in1 && in2;
same and get the value
wire #10 w2 = in1 && in2; of the expression after
wire #10 w3; delay of 10.
assign w3 = in1 && in2;
Basic Verilog
Intel Confidential
Delays in Blocks
The delay represents delta-time from the
previous event
reg a, b;
reg [1:0] c, d;
initial begin
a = 1’b1; // time = 0
#5 b = 1’b0; // time = 5
#10 c = {a,b}; // time = 15 (5+10)
#20 d = {b,a}; // time = 35 (15+20)
end
Basic Verilog
Intel Confidential
// reset generation
initial begin
rst_n = 1’b0; // active low
#100 rst_n = 1’b1;
end
// clock generation
initial clk = 1’b0;
always #20 clk = !clk; // 40 ns period clock
Basic Verilog
Intel Confidential
Intra-Assignment Delay
The expression on the right hand side is
evaluated immediately …
… but left hand side is updated after the
delay
Equivalent to buffer/line delay
Syntax: <reg> = #<number> <expression>
Basic Verilog
Intel Confidential
Statements
Basic Verilog
Intel Confidential
If Statement
If statements are used for making decision based
on certain conditions
If condition yields on ‘x’ then the “if” is not taken
Syntax:
– if (<condition expression>)
<statement>;
[else <statement>;]
– Needs “begin-end” if more than one statement
Use else statements instead of different “if”
statements if possible
Basic Verilog
Intel Confidential
If Statements Example
if (enable)
out = in;
If statement
if (a > b)
smaller = b;
else
smaller = a;
If-else statement
if (state == 0)
y = a + b;
else if (state == 1)
y = a – b;
else If-else-if statement
y = a * b;
Basic Verilog
Intel Confidential
Case Statement
The first alternative that matches the
expression is executed (‘x’ must match an ‘x’)
The case may have a default statement. If
none of the alternatives match, then this
statement is executed
Casez treats all z and ? values as don’t cares
Casex treats all z, x and ? values as don’t
cares
Basic Verilog
Intel Confidential
If Vs. Case
If you have a long sequential nested if-else
chain, a case might be more appropriate than
a nested if
– when there is no need for a priority on any of the
case options
Basic Verilog
Intel Confidential
For Statement
For loops are used for repeating logic.
Syntax:
– for ( <init>; <condition>; <addition>)
<statement>;
integer a;
Assigning zero for each
reg [7:0] arr [13:0];
address of the arr
for (a=0; a<14; a=a+1)
arr[a] = {8{1’b0}};
Basic Verilog
Intel Confidential
While Statement
Perform the statement as long that the
condition expression is true.
Syntax:
– while (<condition expression>)
<statement>; While statements
are not
integer a = 0; synthesizable
reg [7:0] arr [13:0];
while (a<14)
begin
arr[a] = {8{1’b0}}; Assigning zero for
a = a + 1;
end each address of the arr
Basic Verilog
Intel Confidential
Procedural Continuous
Assignment
Uses to perform an assignment in a
block (initial/always)
Useful to force a value to reg/net in
simulation
– assign/deassign
– force/release
“Force” overrides “assign”
Not synthesizable
Basic Verilog
Intel Confidential
assign/deassign statements
assign: Assigns value to a reg
deassign: retrieve original behavior
Syntax
– assign <regname> = <expression> ;
– deassign <regname> ;
reg out;
always @(ctrl)
begin
if (ctrl == 1)
assign out = 1’b1;
else
deassign out;
end Basic Verilog
Intel Confidential
force/release statements
force: Assigns value to a reg/net
release: retrieve original behavior
Syntax
– force <regname> = <expression> ;
– release <regname> ;
reg c;
initial
begin
# 100 force c = 1’b1;
# 100 release c;
end
Basic Verilog
Intel Confidential
Hardware Elements
Flip-Flop
Mux 2 to 1
Adder
Subtractor
Counter
4-bit Shift Register
Tri-state bus
Basic Verilog
Intel Confidential
Flip-Flop
with asynchronous reset
The asynchronous signals should be in the
sensitivity list with the proper edge expression.
reg data_out;
always @(posedge clk or negedge rst)
if (!rst)
data_out <= 1’b0;
else if (en)
data_out <= data_in; rst_1
data_in data_out
D R O
Non-blocking flop
en
assignments are E
used
Basic Verilog clk
Intel Confidential
Mux 2 to 1
using reg
reg [5:0] data_out;
Blocking
always @(sel or data_in1 or data_in2)
if (sel) assignments are
data_out[5:0] = data_in1[5:0]; used
else
data_out[5:0] = data_in2[5:0];
data_in1[5:0] 6
1
data_out[5:0] 6
data_in2[5:0] 6 0
sel
Basic Verilog
Intel Confidential
Mux 2 to 1
using net
wire [5:0] data_out;
data_in1[5:0] 6
1
data_out[5:0] 6
data_in2[5:0] 6 0
sel
Basic Verilog
Intel Confidential
Adder
reg [8:0] sum;
always @(in1[7:0] or in2[7:0])
sum[8:0] = {1’b0,in1[7:0]} + {1’b0,in2[7:0]};
in1[7:0] 8
sum[8:0] 9
+
in2[7:0] 8
(a+b)+(c+d)
(a+(b+(c+d)))
+
Use () wisely
+
+
+
+
+
Basic Verilog
Intel Confidential
Substractor
reg [7:0] sub;
always @(in1[7:0] or in2[7:0])
sub[7:0] = in1[7:0] - in2[7:0];
in1[7:0] 8
sub[7:0] 8
-
in2[7:0] 8
Basic Verilog
Intel Confidential
Counter
reg [3:0] count;
Synchronous reset
always @(posedge clk)
(not present in
if (reset)
sensitivity list)
count[3:0] <= 4’b0;
else if (en)
count[3:0] <= count[3:0] + 1;
count[3:0] 4 count[3:0]
+1 D O
en 4 flops
reset ER
clk
Basic Verilog
Intel Confidential
rst
data_in data_out
D R O
shift shift_reg
E
Tri-State Bus
wire bus[3:0];
assign bus[3:0] = en1 ? {in1[1:0],in2[1:0]} : 4’bzzzz;
assign bus[3:0] = en2 ? 4’b0000 : {4{1’bz}};
assign bus[3:0] = en3 ? in3[3:0] : 4’bzzzz;
in1[1:0] in2[1:0]
en1
bus[3:0]
4
en2 en3
4 Basic Verilog
4 in3[3:0]
4’h0
Intel Confidential
Compiler Directives
define, include, undef, ifdef, else, endif …
The `undef \ `define is used to un\define text macros.
» Syntax: `define <macro_name>[(<arguments>)] <macro_example>
» `undef <macro_name>
– Usage: `<macro_name>[(arguments)]
The `ifdef `ifndef `else `elsif `endif are used to control which
parts of text will be compiled
» Syntax: `ifdef <macro_name>
» …
» `else
» …
» `endif
The `include is used to include a content of a Verilog source
file.
» Syntax: `include “<Verilog file>”
In Verilog 2001 two new directives : ifndef, elsif
Be aware : use left ‘
Basic Verilog
Intel Confidential
System Tasks/functions
System tasks are used for certain
routine procedures.
Syntax:
– $<system task name (keyword)>
Some examples are added
– More information can be Most system
tasks are not
found in the Verilog HDL synthesizable
Language Reference Manual.
Basic Verilog
Intel Confidential
Basic Verilog
Intel Confidential
Basic Verilog
Intel Confidential
Simulation Control
System Tasks
$stop – is provided to stop the
simulation
– Usage: $stop;
$finish – is provided to terminate the
simulation
– Usage: $finish;
Basic Verilog
Intel Confidential
[Link] :
// my wonderful file !
01 // nice number
a5
fe
34 Basic Verilog
Intel Confidential
Basic Verilog
Intel Confidential
Basic Verilog
Intel Confidential
Basic Verilog
Intel Confidential
Mealy
Outputs depends on state and inputs
Synchronous
always
FFs
Basic Verilog
Intel Confidential
Mealy Implementation
module meally(clk, rst, in, out)
…
State encoding
reg [1:0] cur_st, nxt_st;
parameter [1:0] ST_IDLE=2’d0, ST_GO=2’d1 …
always @(cur_st or in)
nxt_st = ST_IDLE; // default Next State “case”
case (cur_st) (comb.)
ST_IDLE : if (in) nxt_st = ST_GO;
…
always @(posedge clk or negedge rst) Current state (sync)
if (!rst) cur_st <= ST_IDLE;
else cur_st <= nxt_st;
always @(cur_st or in) Output “case”
out = 1’b0; // default (comb.)
case (cur_st)
ST_IDLE : if (in) out = 1’b1;
…
endmodule Basic Verilog
Intel Confidential
Moore
Outputs depends on state only
Mid real estate
Short comb. path
Inputs Combinatorical
always
Synchronous
always Logic Outputs
FFs
Basic Verilog
Intel Confidential
Moore Implementation
module moore(clk, rst, in, out)
…
State encoding
reg [1:0] cur_st, nxt_st;
parameter [1:0] ST_IDLE=2’d0, ST_GO=2’d1 …
always @(cur_st or in)
nxt_st = ST_IDLE; // default Next State “case”
case (cur_st) (comb.)
ST_IDLE : if (in) nxt_st = ST_GO;
…
always @(posedge clk or negedge rst) Current state (sync)
if (!rst) cur_st <= ST_IDLE;
else cur_st <= nxt_st;
always @(cur_st) Output “case”
out = 1’b0; // default (comb.)
case (cur_st)
ST_IDLE : out = 1’b1;
…
endmodule Basic Verilog
Intel Confidential
One Hot
Outputs depends on state only
Single flop per state : always a single
flop is ‘1’ (hot), others ‘0’ (cold)
Mid real estate
Very Short comb. path (OR gates) Very fast
Basic Verilog
Intel Confidential
Synchronous Mealy
"Mealy" means that outputs is
determined by the current state and
the inputs
"Synchronous" means that all of the
outputs of the FSM have a FF stage
OUTPUTS
Basic Verilog
Intel Confidential
Simulation Flow
Build a testbench (TB) with the unit instance
TB
unit
Testbench
Generate a “stimulus” to the unit inputs
Checks unit outputs
Controls simulation flow
May use all the language constructs
– Timing control, System tasks etc.
Special functional verification unit (e.g.
Specman) may be used for complex
designs simulation
Basic Verilog
Intel Confidential
Basic Verilog
Intel Confidential
Timescale Directive
`timescale 1 us / 10 ns;
5 time units will be 5 us.
`timescale 1 ps / 1 ps;
5 time units will be 5 ps.
Basic Verilog
Intel Confidential
Basic Verilog
Intel Confidential
Hands On
[Link]
Modelsim Documentation:
[Link]
Basic Verilog
Intel Confidential
Basic Verilog
Intel Confidential
Basic Verilog
Intel Confidential
Basic Verilog
Intel Confidential
wire OUT;
wire RES;
ALU myALU(.A(A),.B(B),.SEL(ACT),.RES(RES));
FLOP myflop (.D(RES), .OUT(OUT), .CLK(CLK));
endmodule;
Basic Verilog