VHDL Programming in CprE 381 Zhao Zhang CprE 381, Fall 2013 Iowa State University Last update: 9/15/2013.

Slides:



Advertisements
Similar presentations
HDL Programming Fundamentals
Advertisements

What are FPGA Power Management HDL Coding Techniques Xilinx Training.
©2004 Brooks/Cole FIGURES FOR CHAPTER 20 VHDL FOR DIGITAL SYSTEM DESIGN Click the mouse to move to the next page. Use the ESC key to exit this chapter.
1/8/ VerilogCopyright Joanne DeGroat, ECE, OSU1 Verilog Overview An overview of the Verilog HDL.
L23 – Adder Architectures. Adders  Carry Lookahead adder  Carry select adder (staged)  Carry Multiplexed Adder  Ref: text Unit 15 9/2/2012 – ECE 3561.
VHDL in digital circuit synthesis (tutorial) dr inż. Miron Kłosowski EA 309
VHDL Lecture 1 Megan Peck EECS 443 Spring 08.
COE 405 VHDL Basics Dr. Aiman H. El-Maleh Computer Engineering Department King Fahd University of Petroleum & Minerals Dr. Aiman H. El-Maleh Computer Engineering.
1 Introduction to VHDL (Continued) EE19D. 2 Basic elements of a VHDL Model Package Declaration ENTITY (interface description) ARCHITECTURE (functionality)
Introduction To VHDL for Combinational Logic
INTRO TO VHDL Appendix A: page page VHDL is an IEEE and ANSI standard. VHDL stands for Very High Speed IC hardware description language.
Lecture #28 Page 1 ECE 4110– Sequential Logic Design Lecture #28 Agenda 1.Counters Announcements 1.HW #13 assigned 2.Next: Test #2 Review.
Multiplexers Section 3-7 Mano & Kime. Multiplexers & Demultiplexers Multiplexers (Selectors) Lab 1 – Behavioral VHDL -- Multiplexers MUX as a Universal.
Digital Logic with VHDL EE 230 Digital Systems Fall 2006 (10/17/2006)
LECTURE 4: The VHDL N-bit Adder
Digital Design with VHDL Presented by: Amir Masoud Gharehbaghi
VHDL Structural Architecture ENG241 Week #5 1. Fall 2012ENG241/Digital Design2 VHDL Design Styles Components and interconnects structural VHDL Design.
MO Prof. Paulo Cesar Centoducatte MC542 Organização de Computadores Teoria e Prática.
Generic Multiplexers: Parameters Discussion D2.5 Example 8.
Topics of Lecture Configuration Test Bench Encapsulation Structural Decomposition.
© Dr. Alaaeldin Amin 1 Hardware Modeling & Synthesis Using VHDL Very High Speed Integrated Circuits Start Of VHDL Development First Publication.
Dr. Turki F. Al-Somani VHDL synthesis and simulation – Part 2 Microcomputer Systems Design (Embedded Systems)
Managing design complexity Partition of designs Typical design process using VHDL Test Bed A VHDL example.
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.
N Structural Modeling: n Entities n Ports n Architectures n Packages.
Introduction to VHDL Multiplexers Discussion D1.1.
VHDL. What is VHDL? VHDL: VHSIC Hardware Description Language  VHSIC: Very High Speed Integrated Circuit 7/2/ R.H.Khade.
Simple Testbenches Behavioral Modeling of Combinational Logic
Dr. Turki F. Al-Somani VHDL synthesis and simulation – Part 1 Microcomputer Systems Design (Embedded Systems)
EE 367 – Logic Design Lecture #17
Fall 08, Oct 29ELEC Lecture 7 (updated) 1 Lecture 7: VHDL - Introduction ELEC 2200: Digital Logic Circuits Nitin Yogi
(1) Programming Mechanics © Sudhakar Yalamanchili, Georgia Institute of Technology, 2006.
ECE 332 Digital Electronics and Logic Design Lab Lab 5 VHDL Design Styles Testbenches.
ECE 448: Spring 12 Lab Midterm Exam Review. Part 1: Detailed discussion of a selected midterm from Spring Part 2: Review & discussion of common.
Graduate Computer Architecture I VHDL Structure and Testing Michael Sorensen.
L16 – Testbenches for state machines. VHDL Language Elements  More examples HDL coding of class examples Testbench for example  Testing of examples.
ENG6090 RCS1 ENG6090 Reconfigurable Computing Systems Hardware Description Languages Part 5: Modeling Structure.
VHDL Project I: Introduction to Testbench Design Matthew Murach Slides Available at:
VHDL IE- CSE. What do you understand by VHDL??  VHDL stands for VHSIC (Very High Speed Integrated Circuits) Hardware Description Language.
Digital Design with VHDL Presented by: Amir Masoud Gharehbaghi
Language Concepts Ver 1.1, Copyright 1997 TS, Inc. VHDL L a n g u a g e C o n c e p t s Page 1.
1/26 VHDL VHDL Structural Modeling Digital Logic.
Carry look ahead adder P (I) = a(I) xor b(I); G(I) = a(I) and b(I); S(I) = p(I) xor c(I); Carry(I+1) = c(I)p(I) + g(I)
CprE / ComS 583 Reconfigurable Computing Prof. Joseph Zambreno Department of Electrical and Computer Engineering Iowa State University Lecture #16 – Introduction.
Fall 2004EE 3563 Digital Systems Design EE 3563 VHDL – Basic Language Elements  Identifiers: –basic identifier: composed of a sequence of one or more.
Introduction to VHDL Spring EENG 2920 Digital Systems Design Introduction VHDL – VHSIC (Very high speed integrated circuit) Hardware Description.
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.
IAY 0600 Digital Systems Design VHDL discussion Verification: Testbenches Alexander Sudnitson Tallinn University of Technology.
Topics AliasesSubprograms Generics & Configurations.
Lecture #9 Page 1 Lecture #9 Agenda 1.VHDL : Structural Design Announcements 1.n/a ECE 4110– Digital Logic Design.
George Mason University Simple Testbenches ECE 545 Lecture 4.
1 Introduction to VHDL Part 2 Fall We will use Std_logic And, Or have same precedence See slide 8 of part 1.
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.
4-to-1 Multiplexer: Module Instantiation Discussion D2.2 Example 5.
2/10/07DSD,USIT,GGSIPU1 BCD adder KB3B2B1B0CD3D2D1D
CWRU EECS 318 EECS 318 CAD Computer Aided Design LECTURE 3: The VHDL N-bit Adder Instructor: Francis G. Wolff Case Western Reserve.
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.
George Mason University Behavioral Modeling of Sequential-Circuit Building Blocks ECE 545 Lecture 8.
Case Study: Xilinx Synthesis Tool (XST). Arrays & Records 2.
Describing Combinational Logic Using Processes
ECE 4110–5110 Digital System Design
Combinational Circuits Using VHDL
VHDL Discussion Subprograms
VHDL Structural Architecture
VHDL Discussion Subprograms
Hardware Modeling & Synthesis Using VHDL
4-Input Gates VHDL for Loops
System Controller Approach
Digital Logic with VHDL
Presentation transcript:

