Digital System Design Verilog: System Tasks and...

21
Digital System Design Verilog: System Tasks and Testbench Dr. Bassam Jamil

Transcript of Digital System Design Verilog: System Tasks and...

Page 1: Digital System Design Verilog: System Tasks and …jufiles.com/wp-content/uploads/2016/12/Verilog-Basics-6-System... · Digital System Design Verilog: System Tasks and Testbench Dr.

Digital System Design

Verilog:System Tasks and Testbench

Dr. Bassam Jamil

Page 2: Digital System Design Verilog: System Tasks and …jufiles.com/wp-content/uploads/2016/12/Verilog-Basics-6-System... · Digital System Design Verilog: System Tasks and Testbench Dr.

222

Topics

System Tasks and Functions

Testbench Testing and Simulation commands

Page 3: Digital System Design Verilog: System Tasks and …jufiles.com/wp-content/uploads/2016/12/Verilog-Basics-6-System... · Digital System Design Verilog: System Tasks and Testbench Dr.

3

System Tasks and Functions

System Task and Functions start with $

Common tasks and functions Display the value of variables File I/O Simulation control : Stop (i.e. suspend) , finish (i.e.

exit) simulation

Page 4: Digital System Design Verilog: System Tasks and …jufiles.com/wp-content/uploads/2016/12/Verilog-Basics-6-System... · Digital System Design Verilog: System Tasks and Testbench Dr.

4

Display the value of variables

$monitor ("text_with_format_specifiers", signal, signal, ... ); Continuously monitors the signals listed, and prints the

formatted message whenever one of the signals changes. A newline is automatically added to the text printed.

$display ("text_with_format_specifiers", signal, signal, ... ); Prints the formatted message once when the statement is

executed during simulation. A newline is automatically added to the text printed.

Page 5: Digital System Design Verilog: System Tasks and …jufiles.com/wp-content/uploads/2016/12/Verilog-Basics-6-System... · Digital System Design Verilog: System Tasks and Testbench Dr.

5

$display Example

Output of $display task

Page 6: Digital System Design Verilog: System Tasks and …jufiles.com/wp-content/uploads/2016/12/Verilog-Basics-6-System... · Digital System Design Verilog: System Tasks and Testbench Dr.

6

More $display Examples

Page 7: Digital System Design Verilog: System Tasks and …jufiles.com/wp-content/uploads/2016/12/Verilog-Basics-6-System... · Digital System Design Verilog: System Tasks and Testbench Dr.

7

$monitor Example

$time: returns simulation time

Page 8: Digital System Design Verilog: System Tasks and …jufiles.com/wp-content/uploads/2016/12/Verilog-Basics-6-System... · Digital System Design Verilog: System Tasks and Testbench Dr.

8

File I/O

ptr = $fopen("file_name"); A function that opens a file for writing, and returns

a integer pointer to the file.

$fclose (ptr); A function that closes a disk file that was opened

by $fopen.

$monitor (ptr, "text_with_format_specifiers", signal, signal, ... ); Results of $monitor is sent to output file

$display (ptr, "text_with_format_specifiers", signal, signal, ... ); Results of $display is sent to output file

Page 9: Digital System Design Verilog: System Tasks and …jufiles.com/wp-content/uploads/2016/12/Verilog-Basics-6-System... · Digital System Design Verilog: System Tasks and Testbench Dr.

9

File I/O

$readmemb("file_name", register_array, start, end) Read file_name and load it into register_array. Data is in binary format

$readmemh("file_name", register_array, start, end); Read file_name and load it into register_array. Data is hex format

$fscanf("file_name", format, arguments)

Page 10: Digital System Design Verilog: System Tasks and …jufiles.com/wp-content/uploads/2016/12/Verilog-Basics-6-System... · Digital System Design Verilog: System Tasks and Testbench Dr.

10

File I/O: Generate Output File

Page 11: Digital System Design Verilog: System Tasks and …jufiles.com/wp-content/uploads/2016/12/Verilog-Basics-6-System... · Digital System Design Verilog: System Tasks and Testbench Dr.

11

File I/O: Reading From a File

Note: 14410= 1001 0000

Page 12: Digital System Design Verilog: System Tasks and …jufiles.com/wp-content/uploads/2016/12/Verilog-Basics-6-System... · Digital System Design Verilog: System Tasks and Testbench Dr.

12

File I/O: VCD Generation

Page 13: Digital System Design Verilog: System Tasks and …jufiles.com/wp-content/uploads/2016/12/Verilog-Basics-6-System... · Digital System Design Verilog: System Tasks and Testbench Dr.

13

File I/O: VCD Generation

$dumpfile Sets the VCD file name

$dumpvars Enable dumping all variables in the design

$dumpvars ( level, module) Dump all the vars at level module with depth of level

$dumpon / $dumpoff Enable/disable dumping

Page 14: Digital System Design Verilog: System Tasks and …jufiles.com/wp-content/uploads/2016/12/Verilog-Basics-6-System... · Digital System Design Verilog: System Tasks and Testbench Dr.

14

VCD File Example

Page 15: Digital System Design Verilog: System Tasks and …jufiles.com/wp-content/uploads/2016/12/Verilog-Basics-6-System... · Digital System Design Verilog: System Tasks and Testbench Dr.

15

Simulation Control

$finish; Finishes a simulation and exits the simulation

process.

$stop; Halts a simulation and enters an interactive debug

mode.

$random (seed); Returns a random 32-bit signed integer.

Page 16: Digital System Design Verilog: System Tasks and …jufiles.com/wp-content/uploads/2016/12/Verilog-Basics-6-System... · Digital System Design Verilog: System Tasks and Testbench Dr.

16

Testbench

A testebench is a verilg program to verify a design. It consists of: Stimulus Generators: set the values of the design

inputs Monitors: observe the values of the design output (and

possibly internal nodes) Checkers: verifies the behavior of the design

Page 17: Digital System Design Verilog: System Tasks and …jufiles.com/wp-content/uploads/2016/12/Verilog-Basics-6-System... · Digital System Design Verilog: System Tasks and Testbench Dr.

17

Testbench Module: Main Components

Page 18: Digital System Design Verilog: System Tasks and …jufiles.com/wp-content/uploads/2016/12/Verilog-Basics-6-System... · Digital System Design Verilog: System Tasks and Testbench Dr.

18

Testbench Example: 4-bit Counter

Page 19: Digital System Design Verilog: System Tasks and …jufiles.com/wp-content/uploads/2016/12/Verilog-Basics-6-System... · Digital System Design Verilog: System Tasks and Testbench Dr.

19

Testbench Example: 4-bit Counter

Page 20: Digital System Design Verilog: System Tasks and …jufiles.com/wp-content/uploads/2016/12/Verilog-Basics-6-System... · Digital System Design Verilog: System Tasks and Testbench Dr.

20

Testbench Example: 4-bit Counter

endmodule

Page 21: Digital System Design Verilog: System Tasks and …jufiles.com/wp-content/uploads/2016/12/Verilog-Basics-6-System... · Digital System Design Verilog: System Tasks and Testbench Dr.

21

Testbench Example: half-adder design