VerilogModels0
VerilogModels0
Introduction
Increasing complexities of contemporary systems
Demand the use of increasingly powerful tools
Pencil and paper methods
No longer reasonable in large sense
Major focus in ensuing discussions will be on hardware side of the development cycle
None-the-less software plays major role in development of todays embedded
systems
Will use Verilog HDL as major tool in developing then synthesizing hardware models
Should be quite familiar with basic Verilog and structure of Verilog program
Over next several lessons will take study of language and modeling to next level
Will begin with review of purpose of Verilog
Introduce embedded development cycle
Examine some good design and coding practices
Examine how to utilize different modeling levels
Incorporate real-world effects into Verilog models
Then identify some Verilog constructs that cannot be synthesized into hardware
How to model real-world effects
Important considerations
9 End goal of Verilog program
A solid robust reliable system
9 Verilog is a hardware design language not a software programming language
- 1 of 63 -
9 Many of tools and techniques appropriate to good software development
Also appropriate to developing good Verilog designs
9 Modeling design using Verilog is intermediate step
9 End goal of Verilog program is synthesis into hardware
Traditional Hardware Design Traditional Hardware Design HDL Based Hardware Design
User Inputs
Traditional approach
9 Identify requirements and formulate specification Requirements
Analysis
Functional Functional
Hardware
Architecture
At gate level Hardware
Architecture
Specification
Behavioural Model
Specification
Draw logic diagram or schematic Hardware Design
In design process
Model precedes actual design
Provides opportunity to quickly explore variety of alternative approaches
Cheaply
Quickly
- 3 of 63 -
We know that embedded systems are
Reactive
System runs continuously
Responds or reacts to signals from external environment
Often real-time
Time constraints imposed on behaviour
Heterogeneous
Composed of hardware and software pieces
Hardware can be PLD, ASIC, custom IC, microprocessor, combination
Supported by different development environments
We need to distinguish
9 Model
9 Language used to express the model
Can very easily develop models using
C, C++, Java
Matlab, PSPICE
Etc.
9 Final hardware implementation
To be useful
We can hypothesize some essential general capabilities
Abstraction
Must allow us to express and examine behaviour
Of complete system
Unburdened by details of sub-components
Refinement
Must allow us to express and decompose behaviour of system
At different levels of granularity
Structure
Must be able to express system as set of interconnected modules
Communication
- 4 of 63 -
Must support inter module communication method
Should support synchronization method
Easy to interpret
Must express anticipated behaviour or aspect being modeled
In comprehensible format
Conceptual
Precedes analytic
Allow us to work at high level of abstraction
Uses a symbolic means
To capture qualitative aspects of problem
Analytic
Permits analysis at lower levels of detail
Use mathematical or logical relations
Express quantitative physical behaviour
- 5 of 63 -
Important Characteristics of Models
To be effective
Models should give us ability to express
1. Modularity and hierarchy
Should be able to express
Static and dynamic behaviour
Structural and functional construction
2. Relationships among subsystems
Should be able to express
Sequential and concurrent flow of control
Inter subsystem synchronization and communication
Temporal behaviour
3. Communication amongst tools
4. Use of legacy designs or behaviours
5. Affects of real-world physics on circuit and signal behaviour
6. Ideally models should be executable
Will use Verilog HDL as major tool in developing then synthesizing hardware models
Should be quite familiar with basic Verilog and structure of Verilog program
What is Verilog?
Verilog is a hardware description language - HDL
Provides a means of specifying a digital system
At a wide range of levels of abstraction
Language supports
Early conceptual stages of design
With its behavioral level of abstraction
Later implementation stages
Data and control flow with dataflow level of abstraction
Detailed device level model
With its structural level of abstraction
- 6 of 63 -
Language provides hierarchical constructs
Allows the designer to control the complexity of a description
- 7 of 63 -
Looking at two components of development process
Objectives of Verilog HDL modeling
Capture and verify behaviour of design prior to committing to physical hardware
Process entails
9 Mapping the system requirements into design that meets those
requirements
Sentence makes very strong and important statement
9 Understanding real-world physical constraints and limitations of
Modeled parts and environment
9 Incorporating effects of identified constraints and limitations into model
Includes variations on such constraints and limitations
9 Verifying that modeled design meets or exceeds specified requirements
Subject to real-world physical constraints and limitations
- 8 of 63 -
Working with the Verilog HDL HDL Based Design
We will
Begin with some useful information on
Several different Verilog data types
Follow with quick review of
Basic components and organization of a Verilog program
Review gate-level or structural modeling
Combinational logic circuits
Sequential circuits
Introduce dataflow and behavioral models
Examine some important tools and capabilities of language
Facilitate fine grained modeling and test of a design
- 9 of 63 -
Variable
Verilog variable like a variable in C, C++, or Java
Can be assigned a value
Will hold that value until a subsequent assignment replaces the value
Net
Net represents a class of primitive data types
Used to model a node or electrical connection in a circuit
Cannot
Be assigned to
Hold a value
Value results from being continuously driven by output of a logical device
If a net is not driven
Takes on the default value of z
Meaning high impedance or floating.
Wire
A wire type is a kind of net
Like real world wires are used to
Connect output of one logic element to
Input(s) of other logical elements
Because it is a net
Value of a wire can only be changed
As result of a gate or a behavioral statement driving it
Reg
A reg is a kind of variable
Value of a reg or register
Can be changed directly by an assignment
One should not confuse the Verilog reg with the hardware register
The reg is simply an entity that can hold a value
Default value of a reg data type is x, or unknown
The syntax for the reg and wire declarations is given as
Syntax
reg regList;
wire wireList;
- 10 of 63 -
Declaring Multi-Bit Signals
Often necessary to represent multi-bit wires
Formally such sets called vectors
A 3-bit wire that can carry digital signals representing the values 0..7
Called a 3 bit vector
Types reg and wire can also be formed into a bus such as
Syntax
Big Endian
reg [msb:lsb] reg_list
wire [msb:lsb] wire_list;
Little Endian
reg [lsb:msb] reg_list
wire [lsb:msb] wire_list;
Statement
ANDs together C and the LSB of myWires
Puts the result in the MSB of myWires.
- 11 of 63 -
Note again
We are not assigning conjunction to myWires[2]
The gate a1 is driving that signal
Only way myWires[2] can change
If output of gate changes because input changed
One can also use the same form to take a subset of a multi-bit wire
Pass it as an input to another module
wire[31:0] myWires;
output myWires[3:1];
- 12 of 63 -
Numbers
Verilog supports two types of number specification
Sized
Unsized
Sized Numbers
Sized numbers declaration comprises
Size, base, value
Syntax
size base value
size specifies number of bits in number
base identifies the base
legal bases: d or D decimal
o or O octal
h or H - hexadecimal
value numeric value in specified base
Examples
4b1010 // a 4 bit binary number
8d35 // an 8 bit (2 digit) decimal number
16hface // a 16 bit (4 digit) hex number
Unsized Numbers
Unsized numbers
Without a base specification
Decimal by default
Examples
1010 // a 32 bit decimal number by default
o35 // a 32 bit octal number
hface // a 32 bit hex number
- 13 of 63 -
Unknown or High Impedance Values
Verilog supports numeric specification
For numbers with unknown or high impedance bits/digits
Symbols used for specification
x unknown value
z high impedance value
Examples
4b101x // a bit binary number with lsb unknown
8dz5 // an 8 bit (2 digit) decimal number
// with high impedance ms digit
16hfzxe // a 16 bit (4 digit) hex number with high impedance and
// unknown digits
The Verilog Models
Will now examine models and modeling tools
At each of the levels
Three Models The Gate-Level, the Dataflow, and the Behavioral
Verilog language supports the development of models
At three different primary levels of abstraction
Gate level model
Gives most detailed expression
Behavioral level
Gives most abstract
Gate level
Modules are implemented by interconnecting the various logic gates
Similar to working with SSI and MSI components
Also known as a structural model
Dataflow level
Module is implemented by specifying the movement of the data
Amongst the comprising hardware registers
Model is analogous to the RTL (Register Transfer Level) level
Used in specifying a microprocessor / computer architecture
Behavioral level
Modeling is based upon an algorithmic description of the problem
Without regard for the underlying hardware.
Language does support modeling at the transistor level
- 14 of 63 -
Work at that level will not be discussed here
Model Development
Will begin at the gate level and work up
Path will be to use the three different levels
To introduce the core aspects of the language
Because working at the gate level is the most familiar
Will begin / review at that level then move up to higher levels of abstraction
As we do so we will also introduce several aspects of the language
Apply to all levels of abstraction
Will utilize the same combinational and sequential designs
To illustrate how a model is developed at each of the different levels
Combinational circuits
Will use an AND and an OR gate
Extended to implement a NAND and a NOR circuit
Sequential circuits
Will progress from
Basic latch
Gated latch
Flip-flop
Two bit binary counter
- 15 of 63 -
buf <name> (OUT1, IN1); // Sets output equal to input
not <name> (OUT1, IN1); // Sets output to opposite of input
and <name> (OUT, IN1, IN2); // Sets output to AND of inputs
or <name> (OUT, IN1, IN2); // Sets output to OR of inputs
nand <name> (OUT, IN1, IN2); // Sets to NAND of inputs
nor <name> (OUT, IN1, IN2); // Sets output to NOR of inputs
xor <name> (OUT, IN1, IN2); // Sets output to XOR of inputs
xnor <name> (OUT, IN1, IN2); // Sets to XNOR of inputs
bufif1<name> (out, in, cntrl) // Sets output to input if ctrl is 1 tristate otherwise
bufif0<name> (out, in, cntrl) // Sets output to not input if ctrl is 1 tristate otherwise
notif1<name> (out, in, cntrl) // Sets output to input if ctrl is 0 tristate otherwise
notif0<name> (out, in, cntrl) // Sets output to not input if ctrl is 0 tristate otherwise
Example
A five-input and gate is declared as
and <name> (OUT, IN1, IN2, IN3, IN4, IN5); // 5-input AND
Creating Combinational Logic Modules
At the gate level
Verilog module really is a collection of logic gates
Each time we declare and define a module
We are creating that set of gates
Indicates
Start of module
Name of the module
AndOr
List of signals connected to that module
Subsequent lines
Declare
First two binary values generated by module are outputs
Next two (A, B) are inputs to the module
- 17 of 63 -
and myAnd (AandB, A, B);
or myOr (AorB, A, B);
- 18 of 63 -
// Compute the logical AND and OR of inputs A and B.
module AndOr(AandB, AorB, A, B);
output AandB, AorB;
input A, B;
and myAnd (AandB, A, B);
or myOr (AorB, A, B);
endmodule
- 19 of 63 -
The Real-World Affects Part 1
Lets take a first look at incorporating real-world affects
Into HDL models
Device Delays
Basic syntax is given as
Syntax
#delay device;
The line
and #5 myAnd (AandB, A, B);
- 20 of 63 -
Units of time can be whatever we want
As long as we use consistent values
Net Delays
The delay operator
Can also be applied to a net
When delay specified on a net
Any state change on input to net
Delayed accordingly
Syntax follows that of device delay
Syntax
#delay wire;
parameter propagationDelay = 2;
not #propagationDelay myNot (sigOut, sigIn);
- 21 of 63 -
// Compute the logical AND and OR of inputs A and B.
module AndOr(AandB, AorB, A, B);
output AandB, AorB;
input A, B;
parameter delay0 = 5;
parameter delay1 = 10;
parameter riseTime = 3;
parameter fallTime = 4;
- 22 of 63 -
SR Latch with Enable
Basic design can be extended to include
Enable as an additional level of control
endmodule
endmodule
- 23 of 63 -
Binary Counter
Can use the SR flip-flop to build
Simple two-bit synchronous binary up counter
endmodule
- 24 of 63 -
Developing at a higher level
Not without problems
Farther that one moves
From the low level details and
Increases reliance on tools
To produce those details
The greater the risk that the tools
Will produce less than optimum design
Dataflow Modeling
Views a design from the perspective of
Data moving through the system
From source to destination
In the digital world
Such a view often referred to as RTL or register transfer level design
Contemporary tools able to accept a dataflow model as input
Produce a low-level logic gate implementation
Through a process called logic synthesis
Operators
Syntax and operators used in Verilog at the dataflow level
Follow that of the C language very closely
Table below gives the most commonly used operators
- 25 of 63 -
Operator Symbol Operation
Arithmetic + Add
- Subtract
/ Divide
* Multiply
% Modulus
Equality == Equal
!= Not Equal
Continuous Assignment
At the dataflow level
Design is modeled as movement of data
From module to module
To affect the application
That data moves over a net
Thus, a fundamental element of such modeling
Is ability to drive a value
From a source module
Onto the interconnecting net
To the destination modules
In Verilog such ability
Expressed by continuous assignment
- 26 of 63 -
Continuous assignment statement
Specified using the following syntax
Syntax
assign destination net = source net expression
- 27 of 63 -
The model for the AndOr circuit designed earlier
Can include delays as seen in the following code fragment
// continuous assignment
module AndOr(AandB, AorB, A, B);
output AandB, AorB;
input A, B;
endmodule
Syntax
assign # (rise time, fall time, delay) net
- 28 of 63 -
// Compute the logical AND and OR of inputs A and B.
module AndOr(AandB, AorB, A, B);
output AandB, AorB;
input A, B;
endmodule
Sequential Logic
// Dataflow Level Model
Following three code modules // Gated SR Latch
Evolve the dataflow implementations of module gsrLatch(q, qnot, sg, rg, clr, enab);
input sg, rg, clr, enab;
Gated SR latch output q, qnot;
Master-slave SR flip-flop wire rL, sL;
wire q, qnot;
Two bit binary counter designed earlier
// Build the gating logic
endmodule
- 29 of 63 -
// Use two SR Latches in // Build a synchronous two bit binary up counter
// a master slave configuration to build a flip-flop // using master slave SR flip-flops
module srmsff(q, qnot, s, r, clk, clr); module TwoBitCntr(qA, qB, clr, clk);
input s, r, clk, clr; input clr, clk;
output q, qnot; output qA, qB;
endmodule
Program Structure
At the behavioral level
One of the major differences between languages such as C or C++ becomes clear.
Unlike either C or C++in which flow of control is generally sequential
Flow of control in Verilog is concurrent
Statements in C or C++ execute in series
Those in Verilog execute in parallel
- 30 of 63 -
Each such block
Express a separate flow of control
Each will finish execution independent of any other block
Module may define multiple initial and/or always blocks
Such blocks cannot be nested
Syntax
initial
begin
Initial statements
end
Syntax
always
begin
Statements to be always executed
end
- 31 of 63 -
Operators
Like dataflow model
Syntax and operators used in Verilog at the behavioural level
Follow that of the C language very closely
Table below several additional operators
Condition ?: If else
Reduction
Reduction operators
Operate on all bits of single operand
Product 1 bit result
If any bit in operand is z or x
Result is x
Reduction AND
If any bit in operand is 0 result is 0 else result is 1
Reduction NAND
Inverse of reduction AND
Reduction OR
If any bit in operand is 1 result is 1 else result is 0
Reduction NOR
Inverse of reduction OR
Reduction XOR
If even number of 1s in operand result is 0 else result is 1
Reduction XNOR
Inverse of reduction XOR
- 32 of 63 -
Condition
Condition operator
Similar to triple operator in C
Concatenation
Concatenation is operation of joining bits
From smaller expressions to form larger one
Replication
Creates expression by replicating and concatenating
Target expression
Specified number of times
abus = {8,{dbus[7],dbus};
Procedural Assignment
Assignment in the behavioral model differs from
That in either the gate level or dataflow model
In the behavioral model procedural assignment statements
Used to update the circuit state variables
- 33 of 63 -
In the dataflow model
Continuous assignment construct
Continually updates the value on the net on left hand side
In the behavioral model
Value is only updated
As result of the execution of a procedural assignment statement
Verilog supports
Two kinds of procedural assignment
Blocking and non-blocking
Two kinds of blocks
Sequential and parallel
Statements in a sequential block
Delimited by a begin and an end
Executed in sequence
Statements in a parallel block
Delimited by a fork and a join
Executed in parallel
- 34 of 63 -
Syntax for the two types of assignment is given in the following
Syntax
Blocking
aVariable = aValue;
Nonblocking
aVariable <= aValue;
Syntax
Blocking
aVariable = #d aValue;
#d aVariable = aValue
Nonblocking
aVariable <= #d aValue;
#d aVariable <= aValue
Blocking
The first statement says
Evaluate aValue then block for d time units
Before assigning aValue to aVariable
Any subsequent use of aVariable will get the new value
The second statement says
Block for d time units
Before evaluating aVariable = aValue
The variable aVariable will have the value aValue
d time units in future
Non-blocking
The first statement says
Evaluate aValue
Schedule aVariable to be updated d time units later
However continue processing other statements
Any other variables using the value of aVariable
Within the next d time units will be assigned the old value
The second statement says
- 35 of 63 -
Wait d time units before evaluating aVariable = aValue
Variable aVariable will have the value aValue
d time units in future
time, a, b, c, d, e, f, g, h, i, j, k, l
0 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
10 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0
12 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0
16 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0
18 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0
20 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0
26 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0
28 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0
32 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
- 36 of 63 -
Non-blocking statements are evaluated.
Variable d is assigned the value 1 10 time units
After the blocking statements in the first initial block
Expression j<=1 is evaluated 10 time units
After the blocking statements in the second initial block
Variables e and f are evaluated 2 and 4 time units respectively
After the blocking statements in the first initial block
Finally expressions k<=1 and l <= 1 are evaluated 2 and 4 time units
After the blocking statements in the second initial block
- 37 of 63 -
Major differences between the two implementations
Reflected in the evaluation times for the variables d, e, f, g, h, and i
Combinational Logic
The next example implements the earlier NandNor combinational logic circuit
Using a behavioral model
Utilizing both the blocking and non-blocking assignments
Right and left hand side delays
module blocking_nonblocking();
reg a,b, AandB,AorB, AnandB,AnorB;
reg e,f, EandF,EorF, EnandF,EnorF;
initial
begin
// Blocking Assignment
a = 1; b = 1;
initial
begin
$display("\t time\t a, \tb, \tAnandB, \tAnorB, \t\te, \tf, \tEnandF, \tEnorF");
$monitor($time, "\t%b \t%b \t%b \t\t%b \t\t%b \t %b \t %b \t\t%b", a,b, AnandB, AnorB, e, f, EnandF, EnorF);
#50 $finish(1);
end
endmodule
The outputs of the circuits for each of the cases are given
- 38 of 63 -
Based upon the order of evaluation of the non-blocking assignment
NAND operand is never assigned a valid value
Syntax
Regular Event
@(signal) action
variable = @( signal) action
signal may be clock, posedge clock, negedge clock for example
Named Event
event anEvent // event is a keyword
always @(anEvent) action
OR Event
always @( signal1 or signal2 or signal3 or) action
Level
always wait( signal) action // wait is a keyword
- 39 of 63 -
Branches
Like the C and C++ languages
Verilog utilizes the if and if else constructs
Select alternate paths of execution
Based upon the value of a condition variable
Permitted combinations follow the C and C++ syntax
Syntax
if (condition)
statement;
If (condition)
statement1;
else
statement2;
If (condition1)
statement1;
else If (condition2)
statement2;
else
statement 3;
Case Statement
The switch or case statement in Verilog
Uses the Pascal rather than the C language syntax
Unlike the C switch
Once a statement or block of statements is evaluated
Flow of control leaves the case
Rather than continuing through the remaining alternatives
Syntax
case (expression)
label0: statement0;
label1: statement1;
.
.
labeln-1: statementn-1;
default: defaultStatement;
endcase
- 40 of 63 -
Verilog supports two variants on basic case or switch statement
Syntax
casez treats all z values in case labels or expressions as dont cares
casex treats all x and z values in case labels or expressions as dont cares
Loops
Verilog language supports the four common loop constructs.
while
repeat
for
forever
First three should be familiar
From the C or C++ languages
Forever is unique to Verilog
Syntax for each is given as
Syntax
while(test)
begin
loop body
end
repeat(repeatcount)
begin
loop body
end
forever
begin
loop body
end
- 41 of 63 -
Sequential Logic
As noted earlier behavioural model
Builds design algorithmically
The following three code modules evolve the behavioural implementations of
Gated SR latch
Master-slave SR flip-flop
Two bit binary counter
module gsrLatch(q, qnot, s, r, clr, enab); module TwoBitCntr(qA, qB, clr, clk);
input s, r, enab, clr; input clr, clk;
output q, qnot; output qA, qB;
- 42 of 63 -
Rather than working with individual flip-flops
As noted earlier
Design is approached algorithmically
reg[1:0] state;
else case(state)
state0:
state = state1;
state1:
state = state2;
state2:
state = state3;
state3:
state = state0;
endcase
end
endmodule
At this point
- 43 of 63 -
Will review general structure for
Test bench
Tester
We will illustrate the verification phase
Using the NandNor circuit
To do this we create a test bench
Stimulus Measurement
UUT
- 44 of 63 -
main() function
In C or C++ and t
Top level class
In Java
Acts as the outermost container in the program
Lets look at the pieces
The Unit Under Test
The unit under test or UUT
Is system, subsystem, module
That we are testing
This is our design
We will use the gate level NandNor circuit as the UUT
To be tested and verified
- 45 of 63 -
Later stages verifying
It performs according to specification
Normal operation
Boundary operation
Inside, at, and outside boundaries
Each path through the logic circuit is functional
Timing
All high and low-level timing constraints met
Time
Verilog simulations executed with respect to simulation time
Value stored in special register data type
Time variable declared using keyword time data type
Value of time variable can be retrieved
Using system function $time
// declare variable to hold current time
time simTime;
initial
begin
simTime = $time;
end
Displaying Information
Given purpose of developing Verilog program
Model a design
To confirm that it conforms to specification
During test of module under design and when test complete
Want to be able to
Annotate results
Observe values of
Input and output signals
Intermediate and final values of internal variables
- 46 of 63 -
$display and $monitor statements
The $display and $monitor are standard system tasks
Enable one to see the states of certain signals in text form
Output is typically directed to the screen (or window)
Difference between the two statements is
$display
Only evaluated when the directive is encountered during execution
$monitor
Evaluated every time any of the signals being monitored changes state
Syntax for the two directives is given as
Syntax
$display (["formatrString"], variableList);
$monitor (["formatString"], variableList);
The formatString
Optional for both statements
Both follow the C printf
Is a text string containing format variables that are to be instantiated
From the values specified in variableList
More commonly used format variables given in following table.
%b Binary
%d Decimal
%o Octal
%h Hexadecimal
%c Character
By convention
Logic high is denoted as a 1
Logic low is denoted as a 0
Unknown state is denoted as an x
- 47 of 63 -
Stopping and Finishing
There are several system tasks
Can be used to terminate or temporarily suspend a simulation
These are the
$stop and $finish statements
As names suggest
Used to either stop or finish a simulation
$stop directs the simulation to the interactive mode
Used when the designer wishes to suspend the simulation prior to exit
To examine the state of signal values.
$finish terminates the simulation.
The syntax for the two directives is given as
Syntax
$stop;
$finish;
Time
Verilog simulations executed with respect to simulation time
Uses built in variable
Value stored in special register data type
Syntax
$time
Syntax
$display ($time, ["formatString"], variableList);
$monitor ($time, ["formatString"], variableList);
Sequence
Important to distinguish
Sequence and $time
Consider following code fragment
module SimTime0;
integer a,b;
initial
begin
a = 1;
$display("a is %d", a, $time);
end
initial
begin
b = 2;
$display("b is %d", b, $time);
end
endmodule
- 49 of 63 -
Time Control - #
We used # symbol when modeling prop delay through part
Can also utilize to control when statements executed
Modifying above example
module SimTime1;
initial
begin
sysClk = 0;
i = 0;
end
always
begin
#delay sysClk = ~sysClk;
i = i + 1;
end
// blocking assignment
initial
begin
a = @(posedge sysClk) i+1;
$display("a is %d at $time = %d", a, $time);
#(40*sysClk)
$stop;
$finish;
end
endmodule
Test Module
Lets now move on to the tester or test module
This is most critical element in test process
- 51 of 63 -
A set of inputs and a set of outputs
Inputs to the test module
Will be the outputs of the UUT
Will model the measurement equipment
Outputs from the test module
Will be the inputs of the UUT
These will model the stimulus equipment
Set of test vectors
These will be outputs of test module
Will be
Individual vectors
Sets of vectors
Provide known signals or patterns into UUT
Set of known responses
Will be outputs of UUT
Known responses to applied stimuli
- 52 of 63 -
module Tester (X, Y, XnandYin, XnorYin);
input XnandYin, XnorYin;
output X, Y;
reg X, Y;
parameter stimDelay = 10;
initial // Stimulus
begin
X = 1; Y = 1;
#stimDelay X = 0;
#stimDelay Y = 0;
#stimDelay X = 1;
end
initial
begin // Response
display("\t Time, \t \tX, \t Y, \t XnandYin, \t XnorYin");
monitor($time, "\t \t %b, \t %b, \t %b, \t \t%b", X, Y, XnandYin, XnorYin);
end
endmodule
- 53 of 63 -
Following reg declaration
Parameter stimDelay specifies
Delay between the applications of successive test vectors
Initial block declared next
Initial blocks start executing sequentially at simulation time 0
Starting with the first line between begin end pair
Each line executes from top to bottom
Until a delay is reached
When / if a delay is reached
Execution of this block waits
Until the delay time has passed and then picks up execution again.
Each initial and always block executes concurrently
So if a block is stalled
Other blocks in the design would execute
If always block included
An always block does not continuously execute
Instead only executes on change in items in the sensitivity list
For example posedge clock or negedge reset
Recall events discussed earlier
Means when there is a
low to high on the clock signal or
high to low on reset
always block will execute.
$display is used to print to a line and enter a carriage return at the end
Variables can also be added to the display
Format for the variables can be
Binary using %b
Hex using %h
Decimal using %d
Another common element used in $display is $time
which prints the current simulation time
- 55 of 63 -
// Test module for two bit binary up counter
module tester(clr, clk, qA, qB);
input qA, qB;
output clr, clk;
initial
begin
clk = 0;
clr = 0;
#stimDelay clr = ~clr;
repeat(16)
begin
#clkDelay clk = ~clk;
end
end
initial
begin
$display("\tTime, \t\tqA, \tqB, \tclr, \tclk");
$monitor($time,"\t\t%b, \t%b, \t%b, \t%b", qA, qB, clr, clk);
end
endmodule
initial
begin
clk = 0;
clr = 0;
#stimDelay clr = ~clr;
always
#halfPeriod clk = ~clk;
end
- 56 of 63 -
The Test Bench
Now bring everything together with test bench
In the test bench we instantiate
One copy of the UUT
Here will be NandNor gate,
- 58 of 63 -
Naming Conventions and Styles
Several common formats for writing identifier name
addressBuss
address-buss
address_buss
- 59 of 63 -
Comments
Two forms of comment
// single line comment
Can appear as starting character on each line of block of commented text
/* */ multiple line comment
Can be used to mark single line comment
Comments should be
Meaningful informative suggestive of their intended purpose
Dont state the obvious
Vertically align left hand sides of all comments
Example
Bad
parameter halfPeriod = 100; // set halfPeriod to 100
Good
parameter halfPeriod = 100; // set halfPeriod to minimum legal value
Bad
parameter fullPeriod = 200; // set fullPeriod maximum legal value
parameter halfPeriod = 100; // set halfPeriod to minimum legal value
Good
parameter fullPeriod = 200; // set fullPeriod maximum legal value
parameter halfPeriod = 100; // set halfPeriod to minimum legal value
- 60 of 63 -
Declarations, Definitions, and Modules.
Constants
Declare all parameter constants at the top of the module written in all upper case
letters.
Example
parameter HALFPERIOD = 100;
Modules
The first module should be the test bench or the top-level module
Followed by the remaining modules
//-----------------------------------------------------------
// File name:
// MyFile
//
// Description:
// Implements high-speed SerialIO system.
// Provides coms link between data collection system and
// remote peripheral devices.
// Data stream sent with Manchester Phase Encoded
Clock
//
// Author:
// Iman Engineer
//
//
- 61 of 63 -
Block Comments at the Start of modules
//-----------------------------------------------------------
// Module name:
// MyModule
//
// Description:
// Module implemented as part of high-speed SerialIO system.
// Counts number of characters transmitted
// Computes running parity
// Transmits parity and EOM
//
// Author:
// Youran Engineer
//
//-----------------------------------------------------------
Block Statements
Coding convention for all block statements shall be either of the following:
end
else begin
statement3;
statement4;
end
end
or
- 62 of 63 -
Note:
Indentation of statements
Relative to "if" and "else" for each if-else statement
if( expression )
begin
statement1;
statement2;
if( expression )
begin
statement1a;
statement 2a;
end
end
else
begin
statement3;
statement4;
end
- 63 of 63 -