VHDL Programming in CprE 381 Zhao Zhang CprE 381, Fall 2013 Iowa State University Last update: 9/15/2013

VHDL Notes for Week 4 Generic Constant Entity and component Test bench

Generic Constant Generic constant is used to parameterize an entity entity one_complement is generic(constant N : integer := 16); port(i_A : in std_logic_vector(N-1 downto 0); o_F : out std_logic_vector(N-1 downto 0)); end one_complement; Can be added to entity Takes a default value

Generic Constant architecture behavior of tb_one_complement is component one_complement generic(constant N: integer := 32); port(i_A : in std_logic_vector(N-1 downto 0); o_F : out std_logic_vector(N-1 downto 0)); end component; … begin … The default value can be changed in a component statement

Generic Constant C1: entity work.one_complment(behavior) generic map (N => 32) port map (i_A => s_A, o_F => s_F); C1: one_complement generic map (N => 32) port map (i_A => s_A, o_F => s_F); The generic constant value can also be decided in a component instantiation statement

Entity and Component Be default a component is associated with an entity of the same name Component can be configured in configuration specification to associate with an entity and an architecture for C1 : one_complement use entity work.one_complment(behavior) for all : one_complement use entity work.one_complment(behavior)

Generate Statement A for…generate statement may used in an architecture to instantiate an array of component instances G1: for i in 0 to N-1 generate inv_array: inv port map(i_A => i_A(i), o_F => o_F(i)); end generate;

