 A test bench is an HDL program used for applying stimulus to an HDL design in order to test it and observe its response during simulation.  In addition.

Slides:



Advertisements
Similar presentations
Chapter 15:Introduction to Verilog Testbenches Objectives In this section,you will learn about designing a testbench: Creating clocks Including files Strategic.
Advertisements

//HDL Example 8-2 // //RTL description of design example (Fig.8-9) module Example_RTL (S,CLK,Clr,E,F,A);
Counters Discussion D8.3.
CDA 3100 Recitation Week 11.
//HDL Example 4-10 // //Gate-level description of circuit of Fig. 4-2 module analysis (A,B,C,F1,F2); input.
Verilog.
Simulation executable (simv)
Verilog Overview. University of Jordan Computer Engineering Department CPE 439: Computer Design Lab.
Synchronous Sequential Logic
EE 361 Fall 2003University of Hawaii1 Hardware Design Tips EE 361 University of Hawaii.
Verilog Modules for Common Digital Functions
CPEN Digital System Design
Table 7.1 Verilog Operators.
Verilog Intro: Part 1.
Hardware Description Language (HDL)
16/04/20151 Hardware Descriptive Languages these notes are taken from Mano’s book It can represent: Truth Table Boolean Expression Diagrams of gates and.
CSE 201 Computer Logic Design * * * * * * * Verilog Modeling
//HDL Example 5-1 // //Description of D latch (See Fig.5-6) module D_latch (Q,D,control); output Q; input.
Verilog. 2 Behavioral Description initial:  is executed once at the beginning. always:  is repeated until the end of simulation.
//HDL Example 6-1 // //Behavioral description of //Universal shift register // Fig. 6-7 and Table 6-3 module shftreg.
 HDLs – Verilog and Very High Speed Integrated Circuit (VHSIC) HDL  „ Widely used in logic design  „ Describe hardware  „ Document logic functions.
