Mridula Allani Spr 2011, Apr 115270/6270 Guest Lecture by M. Allani.

Slides:



Advertisements
Similar presentations
Verilog Intro: Part 1.
Advertisements

VHDL ELEC 418 Advanced Digital Systems Dr. Ron Hayne Images Courtesy of Thomson Engineering.
George Mason University ECE 448 – FPGA and ASIC Design with VHDL ECE 448 Lecture 10 Advanced Testbenches.
FPGAs and VHDL Lecture L12.1. FPGAs and VHDL Field Programmable Gate Arrays (FPGAs) VHDL –2 x 1 MUX –4 x 1 MUX –An Adder –Binary-to-BCD Converter –A Register.
ELEN 468 Lecture 191 ELEN 468 Advanced Logic Design Lecture 19 VHDL.
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.
VHDL And Synthesis Review. VHDL In Detail Things that we will look at: –Port and Types –Arithmetic Operators –Design styles for Synthesis.
Simple Testbenches Behavioral Modeling of Combinational Logic
Binary-to-BCD Converter
1Kazi Spring 2008 CSCI 660 CSCI-660 Introduction to VLSI Design Khurram Kazi.
1 Lecture 11 Chap 13: Test Benches Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University.
ECE 332 Digital Electronics and Logic Design Lab Lab 5 VHDL Design Styles Testbenches.
1 Part V: VHDL CODING. 2 Design StructureData TypesOperators and AttributesConcurrent DesignSequential DesignSignals and VariablesState Machines A VHDL.
Reconfigurable Computing - VHDL - Types John Morris Chung-Ang University The University of Auckland.
Binary-to-BCD Converter
Design Verification VHDL ET062G & ET063G Lecture 5 Najeem Lawal 2012.
A.7 Concurrent Assignment Statements Used to assign a value to a signal in an architecture body. Four types of concurrent assignment statements –Simple.
Figure 5.1 Conversion from decimal to binary. Table 5.1 Numbers in different systems.
Graduate Computer Architecture I VHDL Structure and Testing Michael Sorensen.
VHDL Project I: Introduction to Testbench Design Matthew Murach Slides Available at:
VHDL in 1h Martin Schöberl. AK: JVMHWVHDL2 VHDL /= C, Java,… Think in hardware All constructs run concurrent Different from software programming Forget.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
EE3A1 Computer Hardware and Digital Design Lecture 5 Testbenches and Memories in VHDL.
Digital System Design Verilog ® HDL Parameters, and Generate Blocks Maziar Goudarzi.
George Mason University ECE 545 Lecture 7 Advanced Testbenches.
George Mason University ECE 545 – Introduction to VHDL Variables, Functions, Memory, File I/O ECE 545 Lecture 7.
1 ECE 545 – Introduction to VHDL Dataflow Modeling of Combinational Logic Simple Testbenches ECE 656. Lecture 2.
Copyright(c) 1996 W. B. Ligon III1 Getting Started with VHDL VHDL code is composed of a number of entities Entities describe the interface of the component.
CPE 626 Advanced VLSI Design Lecture 6: VHDL Synthesis Aleksandar Milenkovic
IAY 0600 Digital Systems Design VHDL discussion Verification: Testbenches Alexander Sudnitson Tallinn University of Technology.
Mixed Style RTL Modeling
1 component OR_3 port (A,B,C: in bit; Z: out bit); end component ; Reserved Words  Declarations of Components and Entities are similar  Components are.
ECE 331 – Digital System Design Single-bit Adder Circuits and Adder Circuits in VHDL (Lecture #11) The slides included herein were taken from the materials.
Reconfigurable Computing - VHDL - Types John Morris Chung-Ang University The University of Auckland.
George Mason University Simple Testbenches ECE 545 Lecture 4.
Assignment write a short notes on 1.Manufacturing Testing. 2.Functional Testing. 3.Files and Text I/O. 4.Differentiate the cpld and fpga architecture.
2/10/07DSD,USIT,GGSIPU1 BCD adder KB3B2B1B0CD3D2D1D
VHDL Discussion Sequential Sytems. Memory Elements. Registers. Counters IAY 0600 Digital Systems Design Alexander Sudnitson Tallinn University of Technology.
CS/EE 3700 : Fundamentals of Digital System Design Chris J. Myers Lecture 5: Arithmetic Circuits Chapter 5 (minus 5.3.4)
 Seattle Pacific University EE Logic System DesignCounters-1 Shift Registers DQ clk DQ DQ ShiftIn Q3Q3 Q2Q2 DQ Q1Q1 Q0Q0 A shift register shifts.
Data Storage VHDL ET062G & ET063G Lecture 4 Najeem Lawal 2012.
Number Representation and Arithmetic Circuits
IAY 0600 Digital Systems Design VHDL discussion Verification: Testbenches Alexander Sudnitson Tallinn University of Technology.
Unit 4 Structural Descriptions SYLLABUS Highlights of Structural descriptions Organization of the Structural descriptions Binding State Machines Generate(HDL),Generic(VHDL),
George Mason University Behavioral Modeling of Sequential-Circuit Building Blocks ECE 545 Lecture 8.
George Mason University Advanced Testbenches Lecture 4.
EGRE 6311 LHO 04 - Subprograms, Packages, and Libraries EGRE 631 1/26/09.
ECE 448 – FPGA and ASIC Design with VHDL George Mason University ECE 448 Lab 2 Implementing Combinational Logic in VHDL.
CDA 4253 FPGA System Design VHDL Testbench Development Hao Zheng Comp. Sci & Eng USF.
1 Introduction to Engineering Spring 2007 Lecture 19: Digital Tools 3.
An Introduction to Verilog: Transitioning from VHDL
CHAPTER 17 VHDL FOR SEQUENTIAL LOGIC
ECE 4110–5110 Digital System Design
ECE 545 Lecture 10 Advanced Testbenches.
CPE 528: Session #7 Department of Electrical and Computer Engineering University of Alabama in Huntsville.
HDL Programming Fundamentals
ECE 448 Lecture 3 Combinational-Circuit Building Blocks Data Flow Modeling of Combinational Logic ECE 448 – FPGA and ASIC Design with VHDL.
VHDL (VHSIC Hardware Description Language)
CPE 528: Lecture #5 Department of Electrical and Computer Engineering University of Alabama in Huntsville.
Founded in Silicon Valley in 1984
ECE 448 Lecture 3 Combinational-Circuit Building Blocks Data Flow Modeling of Combinational Logic ECE 448 – FPGA and ASIC Design with VHDL.
Data Flow Description of Combinational-Circuit Building Blocks
Figure 8.1. The general form of a sequential circuit.
UNIT 6: Mixed-Type Description
Data Flow Description of Combinational-Circuit Building Blocks
ECE 545 Lecture 5 Simple Testbenches.
Verilog for Testbenches
디 지 털 시 스 템 설 계 UP2 Kit를 이용한 카운터 설계
(Simple Testbenches & Arithmetic Operations)
Presentation transcript:

Mridula Allani Spr 2011, Apr /6270 Guest Lecture by M. Allani

What is A Test Bench?  Test Bench is a program that verifies the functional correctness of the hardware design.  The test bench program checks whether the hardware model does what it is supposed to do and is not doing what it is not supposed to do. Spr 2011, Apr /6270 Guest Lecture by M. Allani

Main Functions of a Test Bench  Generate stimulus for testing the hardware block.  Apply the stimulus.  Compare the generated outputs against the expected outputs. Generating Input Stimuli Design Under Test (DUT) Comparing Generated Outputs and Expected Outputs Spr 2011, Apr /6270 Guest Lecture by M. Allani

Generating Stimulus Vectors  Vectors can be generated within the test bench program or generated elsewhere and supplied to the test bench program as an input file.  Vectors can also be stored in a table within the test bench program. Spr 2011, Apr /6270 Guest Lecture by M. Allani

Typical VHDL Test Bench entity test_bench is end; architecture tb_behavior of test_bench is component design_under_test port ( list-of-ports-their-types- and-modes); end component; Local-signal-declarations; begin CLOCK: process begin clock <= '0'; wait for t ns; clock <= '1'; wait for t ns; end process; Generate-stimulus-vectors-using- behavioral-constructs; Apply-to-entity-under-test; DUT: design_under_test port map ( port-associations ); Monitor-output-values-and-compare- with-expected-values; if (no errors) report "Testbench completed!" severity note; else report "Something wrong!" severity error; end if; end tb_behavior; Spr 2011, Apr /6270 Guest Lecture by M. Allani

Defining a Vector Table in VHDL  Example, constant no_of_bits: INTEGER := 4; constant no_of_vectors: INTEGER := 5; type table_type is array (1 to no_of_vectors) of my_vector(1 to no_of_bits); constant vector_period: time := 100 ns; constant input_vectors: table_type := ("1001", "1000", "0010", "0000", "0110"); signal inputs: my_vector(1 to no_of_bits); signal a, b, c: my; signal d: my_vector(0 to 1); Spr 2011, Apr /6270 Guest Lecture by M. Allani

Reading vectors from a ASCII file  Example, process type vec_type is file of my.vector; file vec_file: vec_type is in "/usr/example.vec"; variable length: INTEGER; variable in_vector: my_vector(1 to 4); begin length := 4; - The number of bits to be read. while (not ENDFILE(vec_file)) loop READ (vec_file, in_vector, length); - It is necessary to specify the length of the vector to be read - since the file contains values of an unconstrained array type. end loop; end process; Spr 2011, Apr /6270 Guest Lecture by M. Allani

A Linear VHDL Test Bench  Example, inputs <= input_vectors(1) after 10 ns, input_vectors(2) after 25 ns, input_vectors(3) after 30 ns, input_vectors(4) after 32 ns, input_vectors(5) after 40 ns; a<= inputs(1); b <= inputs(4); c<=inputs(1); d<=inputs(2 to 3); Spr 2011, Apr /6270 Guest Lecture by M. Allani

Using a ‘generate’ statement  Example, G1: for J in 1 to no_of_vectors generate inputs <= input_vectors(J) after (vector_period * J); end generate G1; a<= inputs(1); b <= inputs(4); c<=inputs(1); d<=inputs(2 to 3); Spr 2011, Apr /6270 Guest Lecture by M. Allani

Using Random Numbers in VHDL  uniform(variable seed1, seed2 : inout positive; variable X : out real);  1 <= seed1 <=  1 <= seed2 <=  Example, PROCESS VARIABLE seed1, seed2: positive; -- Seed values for random generator VARIABLE rand: real; -- Random real-number value in range 0 to 1.0 VARIABLE int_rand: integer; -- Random integer value in range VARIABLE stim: std_logic_vector(31 DOWNTO 0); -- Random 32-bit stimulus BEGIN for i in 1 to 1000 loop UNIFORM(seed1, seed2, rand); -- generate random number int_rand := INTEGER(TRUNC(rand *256.0)); -- Convert to integer in range of 0 to , find integer part stim := std_logic_vector(to_unsigned(int_rand, stim'LENGTH)); -- convert to --std_logic_vector end loop; Spr 2011, Apr /6270 Guest Lecture by M. Allani

Libraries needed  use ieee.std_logic_1164.all;  use ieee.std_logic_textio.all; --For file operations  use ieee.numeric_std.all; --For unsigned numbers  use ieee.math_real.all;--For random number generation  use std.textio.all; Spr 2011, Apr /6270 Guest Lecture by M. Allani

Simple Example in VHDL library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; use ieee.std_logic_arith.all; entity counter_TB is -- entity declaration end counter_TB; architecture TB of counter_TB is component counter port( clock: in std_logic; clear: in std_logic; count: in std_logic; Q: out std_logic_vector(1 downto 0) ); end component; signal T_clock: std_logic; signal T_clear: std_logic; signal T_count: std_logic; signal T_Q: std_logic_vector(1 downto 0); begin U_counter: counter port map (T_clock, T_clear, T_count, T_Q); process begin T_clock <= '0'; -- clock cycle is 10 ns wait for 5 ns; T_clock <= '1'; wait for 5 ns; end process; process variable err_cnt: integer :=0; begin T_clear <= '1'; -- start counting T_count <= '1'; wait for 20 ns; T_clear <= '0'; -- clear output -- test case 1 wait for 10 ns; assert (T_Q=1) report "Failed case 1" severity error; if (T_Q/=1) then err_cnt := err_cnt+1; end if; -- test case 2 wait for 10 ns; assert (T_Q=2) report "Failed case 2" severity error; if (T_Q/=2) then err_cnt := err_cnt+1; end if; if (err_cnt=0) then assert false report "Testbench of Adder completed successfully!" severity note; else assert true report "Something wrong, try again" severity error; end if; wait; end process; end TB; Spr 2011, Apr /6270 Guest Lecture by M. Allani

Typical Verilog Test Bench module test_bench ; reg list_of_inputs_to_DUT; wire list_of_outputs_to_DUT; design_under_test ( list-of-inputs-outputs-of-DUT- their-types-and-modes); initial begin Initialize-Generate-stimulus- vectors-using-behavioral-constructs; end always #period clk = ! clk; initial begin $dumpfile (“dump.vcd"); $dumpvars; end initial begin $display (“variable list with their type specifier”); $monitor(“variable list with their type specifier”); end initial #simulation_time $finish; //Rest of testbench code after this line endmodule Spr 2011, Apr /6270 Guest Lecture by M. Allani

Defining a Vector Table in Verilog  Example, no_of_bits = 4; no_of_vectors = 5; reg [0 : (no_of_vectors-1)] table[0: (no_of_bits-1)]; vector_period = 100 ns; table[0] = 4’b1001; table[1] = 4’b1000; table[2] = 4’b0010; table[3] = 4’b0000; table[4] = 4’b0110 ; Spr 2011, Apr /6270 Guest Lecture by M. Allani

 Example, vec_file = $fopen("/usr/example.vec“); results = $fopen(" /usr/results.dat"); reg [3:0] my_vector length [0:3] ; //The number of vectors and number of bits to be read for each vector. c = $fgetc(file); while (c !== `EOF) begin $readmemh (“vec_file”, length ); //Read hex file content into a memory array. $readmemb (“vec_file”, length ); //Read binary file content into a memory array. $fdisplay (results, variable list with format specifiers); $fmonitor (results, variable list with format specifiers); $fclose (results); $fclose (vec_file ); end end process; Reading vectors from a ASCII file Spr 2011, Apr /6270 Guest Lecture by M. Allani

A Linear Verilog Test Bench  Example, #10 ns inputs = input_vectors(1); # 25 ns inputs = input_vectors(2); # 30 ns inputs = input_vectors(3); # 32 ns inputs = input_vectors(4); # 40 ns inputs = input_vectors(5); a = inputs[1]; b = inputs[4]; c =inputs[1]; d =inputs[2 : 3]; Spr 2011, Apr /6270 Guest Lecture by M. Allani

 Example, generate genvar j; for (j=0; j<= no_of_vectors; j=j+1) begin vector_period = (vector_period * j) ; #vector_period inputs = input_vectors(j); end endgenerate a = inputs[1]; b = inputs[4]; c =inputs[1]; d =inputs[2 : 3]; Using a ‘generate’ statement Spr 2011, Apr /6270 Guest Lecture by M. Allani

Using Random Numbers in Verilog  Example 1, module test (); integer address; initial begin repeat(5) #1 address = $random; end initial $monitor("address = %d;",address); endmodule RESULT: //any 32-bit integer  Example 2, module Tb(); integer add_2, add_3; reg [31:0] add_1; initial begin repeat(5) begin #1; add_1 = $random % 10; add_2 = {$random} %10 ; add_3 = $unsigned($random) %10 ; end end initial $monitor("add_3 = %d;add_2 = %d;add_1 = %d",add_3,add_2,add_1); endmodule RESULT: add_3 = integers between 0 and 10 add_2 = integers between 0 and 10 add_1 = the result will not be an integer between 0 and 10 because $random also generates some negative 32-bit numbers. In general, min + {$random} % (max - min ) will generate random numbers between min and max. Spr 2011, Apr /6270 Guest Lecture by M. Allani

Simple Example in Verilog module tb_ripple_adder(); reg [1:0] a, b; reg carryin; wire carrout; wire [1:0] sum; ripple_adder DUT (.sum(sum),.carryout(carryout),.a(a),.b(b),.carryin(carryin)); initial begin //=====VCD==== $dumpfile ("synthesized.dump"); $dumpvars (0, tb_ripple_adder); //=====initialization ==== a = 2'b00; b = 2'b00;carryin = 0; //=====vector generation========= #50 a = 2'b00; b = 2'b01; #50 a = 2'b00; b = 2'b10; #50 a = 2'b00; b = 2'b11; end //=====display===== or b or carryin) $display ("time=%t", $time, "carryin=%b", carryin, "a=%b", a, "b=%b", b, "carryout=%b", carryout, "sum=%b", sum); //======job control===== initial begin #10001 $finish; end endmodule Spr 2011, Apr /6270 Guest Lecture by M. Allani

References  A VHDL Primer, 3rd Edition, J. Bhaskar   00/TestBench.pdf 00/TestBench.pdf  nedRandom_SynthWorks_2009.pdf nedRandom_SynthWorks_2009.pdf    nchGenerator.html nchGenerator.html  /xst/xst0086_10.html /xst/xst0086_10.html Spr 2011, Apr /6270 Guest Lecture by M. Allani