Testbenches HDL that tests another module: device under test (dut)

Slides:



Advertisements
Similar presentations
The Verilog Hardware Description Language
Advertisements

Synchronous Sequential Logic
Table 7.1 Verilog Operators.
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.
Copyright © 2007 Elsevier4- Chapter 4 :: Hardware Description Languages Digital Design and Computer Architecture David Money Harris and Sarah L. Harris.
Computer Architecture and Design – ECEN 350
Sequential Logic in Verilog
Lecture 4. Verilog HDL 1 (Combinational Logic Design)
SoC Verification HW #2 TA: Wei-Ting Tu Assignment: 04/12/06
Lecture 6. Verilog HDL – Sequential Logic
ECE 551 Digital System Design & Synthesis Fall 2011 Midterm Exam Overview.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
1 CSE-308 Digital System Design (DSD) N-W.F.P. University of Engineering & Technology, Peshawar.
Anurag Dwivedi. Basic Block - Gates Gates -> Flip Flops.
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.
1 Arithmetic, ALUs Lecture 9 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
HDL – Hardware Description Languages CT101 – Computing Systems.
 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.
Chapter 4 Computer System Architectures Chapter 4 Based on Digital Design and Computer Architecture, 2 nd Edition David Money Harris and Sarah L. Harris.
Lecture 5. Verilog HDL #1 Prof. Taeweon Suh Computer Science & Engineering Korea University COSE221, COMP211 Logic Design.
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.
Modern VLSI Design 3e: Chapter 8 Copyright  1998, 2002 Prentice Hall PTR Topics n Verilog register-transfer modeling: –basics using traffic light controller;
Structural Description
Chapter 4 Digital Design and Computer Architecture: ARM® Edition
Lecture 10 Flip-Flops/Latches
Supplement on Verilog FF circuit examples
Figure 8.1. The general form of a sequential circuit.
Last Lecture Talked about combinational logic always statements. e.g.,
Timing and Verification
Discussion 2: More to discuss
EMT 351/4 DIGITAL IC DESIGN Week # Synthesis of Sequential Logic 10.
Chapter 4 Digital Design and Computer Architecture, 2nd Edition
COMP211 Computer Logic Design
Testbenches HDL that tests another module: device under test (dut)
Digital System Verification
‘if-else’ & ‘case’ Statements
HDL for Sequential Circuits
Chapter 4 Digital Design and Computer Architecture, 2nd Edition
Lecture 9: Testbench and Division
Registers and Counters
Developing More Advanced Testbenches
FSM MODELING MOORE FSM MELAY FSM. Introduction to DIGITAL CIRCUITS MODELING & VERIFICATION using VERILOG [Part-2]
Registers and Counters
332:437 Lecture 8 Verilog and Finite State Machines
Test Fixture (Testbench)
Verilog for Digital Design
COE 202 Introduction to Verilog
Register-Transfer Level Components in Verilog
Lecture 9: Testbench and Division
The Verilog Hardware Description Language
Dr. Tassadaq Hussain Introduction to Verilog – Part-3 Expressing Sequential Circuits and FSM.
The Verilog Hardware Description Language
CS 153 Logic Design Lab Professor Ian G. Harris
The Verilog Hardware Description Language
Lecture 4: Continuation of SystemVerilog
Chapter 4 Digital Design and Computer Architecture: ARM® Edition
Registers and Counters
Verilog for Testbenches
Registers and Counters
332:437 Lecture 8 Verilog and Finite State Machines
Introduction to Digital IC Design
Registers and Counters
Design of Digital Circuits Lecture 8: Timing and Verification
Lecture 7: Verilog Part II
Presentation transcript:

Testbenches HDL that tests another module: device under test (dut) Not synthesizeable Types: Simple Self-checking Self-checking with testvectors Slide derived from slides by Harris & Harris from their book

Delays module example(input logic a, b, c, output logic y); logic ab, bb, cb, n1, n2, n3; assign #1 {ab, bb, cb} = ~{a, b, c}; assign #2 n1 = ab & bb & cb; assign #2 n2 = a & bb & cb; assign #2 n3 = a & bb & c; assign #4 y = n1 | n2 | n3; endmodule Slide derived from slides by Harris & Harris from their book