Generic Example architecture structure of one_complement is component inv port(i_A : in std_logic; o_F : out std_logic); end component; begin G1: for i in 0 to N-1 generate inv_i: inv port map(i_A => i_A(i), o_F => o_F(i)); end generate; end structure;

Test Bench Test bench provides stimulus to the simulation Its entity statement is usually empty entity tb_one_complement is end tb_one_complement;

Test Bench architecture behavior of tb_one_complement is … -- components, signals, component instances -- The test sequence process begin s_A <= X" "; wait for 100 ns; s_A <= X" "; wait for 100 ns; end process; -- it repeats end behavior;

VHDL Notes for Week 5 Mixing VHDL styles: Structure, data flow, behavior Model a truth table Model a register file

VHDL Notes in 381 I will discuss VHDL programming techniques just for the need of CprE 381 – The notes are customized for the labs – I’m not a VHDL expert (used to program in Verilog) Take the notes as exposure to new techniques – The notes will only cover the essential of each technique – Search Internet or get a good VHDL book, for the complete description and details – The “VHDL tutorial” is a good starting point but may not be sufficient

Structure, Dataflow and Behavior Those are different ways to model a hardware component entity my_circuit is port(i1, i2, i3, i4 : in bit; o : out bit); end my_circuit;

Structure, Dataflow and Behavior architecture mixed of my_circuit is signal wire1, wire2 : bit; begin nand_gate1 : entity work.nand2(dataflow) port map (i1, i2, wire1); nand_gata2 : block begin wire2 <= i1 nand i2; end block; nand_data3 : process (wire1, wire2) begin if (wire1 = ‘1’) and (wire2 = ‘1’) then o <= ‘0’; else o <= ‘1’; end if; end process; end

Structure, Data Flow and Behavior The previous example mixes three modeling styles: structure, data flow, and behavior It uses three VHDL programming constructs (complex statements), each for a NAND gate – Component/entity instantiation – Concurrent signal assignment – Process statement The logic circuits can be the same – Different modeling styles may or may not lead to the same circuit

Model Truth Table Use case statement (behavior) architecture behavior of reg_decoder is begin -- input : 5-bit addr; output: 32-bit sel D : process (addr) begin case (addr) is when b”00000” => sel <= x” ”; when b”00001” => sel <= x” ”; … -- more cases when b”11111” => sel <= x” ”; end case; end process; end behavior;

Model Truth Table Use selected signal statement (data flow) architecture dataflow of reg_decoder is begin -- input : 5-bit addr; output: 32-bit sel with addr select sel <= x” ” when b”00000”, x” ” when b”00001”, … -- more cases x” ” when bb”11111”; end dataflow;

Model Regfile A simplest way to mode register file is to use two process statements, with an array of 32- bit internal signals – Not acceptable if you do it for Lab 3 assignment

Model Regfile architecture behavior of regfile is signal reg_array : m32_regval_array; begin REG_READ : process (clk, src1, src2) variable r1, r2 : integer; begin r1 := to_integer(unsigned(src1)); r2 := to_integer(unsigned(src2)); rdata1 <= reg_array(r1); rdata2 <= reg_array(r2); end process; Continue…

Model Regfile Continue… REG_WRITE : process (clk) variable r : integer; begin if (rising_edge(clk)) then if (WE = '1') then r := to_integer(unsigned(dst)); reg_array(r) <= wdata; end if; end process; end behavior;

Lab 4 This Week Part 1: Sign and Zero extension – You will need both in Mini-Projects B and C What extension is needed in J instruction What extension is needed in BNE instruction? Part 2: Test a given memory implementation – It is like using an IP from other designers – Write your test carefully, make sure it really works