Pulse-Width Modulated DAC
Conditional Statements  if and else if statements if (expression) if (expression) statements statements { else if (expression) { else if (expression)
OUTLINE Introduction Basics of the Verilog Language Gate-level modeling Data-flow modeling Behavioral modeling Task and function.
Verilog Sequential Circuits Ibrahim Korpeoglu. Verilog can be used to describe storage elements and sequential circuits as well. So far continuous assignment.
ECE 353 Computer Systems Lab I Verilog Hardware Description Language.
Kazi Fall 2006 EEGN 4941 EEGN-494 HDL Design Principles for VLSI/FPGAs Khurram Kazi Some of the slides were taken from K Gaj’s lecture slides from GMU’s.
Silicon Programming--Intro. to HDLs1 Hardware description languages: introduction intellectual property (IP) introduction to VHDL and Verilog entities.
Design example Binary Multiplier.
ELEN 468 Advanced Logic Design
COE 202 Introduction to Verilog Computer Engineering Department College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals.
Kazi Fall 2006 EEGN 4941 EEGN-494 HDL Design Principles for VLSI/FPGAs Khurram Kazi.
Verilog Intro: Part 2. Procedural Blocks There are two types of procedural blocks in Verilog. – initial for single-pass behavior : initial blocks execute.
Quad 2-to-1 Multiplexer Discussion D7.4 Example 7.
Today’s Lecture Process model –initial & always statements Assignments –Continuous & procedural assignments Timing Control System tasks.
Overview Logistics Last lecture Today HW5 due today
Figure 7.1. Control of an alarm system. Memory element Alarm Sensor Reset Set OnOff 
Week Four Design & Simulation Example slides. Agenda Review the tiny example (Minako “logic”)from last week – look at the detailed static timing report.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
SoC Verification HW #2 TA: Wei-Ting Tu Assignment: 04/12/06
Chapter 4: Behavioral Modeling Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 4-1 Ders – 4: Davranışsal Modelleme.
ECE 551 Digital System Design & Synthesis Fall 2011 Midterm Exam Overview.
CS 61C L4.2.2 Verilog II (1) K. Meinz, Summer 2004 © UCB CS61C : Machine Structures Lecture Verilog II Kurt Meinz inst.eecs.berkeley.edu/~cs61c.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
Slide 1 6. VHDL/Verilog Behavioral Description. Slide 2 Verilog for Synthesis: Behavioral description Instead of instantiating components, describe them.
ECE/CS 352 Digital System Fundamentals© 2001 C. Kime 1 ECE/CS 352 Digital Systems Fundamentals Spring 2001 Chapters 3 and 4: Verilog – Part 2 Charles R.
1 CSE-308 Digital System Design (DSD) N-W.F.P. University of Engineering & Technology, Peshawar.
1 COMP541 Sequential Circuits Montek Singh Feb 1, 2012.
Behavioral Modelling - 1. Verilog Behavioral Modelling Behavioral Models represent functionality of the digital hardware. It describes how the circuit.
Verilog A Hardware Description Language (HDL ) is a machine readable and human readable language for describing hardware. Verilog and VHDL are HDLs.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
OUTLINE Introduction Basics of the Verilog Language Gate-level modeling Data-flow modeling Behavioral modeling Task and function.
SYEN 3330 Digital SystemsJung H. Kim Chapter SYEN 3330 Digital Systems Chapters 4 – Part4: Verilog – Part 2.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
Lecture 5. Verilog HDL #3 Prof. Taeweon Suh Computer Science & Engineering Korea University COSE221, COMP211 Logic Design.
1 Lecture 3: Modeling Sequential Logic in Verilog HDL.
Figure Implementation of an FSM in a CPLD..
Structural Description
An Introduction to Verilog: Transitioning from VHDL
Supplement on Verilog FF circuit examples
Supplement on Verilog for Algorithm State Machine Chart
Figure 8.1. The general form of a sequential circuit.
Lecture 11 Registers and Counters
HDL for Sequential Circuits
Verilog-HDL-3 by Dr. Amin Danial Asham.
Test Fixture (Testbench)
COE 202 Introduction to Verilog
Register-Transfer Level Components in Verilog
The Verilog Hardware Description Language
Presentation transcript:

 A test bench is an HDL program used for applying stimulus to an HDL design in order to test it and observe its response during simulation.  In addition to the always statement, test benches use the initial statement to provide a stimulus to the circuit under test.  The always statement executes repeatedly in a loop. The initial statement executes only once starting from simulation time=0 and may continue with any operations that are delayed by a given number of units as specified by the symbol #.

 A stimulus module is an HDL program that has the following form. module testname Declare local reg and wire identifiers Instantiate the design module under test. Generate stimulus using initial and always statements Display the output response. endmodule  A test module typically has no inputs or outputs.  The signals that are applied as inputs to the design module for simulation are declared in the stimulus module as local reg data type.  The outputs of the design module that are displayed for testing are declared in the stimulus model as local wire data type.  The module under test is then instantiated using the local identifiers.

The stimulus model generates inputs for the design module by declaring identifiers TA and TB as reg data type, and checks the output of the design unit with the wire identifier TC. The local identifiers are then used to instantiate the design module under test.

 The response to the stimulus generated by the initial and always blocks will appear at the output of the simulator as timing diagrams.  It is also possible to display numerical outputs using Verilog system tasks. ◦ $display – display one-time value of variables or strings with end-of-line return, ◦ $write – same $display but without going to next line. ◦ $monitor – display variables whenever a value changes during simulation run. ◦ $time – displays simulation time ◦ $finish – terminates the simulation  The syntax for $display,$write and $monitor is of the form Task-name (format-specification, argument list); E.g. $display(%d %b %b, C,A,B); $display(“time = %0d A = %b B=%b”,$time,A,B);

//Dataflow description of 2-to-1-line multiplexer module mux2x1_df (A,B,select,OUT); input A,B,select; output OUT; assign OUT = select ? A : B; endmodule

//Stimulus for mux2x1_df module testmux; reg TA,TB,TS; //inputs for mux wire Y; //output from mux mux2x1_bh mx (TA,TB,TS,Y); // instantiate mux initial begin $monitor(”select=%b A=%b B=%b OUT=%b",TS,TA,TB,Y); TS = 1; TA = 0; TB = 1; #10 TA = 1; TB = 0; #10 TS = 0; #10 TA = 0; TB = 1; end endmodule

Design Module ABOut Truth Table

Design Module Test Bench A in Y

module and_2in (A, B, Out); input A, B; output Out; wire Out; assign Out = A & B; endmodule

`include “and_2in.v” `timescale 1ns/10ps module and_2in_tb; reg A, in; wire Y; and_2in a1(.A(A),.B(in),.Out(Y)); initial begin A=0; in=0; #20; A=0; in=1; #20; A=1; in=0; #20; A=1; in=1; #40; $stop; $finish; end endmodule

D clk Q Q_n reset_n Design Module Test Bench DClkreset_nQQ_n

D clk Q Q_n reset_n Design Module TestBench in out outbar clock reset

module dff (D, reset_n, clk, Q, Q_n); input D, clk, reset_n; output Q, Q_n; reg Q, Q_n; (posedge clk or negedge reset_n) begin end if(reset_n == 0) begin Q <= 0; Q_n<=1; end else begin Q <= D; Q_n <= !D; end

`include “dff.v” `timescale 1ns/10ps module dff_tb; reg in, clock, reset; wire out, outbar; dff d1(.D(in),.reset_n(reset),.clk(clock),.Q(out),.Q_n(outbar));

initial begin in =0; reset =0; clock =0; #10; reset =1; #5; in=1; #10; in=0; #40; $stop; end always #10 clock = ~clock; endmodule

 Reset the counter asynchronously through active low global reset reset_n  reset the count when the count has reached value max_count  Advance the counter through active high enable signal reset_n max_count[7:0] enable clk count[7:0]

assign reset_count = (count == max_count); /* Generates the signal reset_count which resets the counter when the count reaches value of input max_count */ assign cnt_next = count +1; // Preincrement the value of count

(posedge clk or negedge reset_n) begin if(reset_n ==0) count <= 8’d0; else if(reset_count == 1) count <= 8’d0; else if(enable ==1) count <= cnt_next; else count <= count; end

`include “counter.v” `timescale 1ns/10ps module counter_tb; reg reset_n, clk, enable; reg[7:0] max_count; wire[7:0] count; counter c1(.reset_n(reset_n),.clk(clk),.enable(enable),.max_count(max_count),.count(count) );

initial begin reset_n =0; clk =0; enable =0; max_count =100; #25; reset_n =1; enable =1; #5000; $stop; end always #10 clock =~ clock; endmodule

 Loads data set_data into the register when load signal is high  Shifts data when shift signal is high  Can perform both right and left shift operations  rl_n signal indicates whether to shift right or left. A high value shifts right and a low value shifts left.  data_valid is high whenever data is valid and eoc is asserted when transfer is complete

reset_n clk rl_n shift load set_data[15:0] data_out data_valid eoc

(posedge clk or negedge reset_n) begin if(reset_n == 0) begin data_out<=0; data_valid<=0; eoc <=0; sr <=0; cnt_reg <=0; end else if(load ==1) begin sr<= set_data; cnt_reg <=16; data_out<=0; data_valid<=0; eoc <=0; end

else if ((shift==1) && (cnt_reg !=0)) begin sr > 1) : (sr <<1); data_out <= rl_n ? sr[0] : sr[15]; cnt_reg <= cnt_reg -1; data_valid <=1; eoc<=0; end

else if ((shift==1) && (cnt_reg ==0)) begin sr <=sr; cnt_reg <=cnt_reg; data_out<=0; data_valid<=0; eoc <=1; end

else begin sr <=sr; cnt_reg <=cnt_reg; data_out<=data_out; data_valid<=data_valid; eoc <=eoc; end

module parallel_serial_tb ; reg reset_n, load, shift, rl_n, clk; reg[15:0] set_data; wire data_out, data_valid, eoc; parallel_serial p1(.reset_n(reset_n),.load(load),.shift(shift),.rl_n(rl_n),.clk(clk),. set_data(set_data),.data_out(data_out),.data_valid(data_valid),.eoc(eoc) );

initial begin reset_n =0;load=0;shift=0;rl_n=0;clk=0; set_data=0; #25; reset_n =1; set_data = 16’hAAAA; load =1; #20; load =0; shift =1; #400; shift =0; #20; rl_n =1; load=1; #20; shift=1; #500; $stop; end always #10 clk = ~clk; endmodule