Delays module example(input logic a, b, c, output logic y); logic ab, bb, cb, n1, n2, n3; assign #1 {ab, bb, cb} = ~{a, b, c}; assign #2 n1 = ab & bb & cb; assign #2 n2 = a & bb & cb; assign #2 n3 = a & bb & c; assign #4 y = n1 | n2 | n3; endmodule Slide derived from slides by Harris & Harris from their book

Testbench Example Write SystemVerilog code to implement the following function in hardware: y = bc + ab Name the module sillyfunction Slide derived from slides by Harris & Harris from their book

Testbench Example Write SystemVerilog code to implement the following function in hardware: y = bc + ab module sillyfunction(input logic a, b, c, output logic y); assign y = ~b & ~c | a & ~b; endmodule Slide derived from slides by Harris & Harris from their book

Simple Testbench module testbench1(); logic a, b, c; logic y; // instantiate device under test sillyfunction dut(a, b, c, y); // apply inputs one at a time initial begin a = 0; b = 0; c = 0; #10; c = 1; #10; b = 1; c = 0; #10; a = 1; b = 0; c = 0; #10; end endmodule Slide derived from slides by Harris & Harris from their book

Self-checking Testbench module testbench2(); logic a, b, c; logic y; sillyfunction dut(a, b, c, y); // instantiate dut initial begin // apply inputs, check results one at a time a = 0; b = 0; c = 0; #10; if (y !== 1) $display("000 failed."); c = 1; #10; if (y !== 0) $display("001 failed."); b = 1; c = 0; #10; if (y !== 0) $display("010 failed."); if (y !== 0) $display("011 failed."); a = 1; b = 0; c = 0; #10; if (y !== 1) $display("100 failed."); if (y !== 1) $display("101 failed."); if (y !== 0) $display("110 failed."); if (y !== 0) $display("111 failed."); end endmodule Slide derived from slides by Harris & Harris from their book

Testbench with Testvectors Testvector file: inputs and expected outputs Testbench: Generate clock for assigning inputs, reading outputs Read testvectors file into array Assign inputs, expected outputs Compare outputs with expected outputs and report errors Slide derived from slides by Harris & Harris from their book

Testbench with Testvectors Testbench clock: assign inputs (on rising edge) compare outputs with expected outputs (on falling edge). Testbench clock also used as clock for synchronous sequential circuits Slide derived from slides by Harris & Harris from their book

Testvectors File File: example.tv contains vectors of abc_y expected 000_1 001_0 010_0 011_0 100_1 101_1 110_0 111_0 Slide derived from slides by Harris & Harris from their book

1. Generate Clock module testbench3(); logic clk, reset; logic a, b, c, yexpected; logic y; logic [31:0] vectornum, errors; // bookkeeping variables logic [3:0] testvectors[10000:0]; // array of testvectors // instantiate device under test sillyfunction dut(a, b, c, y); // generate clock always // no sensitivity list, so it always executes begin clk = 1; #5; clk = 0; #5; end Slide derived from slides by Harris & Harris from their book

2. Read Testvectors into Array // at start of test, load vectors and pulse reset initial begin $readmemb("example.tv", testvectors); vectornum = 0; errors = 0; reset = 1; #27; reset = 0; end // Note: $readmemh reads testvector files written in // hexadecimal Slide derived from slides by Harris & Harris from their book

3. Assign Inputs & Expected Outputs // apply test vectors on rising edge of clk always @(posedge clk) begin #1; {a, b, c, yexpected} = testvectors[vectornum]; end Slide derived from slides by Harris & Harris from their book

4. Compare with Expected Outputs // check results on falling edge of clk always @(negedge clk) if (~reset) begin // skip during reset if (y !== yexpected) begin $display("Error: inputs = %b", {a, b, c}); $display(" outputs = %b (%b expected)",y,yexpected); errors = errors + 1; end // Note: to print in hexadecimal, use %h. For example, // $display(“Error: inputs = %h”, {a, b, c}); Slide derived from slides by Harris & Harris from their book

4. Compare with Expected Outputs // increment array index and read next testvector vectornum = vectornum + 1; if (testvectors[vectornum] === 4'bx) begin $display("%d tests completed with %d errors", vectornum, errors); $finish; end endmodule // === and !== can compare values that are 1, 0, x, or z. Slide derived from slides by Harris & Harris from their book