Multiple Testing Processes In a test bench, we may use multiple process statements Example: Use two processes in REGFILE test bench – One process for generating clock signal – Another for providing control and data signals

Multiple Testing Processes entity tb_reg32 is -- This is a single reg -- Half clock Cycle Time generic (HCT : time := 50 ns); end tb_reg32; architecture behavior of tb_reg32 is -- Clock Cycle Time constant CCT : time := 2 * HCT; -- Component and signal declarations …

Multiple Testing Processes begin REG_A: reg32 port map (clk, rst, WE, D, Q); P_CLK : process -- Clock generation begin clk <= '0'; wait for HCT; -- Wait for half clock cycle clk <= '1'; wait for HCT; -- Wait for half clock cycle end process;

Multiple Testing Processes P_DATA : process begin -- Reset the register rst <= '1'; wait for CCT; rst <= '0'; -- Write hex 0x WE <= '1'; D <= X" "; wait for CCT;

Multiple Testing Processes -- Test with WE = ‘0’ WE <= '0'; D <= X" "; wait for CCT; -- More stimulus … end process; end behavior;

Assert Statements assert condition report message severity level; If the condition is false, report a message, and potentially stop the simulation Can be useful in test bench for automatic testing – No need to read the waveform all the time – Help you quickly identify errors Can also be used to self-check a logic circuit

Assert Statement Example: Use report and assert statements inside a testing process -- Test register write report “Test on input 0x ”; WE <= '1'; D <= X" "; wait for CCT; assert(Q = X" ") report ”Fail on input 0x ”;

Assert Statement Use severity level to tell the simulator whether to stop. assert(Q = X" ") report "Test input 0x ” severity ERROR; Four severity levels and ModelSim behavior note:Just print the message warning:Print “warning” message error:Print “error” message (default) failure:Print “failure” message, break/pause the simulation

Report Statement You can also use report statements like printf – Note: You may need functions to convert std_logic_vector to integer, e.g. hex() – You may search the Internet or contact Dr. Zhang for the code TEST : process begin … report “rdata1 = “ & hex(rdata1) “rdata2 = “ & hex(rdata2); … end process;

Debugging Single-Cycle Processor General debugging skills Pause the simulation and inspect signals Inspect register and memory contents Be selective with waveform signals: There are too many signals! Pause simulation and inspect signals at the right time, avoiding the rising clock edges

Debugging Single-Cycle Processor Check the outcome of an instruction to see if it runs correctly – Check PC for all instructions – Check dest register for R-Type and load – Check memory word for store – Test taken and not-taken cases for branch

Debugging Single-Cycle Processor Suggest strategy 1: Trace instruction execution in forward direction. Check: – PC and instruction memory output – rs, rt, shamt, funct, immediate – All control signals – Register read data – ALU inputs and outputs – Data memory address, data input, data output – Register write data – And other signals

Debugging Single-Cycle Processor Suggest strategy 2: Trace instruction execution in backward direction. The tracing can be more focused

Debugging Single-Cycle Processor A case of debugging: For code lw $t0, 0($zero) lw $t1, 4($zero) The first instruction runs correctly, the second doesn’t. Check on the second instruction: Memory address: It is 0x , not 0x ! ALU result (address): it is indeed 0x (wrong) ALU inputs – rdata1 = 0x : OK – alu_input2 = 0x : OK – ALU_code = "0000”: Wrong! That's AND operation

Debugging Single-Cycle Processor Continue to check: ALUop = "00”: OK Something is wrong with ALU control, continue: Check inside of alu_ctrl.vhd: – I used ‘X’ in programming the truth table – Thought ‘X’ is “don't care”. No, that's Verilog! – In VHDL std_logic, ‘X’ is “unknown”, and "-" is “don't care”! Then learned that VHDL 2002 doesn't support matching '0' or '1' with X in case statement – VHDL 2008 does support this feature – ModelSim (PE 10.2c) supports VHDL 2002 by default Change a programming technique and then it works