(Simple Testbenches & Arithmetic Operations)

Slides:



Advertisements
Similar presentations
1 Lecture 13 VHDL 3/16/09. 2 VHDL VHDL is a hardware description language. The behavior of a digital system can be described (specified) by writing a.
Advertisements

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.
Simple Testbenches Behavioral Modeling of Combinational Logic
1 Data Object Object Types A VHDL object consists of one of the following: –Signal, Which represents interconnection wires that connect component instantiation.
ECE 332 Digital Electronics and Logic Design Lab Lab 5 VHDL Design Styles Testbenches.
Data Flow Modeling of Combinational Logic Simple Testbenches
A VHDL Tutorial ENG2410. ENG241/VHDL Tutorial2 Goals Introduce the students to the following: –VHDL as Hardware description language. –How to describe.
George Mason University ECE 448 – FPGA and ASIC Design with VHDL George Mason University ECE 448 Lab 1 Developing Effective Testbenches.
VHDL for Combinational Circuits. VHDL We Know Simple assignment statements –f
CprE / ComS 583 Reconfigurable Computing Prof. Joseph Zambreno Department of Electrical and Computer Engineering Iowa State University Lecture #16 – Introduction.
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.
George Mason University ECE 448 – FPGA and ASIC Design with VHDL VHDL Refresher Lecture 2.
IAY 0600 Digital Systems Design VHDL discussion Verification: Testbenches Alexander Sudnitson Tallinn University of Technology.
(1) Basic Language Concepts © Sudhakar Yalamanchili, Georgia Institute of Technology, 2006.
George Mason University Simple Testbenches ECE 545 Lecture 4.
Digital System Projects
1 Part III: VHDL CODING. 2 Design StructureData TypesOperators and AttributesConcurrent DesignSequential DesignSignals and VariablesState Machines A VHDL.
04/26/20031 ECE 551: Digital System Design & Synthesis Lecture Set : Introduction to VHDL 12.2: VHDL versus Verilog (Separate File)
VHDL Discussion Subprograms IAY 0600 Digital Systems Design Alexander Sudnitson Tallinn University of Technology 1.
ECE 332 Digital Electronics and Logic Design Lab Lab 5 VHDL Design Styles Testbenches Concurrent Statements & Adders.
55:032 - Intro. to Digital DesignPage 1 VHDL and Processes Defining Sequential Circuit Behavior.
IAY 0600 Digital Systems Design VHDL discussion Verification: Testbenches Alexander Sudnitson Tallinn University of Technology.
George Mason University Advanced Testbenches Lecture 4.
ECE 448 Lab 1 Developing Effective Testbenches
EGRE 6311 LHO 04 - Subprograms, Packages, and Libraries EGRE 631 1/26/09.
George Mason University ECE 545 – Introduction to VHDL Data Flow & Structural Modeling of Combinational Logic ECE 545 Lecture 2.
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 18: Digital Tools 2.
Combinational logic circuit
Introduction to Vivado
Basic Language Concepts
Behavioral Style Combinational Design with VHDL
Verification: Testbenches in Combinational Design
CHAPTER 17 VHDL FOR SEQUENTIAL LOGIC
Behavioral Style Combinational Design with VHDL
IAY 0600 Digital Systems Design
ECE 448 Lecture 3 Combinational-Circuit Building Blocks Data Flow Modeling of Combinational Logic ECE 448 – FPGA and ASIC Design with VHDL.
ECE 545 Lecture 10 Advanced Testbenches.
ECE 448 Lab 1a Developing Effective Testbenches
ECE 434 Advanced Digital System L08
Lecture 4 VHDL Basics Simple Testbenches.
Signal & Variables April 14,2007 DSD,USIT,GGSIPU.
ECE 448 Lecture 3 Combinational-Circuit Building Blocks Data Flow Modeling of Combinational Logic ECE 448 – FPGA and ASIC Design with VHDL.
IAS 0600 Digital Systems Design
Lecture 3 VHDL Basics Simple Testbenches.
ECE 448 Lab 1 Developing Effective Testbenches
ECE 448 Lecture 3 Combinational-Circuit Building Blocks Data Flow Modeling of Combinational Logic ECE 448 – FPGA and ASIC Design with VHDL.
Data Flow Modeling of Combinational Logic
VHDL Discussion Subprograms
Behavioral Modeling of Sequential-Circuit Building Blocks
ECE 448 Lab 1 Developing Effective Testbenches
ECE 448 Lecture 3 Combinational-Circuit Building Blocks Data Flow Modeling of Combinational Logic ECE 448 – FPGA and ASIC Design with VHDL.
VHDL Discussion Subprograms
Data Flow Description of Combinational-Circuit Building Blocks
ECE 448 Lab 1 Developing Effective Testbenches
IAS 0600 Digital Systems Design
Data Flow Description of Combinational-Circuit Building Blocks
Developing Effective Testbenches
ECE 545 Lecture 5 Simple Testbenches.
Introduction to VHDL for Synthesis
CprE / ComS 583 Reconfigurable Computing
Sequntial-Circuit Building Blocks
4-Input Gates VHDL for Loops
ECE 448 Lab 1 Developing Effective Testbenches
(Sequential-Circuit Building Blocks)
EEL4712 Digital Design (Lab 1)
EEL4712 Digital Design.
EEL4712 Digital Design (Midterm 1 Review).
Presentation transcript:

(Simple Testbenches & Arithmetic Operations) EEL4712 Digital Design (Simple Testbenches & Arithmetic Operations) https://ece.gmu.edu/coursewebpages/ECE/ECE545/F18/ Thanks to Prof. Gaj for providing his course materials.

Testbench Defined Testbench = VHDL entity that applies stimuli (drives the inputs) to the Design Under Test (DUT) and (optionally) verifies expected outputs. The results can be viewed in a waveform window or written to a file. Since Testbench is written in VHDL, it is not restricted to a single simulation tool (portability). The same Testbench can be easily adapted to test different implementations (i.e. different architectures) of the same design.

Simple Testbench

Testbench The same testbench can be used to test multiple implementations of the same circuit (multiple architectures)

Testbench Anatomy ENTITY my_entity_tb IS --TB entity has no ports END my_entity_tb; ARCHITECTURE behavioral OF tb IS --Local signals and constants COMPONENT TestComp --All Design Under Test component declarations PORT ( ); END COMPONENT; ----------------------------------------------------- BEGIN DUT:TestComp PORT MAP( -- Instantiations of DUTs ); testSequence: PROCESS -- Input stimuli END PROCESS; END behavioral;

Testbench for XOR3 LIBRARY ieee; USE ieee.std_logic_1164.all; BEGIN UUT : xor3 PORT MAP ( A => test_vector(2), B => test_vector(1), C => test_vector(0), Result => test_result); ); Testing: PROCESS test_vector <= "000"; WAIT FOR 10 ns; test_vector <= "001"; test_vector <= "010"; test_vector <= "011"; test_vector <= "100"; test_vector <= "101"; test_vector <= "110"; test_vector <= "111"; END PROCESS; END behavioral; LIBRARY ieee; USE ieee.std_logic_1164.all; ENTITY xor3_tb IS END xor3_tb; ARCHITECTURE behavioral OF xor3_tb IS -- Component declaration of the tested unit COMPONENT xor3 PORT( A : IN STD_LOGIC; B : IN STD_LOGIC; C : IN STD_LOGIC; Result : OUT STD_LOGIC ); END COMPONENT; -- Stimulus signals - signals mapped to the input and inout ports of tested entity SIGNAL test_vector: STD_LOGIC_VECTOR(2 DOWNTO 0); SIGNAL test_result : STD_LOGIC;

Process without Sensitivity List and its use in Testbenches The execution of statements continues sequentially till the last statement in the process. After execution of the last statement, the control is again passed to the beginning of the process. Testing: PROCESS BEGIN test_vector<=“00”; WAIT FOR 10 ns; test_vector<=“01”; test_vector<=“10”; test_vector<=“11”; END PROCESS; Order of execution Program control is passed to the first statement after BEGIN

PROCESS with a WAIT Statement The last statement in the PROCESS is a WAIT instead of WAIT FOR 10 ns. This will cause the PROCESS to suspend indefinitely when the WAIT statement is executed. This form of WAIT can be used in a process included in a testbench when all possible combinations of inputs have been tested or a non-periodical signal has to be generated. Testing: PROCESS BEGIN test_vector<=“00”; WAIT FOR 10 ns; test_vector<=“01”; test_vector<=“10”; test_vector<=“11”; WAIT; END PROCESS; Order of execution Program execution stops here

WAIT FOR vs. WAIT WAIT FOR: waveform will keep repeating itself forever … 1 2 3 1 2 3 WAIT : waveform will keep its state after the last wait instruction. …

Generating selected values of one input SIGNAL test_vector : STD_LOGIC_VECTOR(2 downto 0); BEGIN ....... testing: PROCESS test_vector <= "000"; WAIT FOR 10 ns; test_vector <= "001"; test_vector <= "010"; test_vector <= "011"; test_vector <= "100"; END PROCESS; ........ END behavioral;

Generating all values of one input SIGNAL test_vector : STD_LOGIC_VECTOR(3 downto 0):="0000"; BEGIN ....... testing: PROCESS WAIT FOR 10 ns; test_vector <= test_vector + 1; end process TESTING; ........ END behavioral;

Generating all possible values of two inputs SIGNAL test_ab : STD_LOGIC_VECTOR(1 downto 0); SIGNAL test_sel : STD_LOGIC_VECTOR(1 downto 0); BEGIN ....... double_loop: PROCESS test_ab <="00"; test_sel <="00"; for I in 0 to 3 loop for J in 0 to 3 loop wait for 10 ns; test_ab <= test_ab + 1; end loop; test_sel <= test_sel + 1; END PROCESS; ........ END behavioral;

Generating periodical signals, such as clocks CONSTANT clk1_period : TIME := 20 ns; CONSTANT clk2_period : TIME := 200 ns; SIGNAL clk1 : STD_LOGIC; SIGNAL clk2 : STD_LOGIC := ‘0’; BEGIN ....... clk1_generator: PROCESS clk1 <= ‘0’; WAIT FOR clk1_period/2; clk1 <= ‘1’; END PROCESS; clk2 <= not clk2 after clk2_period/2; END behavioral;

Generating one-time signals, such as resets CONSTANT reset1_width : TIME := 100 ns; CONSTANT reset2_width : TIME := 150 ns; SIGNAL reset1 : STD_LOGIC; SIGNAL reset2 : STD_LOGIC := ‘1’; BEGIN ....... reset1_generator: PROCESS reset1 <= ‘1’; WAIT FOR reset_width; reset1 <= ‘0’; WAIT; END PROCESS; reset2_generator: PROCESS reset2 <= ‘0’; END behavioral;

Typical error SIGNAL test_vector : STD_LOGIC_VECTOR(2 downto 0); SIGNAL reset : STD_LOGIC; BEGIN ....... generator1: PROCESS reset <= ‘1’; WAIT FOR 100 ns reset <= ‘0’; test_vector <="000"; WAIT; END PROCESS; generator2: PROCESS WAIT FOR 200 ns test_vector <="001"; WAIT FOR 600 ns test_vector <="011"; END behavioral;

Arithmetic Operators in VHDL (1) To use basic arithmetic operations involving std_logic_vectors you need to include the following library packages: LIBRARY ieee; USE ieee.std_logic_1164.all; USE ieee.std_logic_unsigned.all; or USE ieee.std_logic_signed.all; Or USE ieee.numeric_std.all;

Arithmetic Operators in VHDL (2) You can use standard +, - operators to perform addition and subtraction: signal A : STD_LOGIC_VECTOR(3 downto 0); signal B : STD_LOGIC_VECTOR(3 downto 0); signal C : STD_LOGIC_VECTOR(3 downto 0); …… C <= A + B; Internal signals are from DUT. Main process may be split into main process. I.e. one to drive clk, rst and other for test vectors. Many architectures can be tested by inserting more for DUT:TestComp use entity work.TestComp(archName) statmetns “work” is the name of the library that “TestComp” is being compiled to. The “DUT” tag is required.

Different declarations for the same operator Declarations in the package ieee.std_logic_unsigned: function “+” ( L: std_logic_vector; R:std_logic_vector) return std_logic_vector; function “+” ( L: std_logic_vector; R: integer) return std_logic_vector; function “+” ( L: std_logic_vector; R:std_logic) return std_logic_vector;

Add Operation architecture BHV1 of add is begin library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; entity add is generic ( WIDTH: positive := 8); port( input1: in std_logic_vector (WIDTH-1 downto 0); input2: in std_logic_vector (WIDTH-1 downto 0); output: out std_logic_vector (WIDTH-1 downto 0); carry: out std_logic ); end add; architecture BHV1 of add is begin process (input1, input2) variable temp : std_logic_vector (WIDTH downto 0); temp := conv_std_logic_vector(unsigned(input1), WIDTH+1) + conv_std_logic_vector(unsigned(input2), WIDTH+1); output <= temp(WIDTH-1 downto 0); carry <= temp(WIDTH); end process; end BHV1;

Variables Used for Local storage in processes, functions, … Their scope is within the procedure that they have been defined Declararion variable list_of_variable_names : type_name [ := initial value ]; variable temp_var : std_logic_vector (WIDTH downto 0); Usage Variable_name := value; temp_var := ("0"&input1) + ("0"&input2);

Signals Must be declared outside a process Declaration form: signal list_of_signal_names : type_name [ := initial value ]; signal temp_sig : std_logic_vector(WIDTH downto 0); Declared in an architecture body and can be used anywhere within that architecture Usage temp_var <= ("0"&input1) + ("0"&input2);

Signals vs Variables Variables Signals The right-hand side expression is evaluated immediately and the variable is instantaneously updated (no delay) Signals The right-hand side expression is evaluated and the signal is scheduled to change after delay The signal value will be updated at the end of process (if the signal assignment is in the process)

Example: Signals vs Variables architecture BHV1 of add is varailable temp_var : std_logic_vector(WIDTH downto 0); begin process (input1, input2) temp_var := ("0"&input1) + ("0"&input2); output <= temp_var(WIDTH-1 downto 0); carry <= temp_var(WIDTH); end process; end BHV1; 1) temp_sig/temp_var = 0, input1 = 0, and input2 = 15 2) Input1 changes to 10 3) The sum of input1 and input2 (25) 4) Input1 changes to 20, causing the process to execute 6) Temp_sig is assigned the new value of 35, but the following lines will see the previous value of 25, causing the output to be set to 25. architecture BHV2 of add is signal temp_sig : std_logic_vector(WIDTH downto 0); begin process (input1, input2) temp_sig <= ("0"&input1) + ("0"&input2); output <= temp_sig(WIDTH-1 downto 0); carry <= temp_sig(WIDTH); end process; end BHV2;

Questions?