Tutorial 4 HDL. Outline VHDL PROCESS. Modeling Combinational Logic. Structural Description Instantiation and Interconnection Hierarchy

Similar documents
CS221: VHDL Models & Synthesis

CS221: VHDL Introduction

Synthesis of Digital Systems CS 411N / CSL 719. Part 3: Hardware Description Languages - VHDL

LECTURE 4: The VHDL N-bit Adder

Concurrent Signal Assignment Statements (CSAs)

In our case Dr. Johnson is setting the best practices

Computer-Aided Digital System Design VHDL

CS221: VHDL Introduction

COE 405, Term 062. Design & Modeling of Digital Systems. HW# 1 Solution. Due date: Wednesday, March. 14

Declarations of Components and Entities are similar Components are virtual design entities entity OR_3 is

UNIT I Introduction to VHDL VHDL: - V -VHSIC, H - Hardware, D - Description, L Language Fundamental section of a basic VHDL code Library :

Hardware Description Language VHDL (1) Introduction

Abi Farsoni, Department of Nuclear Engineering and Radiation Health Physics, Oregon State University

VHDL: A Crash Course

IE1204 Digital Design L7: Combinational circuits, Introduction to VHDL

VHDL Examples Mohamed Zaky

Summary of FPGA & VHDL

VHDL. ELEC 418 Advanced Digital Systems Dr. Ron Hayne. Images Courtesy of Cengage Learning

Mridula Allani Fall Fall

310/ ICTP-INFN Advanced Tranining Course on FPGA and VHDL for Hardware Simulation and Synthesis 27 November - 22 December 2006

Advanced Training Course on FPGA Design and VHDL for Hardware Simulation and Synthesis. 26 October - 20 November, 2009

-- Fill in values for each generic. -- Fill in values for each signal. SIGNAL load_start : std_ulogic := '1'; SIGNAL clock : std_ulogic := '0';

Lattice VHDL Training

EITF35: Introduction to Structured VLSI Design

Hardware Description Languages. Modeling Complex Systems

VHDL for FPGA Design. by : Mohamed Samy

Hardware Modeling. VHDL Basics. ECS Group, TU Wien

Quartus Counter Example. Last updated 9/6/18

Review of Digital Design with VHDL

Lecture 7. Standard ICs FPGA (Field Programmable Gate Array) VHDL (Very-high-speed integrated circuits. Hardware Description Language)

VHDL Testbench. Test Bench Syntax. VHDL Testbench Tutorial 1. Contents

Digital Systems Design

Arithmetic Circuits. Nurul Hazlina Adder 2. Multiplier 3. Arithmetic Logic Unit (ALU) 4. HDL for Arithmetic Circuit

VHDL 2 Combinational Logic Circuits. Reference: Roth/John Text: Chapter 2

1 ST SUMMER SCHOOL: VHDL BOOTCAMP PISA, JULY 2013

VHDL in 1h. Martin Schöberl

Introduction to VHDL. Yvonne Avilés Colaboration: Irvin Ortiz Flores Rapid System Prototyping Laboratory (RASP) University of Puerto Rico at Mayaguez

Lecture 3: Modeling in VHDL. EE 3610 Digital Systems

Lecture 5: State Machines, Arrays, Loops. EE 3610 Digital Systems

FSM Components. FSM Description. HDL Coding Methods. Chapter 7: HDL Coding Techniques

EEL 4783: Hardware/Software Co-design with FPGAs

Review. LIBRARY list of library names; USE library.package.object; ENTITY entity_name IS generic declarations PORT ( signal_name(s): mode signal_type;

Two HDLs used today VHDL. Why VHDL? Introduction to Structured VLSI Design

Sequential Statement

COVER SHEET: Total: Regrade Info: 5 (14 points) 7 (15 points) Midterm 1 Spring 2012 VERSION 1 UFID:

Modeling Complex Behavior

VHDL. VHDL History. Why VHDL? Introduction to Structured VLSI Design. Very High Speed Integrated Circuit (VHSIC) Hardware Description Language

Lecture 4: Modeling in VHDL (Continued ) EE 3610 Digital Systems

Getting Started with VHDL

Introduction to VHDL #3

CCE 3202 Advanced Digital System Design

The block diagram representation is given below: The output equation of a 2x1 multiplexer is given below:

Basic Language Concepts

What Is VHDL? VHSIC (Very High Speed Integrated Circuit) Hardware Description Language IEEE 1076 standard (1987, 1993)

2/14/2016. Hardware Synthesis. Midia Reshadi. CE Department. Entities, Architectures, and Coding.

ECE 545 Lecture 6. Behavioral Modeling of Sequential-Circuit Building Blocks. George Mason University

Digital Design Laboratory Lecture 2

COE 405 Design Methodology Based on VHDL

VHDL And Synthesis Review

Assignment. Last time. Last time. ECE 4514 Digital Design II. Back to the big picture. Back to the big picture

VHDL Structural Modeling II

3 Designing Digital Systems with Algorithmic State Machine Charts

ECE Digital Design Laboratory. Lecture 3 Finite State Machines!

ECE 448 Lecture 4. Sequential-Circuit Building Blocks. Mixing Description Styles

Timing in synchronous systems

EE261: Intro to Digital Design

EECS150 - Digital Design Lecture 5 - Verilog Logic Synthesis

COVER SHEET: Total: Regrade Info: 5 (5 points) 2 (8 points) 6 (10 points) 7b (13 points) 7c (13 points) 7d (13 points)

Reconfigurable Hardware Design (coursework)

EITF35: Introduction to Structured VLSI Design

EECE-4740/5740 Advanced VHDL and FPGA Design. Lecture 3 Concurrent and sequential statements

IT T35 Digital system desigm y - ii /s - iii

Digital Design Using VHDL Using Xilinx s Tool for Synthesis and ModelSim for Verification

SRI SUKHMANI INSTITUTE OF ENGINEERING AND TECHNOLOGY, DERA BASSI (MOHALI)

ECE 448 Lecture 3. Combinational-Circuit Building Blocks. Data Flow Modeling of Combinational Logic

Sequential Logic - Module 5

VHDL: Code Structure. 1

C-Based Hardware Design

Elektrotechnik und Informationstechnik, Stiftungsprofessur hochparallele VLSI Systeme und Neuromikroelektronik. Oberseminar Informationstechnik

ECE 545 Lecture 5. Data Flow Modeling in VHDL. George Mason University

Luleå University of Technology Kurskod SMD152 Datum Skrivtid

Sudhakar Yalamanchili, Georgia Institute of Technology, 2006

SEQUENTIAL STATEMENTS

JUNE, JULY 2013 Fundamentals of HDL (10EC45) PART A

Lab 1 Modular Design and Testbench Simulation ENGIN 341 Advanced Digital Design University of Massachusetts Boston

CS211 Digital Systems/Lab. Introduction to VHDL. Hyotaek Shim, Computer Architecture Laboratory

ECE 448 Lecture 3. Combinational-Circuit Building Blocks. Data Flow Modeling of Combinational Logic

ECEU530. Last Few Lectures. ECE U530 Digital Hardware Synthesis. What is on Quiz 2. Projects. Today:

A bird s eye view on VHDL!

Field Programmable Gate Array

VHDL VS VERILOG.

A Brief Introduction to Verilog Hardware Definition Language (HDL)

ELE432. ADVANCED DIGITAL DESIGN HACETTEPE UNIVERSITY Designing with VHDL

EEE8076. Reconfigurable Hardware Design (coursework) Module Outline. Dr A. Bystrov Dr. E.G. Chester. Autumn

COVER SHEET: Total: Regrade Info: 2 (6 points) 3 (8 points) 4 (10 points) 8 (12 points) 6 (6 points) 7 (6 points) 9 (30 points) 10 (4 points)

Chapter 6 Combinational-Circuit Building Blocks

CSE140L: Components and Design Techniques for Digital Systems Lab. Verilog HDL. Instructor: Mohsen Imani UC San Diego. Source: Eric Crabill, Xilinx

Advanced Digital Design Spring 2011 Final Examination Time Limit: 2 Hours

ECE 545 Lecture 8. Data Flow Description of Combinational-Circuit Building Blocks. George Mason University

CMPT 250: Computer Architecture. Using LogicWorks 5. Tutorial Part 1. Somsubhra Sharangi

Transcription:

CS3: Hardware Lab Tutorial 4 HDL Outline VHDL basic language concepts basic design methodology Examples A. Sahu Dept of Comp. Sc. & Engg. Indian Institute of Technology Guwahati i i i3 i4 Modeling Combinational Logic One concurrent assignment for each output o o o3 o4 ARCHITECTURE data_flow OF comb_logic IS o <= i and i; o <= (i or i3) xor (i and i4); o3 <=...; o4 <=...; END data_flow; 3 VHDL PROCESS PROCESS is sequential Processes are concurrent w.r.t each other Signal assignment is a simple special case Architecture consists of a set of Processes (and signal assignments) at top level Processes communicate using signals ARCHITECTURE x of a IS f <= g+ ; p: PROCESS IF (x) THEN... ELSE...;... p: PROCESS FOR i in TO 5 LOOP a (i) <= 0; ENDL LOOP;... END x; 4 a b Structural Description Instantiation and Interconnection Hierarchy ENTITY x IS PORT (a, b: IN BIT, c: OUT BIT); END x; ARCHITECTURE xa OF x IS c <= a AND b; END xa; X c Y ENTITY y IS PORT (a : IN BIT, b: OUT BIT); END y; ARCHITECTURE ya OF y IS b <= NOT a; END xa; X Z Y z contains instances Of x and y 5 Generics VHDL Models Entity Ports Architecture Architecture Architecture (structural) Concurrent Statements Concurrent Statements Process Sequential Statements

Boolean Equations For concurrent signal assignments Concurrent Statements Three types of concurrent statements used in dataflow descriptions with select when For selective signal assignments when else For conditional signal assignments Sequential Statements Sequential statements are contained in a process, function, or procedure. Inside a process signal assignment is sequential from a simulation point of view. The order in which signal assignments are listed does affect the result. Sequential Statements 4 ways to DO IT the VHDL way if the else Four types of sequential statements used in behavioral descriptions case when for loop while loop Dataflow when else, when RTL Clocked, Transfers Behavioral Process, For loop, While loop, if then else Structural Using Components Mixed : Instantiation and Interconnection ENTITY z IS PORT (p, q: IN BIT, r: OUT BIT); END x; ARCHITECTURE structural OF z IS COMPONENT xc PORT (a, b: IN BIT; c: OUT BIT); COMPONENT yc PORT (a, b: IN BIT; c: OUT BIT); FOR ALL: xc USE WORK.x (xa); FOR ALL: yc USE WORK.y (ya); SIGNAL t: BIT; x: xc PORT MAP (p, q, t); y: yc PORT MAP (t, r); END structural; X Z Y Component declaration Configuration specification (which architecture?) Temporary signal Instantiation Instantiation and Interconnection a b Instance name Component name x: xc PORT MAP (p, q, t); y: yc PORT MAP (t, r); X Same name implies connection c X Z Y Port association list: order of names determines connectivity: a p b q c t

Port Mapping COMPONENT xc PORT (a, b: IN BIT; c: OUT BIT); Mapping by position: preferred for short port lists x: xc PORT MAP (p, q, t); Mapping by name: preferred for long port lists x: xc PORT MAP (b => q, a => p, c => t); Test Benches Purpose test correctness of Design Under Test (DUT) provide input stimulus observe outputs compare against expected outputs Test Bench is also a VHDL model In both cases, complete port mapping should be specified 3 4 Test bench for Adder Test bench For (i=0;i<8;i++){ wait 0ns Read (Truth Table) Send read A, B, Ci } Receive S,Co from adder Compare with expected if (error found) Report Error Expected S Expected Co A B Ci Adder Compare result S Co 5 Test Bench Modelling Test Bench Signals Design Under Test (DUT) Test bench a separate VHDL entity Ports are connected to DUT s ports i/p port corresponding to DUT s o/p port o/p port corresponding to DUT s i/p port Test bench instantiates the DUT Stimulus generation and output monitoring in a separate VHDL process Signals are connected to DUT s ports 6 Libraries and Packages PACKAGE collection of Components data types functions/procedures LIBRARY collection of PACKAGEs 7 Packages PACKAGE util IS COMPONENT c IS PORT (a: IN BIT, b: OUT BIT); END COMPONENT TYPE my_int IS INTEGER RANGE 7 TO 7; FUNCTION comp (a: BIT_VECTOR) RETURN BIT_VECTOR; END util; PACKAGE BODY util IS FUNCTION comp (a: BIT_VECTOR) RETURN BIT_VECTOR IS RETURN NOT a; END comp; END util; Package Declaration Package Body 8 3

Using a Package PACKAGE util IS COMPONENT c IS PORT (a: IN BIT,, b: OUT BIT); END COMPONENT TYPE my_int IS INTEGER RANGE 7 TO 7; FUNCTION comp (a: BIT_VECTOR) RETURN BIT_VECTOR; END util; Library Name Package Name All Contents USE WORK.UTIL.ALL;... SIGNAL x: my_int; a = comp (b); Libraries STD STANDARD : types/utilities (BIT, TIME, INTEGER,...) TEXTIO interface to text files WORK default library for storing user designs STD_LOGIC_64 multi valued logic 9 0 TEXTIO Package Design Parameterization: GENERIC & GENERATE Data types and functions for reading from text files writing out text files FILE f: TEXT IS file_name name ; VARIABLE one_line: line; VARIABLE str: STRING;... READLINE (f, one_line); read one line from file READ (str, one_line); read a word from line WRITELINE (g, one_line); write one line to file WRITE (str, one_line); write a word into line ENTITY e IS GENERIC (delay: TIME := NS; width: INTEGER := 4); PORT (a: IN BIT_VECTOR (0 TO width); b: OUT BIT_VECTOR (0 TO width) ); END e; ARCHITECTURE a OF e IS b <= NOT a AFTER delay; END a; Default Value Generic Parameters Passing GENERIC Parameters ENTITY c IS GENERIC (delay: TIME := 4 ns); PORT (a: IN BIT; b: OUT BIT); END c; ARCHITECTURE a OF e IS COMPONENT c GENERIC (t: TIME:= 4 NS); PORT (a: IN BIT, b: OUT BIT); SIGNAL x, y: BIT; FOR ALL: c USE work.c (arc); c: c GENERIC MAP (3 ns) PORT MAP (x, y); END a; Delay Parameter 3ns ARCHITECTURE def OF e IS COMPONENT c GENERIC (t: TIME:= 4 NS); PORT (a: IN BIT, b: OUT BIT); SIGNAL x, y: BIT; FOR ALL: c USE work.c (arc); c: c PORT MAP (x, y); END def; Delay Default Value 4ns 3 Inp CLK GENERATE: Conditional and Looped Instantiation Number of instances of DFF determined by Generic Parameter n 0 N Outp 4 4

Inp CLK GENERATE: Conditional and Looped Instantiation GENERIC (n: INTEGER)...... SIGNAL t: BIT_VECTOR (0 TO n ); 0 t(0) t() t() t(n ) Need intermediate signal t (0 to n ) N Outp Inp GENERATE Statement SIGNAL t: BIT_VECTOR (0 TO n );... dff_0: DFF PORT MAP (Inp, Clk, t (0)); dff_n: DFF PORT MAP (t (n ), Clk, Outp); FOR i IN TO n GENERATE dff_i: DFF PORT MAP ( t (i ), Clk, t (i) ); END GENERATE; 0 N Outp CLK 5 6 N Bit Ripple Carry Adder: FA ENTITY full_adder IS PORT (a, b, c_in: IN std_logic; Sum, Carry: OUT std_logic ); END full_adder; N Bit Ripple Carry Adder ENTITY adder_bits_n IS GENERIC(n: INTEGER := ); ARCHITECTUREfull_adder_arch_ OF full_adder IS SIGNAL S, S, S3: std_logic; s3 <= ( a AND b ) after 5 ns; s <= ( c_in AND s ) after 5 ns; s <= ( a XOR b ) after 5 ns; Carry <= ( s OR s3 ) after 5 ns; Sum <= ( s XOR c_in ) after 5 ns; END full_adder_arch_; 7 PORT ( Cin: IN std_logic; a, b: IN std_logic_vector(n downto 0); S: OUT std_logic_vector(n downto 0); Cout: OUT std_logic ); END; 8 N Bit Ripple Carry Adder ARCHITECTURE ripple_n_arch OF adder_bits_n IS COMPONENT full_adder PORT (x, y, z: IN std_logic; Sum, Carry: OUT std_logic); Test benches for 4 bit adder: Stimulus only ARCHITECTURE tbof tb_adder_4 IS COMPONENT adder_bits_n GENERIC(n: INTEGER := ); PORT ( Cin: IN std_logic; a, b: IN std_logic_vector(n downto0); S: OUT std_logic_vector(n downto 0); Cout: OUT std_logic); SIGNAL t: std_logic_vector(n downto 0); t(0) <= Cin; Cout <= t(n); FA: FOR i in 0 to n GENERATE FA_i: full_adder PORT MAP (t(i), a(i), b(i), S(i), t(i+)); end generate; END; 9 SIGNAL x, y, Sum: std_logic_vector(n downto 0); SIGNAL c, Cout: std_logic; x <= 0000, 000 after 00 ns, 00, after 400 ns; y <= 000, 00 after 00 ns, 00, after 400 ns; c <=, 0 after 00 ns; UUT_ADDER_4: adder_bits_n GENERIC MAP(4) PORT MAP (c, x, y, Sum, Cout); END 30 5

Data Flow: Full Adder ENTITY full_adder IS PORT (a, b, c_in: IN std_logic; Sum, Carry: OUT std_logic ); END full_adder; ARCHITECTURE Data_Flow OF full_adder IS SIGNAL S, S, S3: std_logic; s3 <= ( a AND b ) after 5 ns; s <= ( c_in AND s ) after 5 ns; s <= ( a XOR b ) after 5 ns; Carry <= ( s OR s3 ) after 5 ns; Sum <= ( s XOR c_in ) after 5 ns; END full_adder_arch_; 3 Components : FA Architecture structural of Full_adder is component XOR_GATE is port( X, Y : in std_logic; F: out std_logic ); end component; component AND_GATE is port( X, Y : in std_logic; F: out std_logic ); end component; component OR_GATE is.. signal s, s.s3: std_logic; signal just like wire Begin XOR: XOR_GATE port map (a, b, s); AND: AND_GATE port map (a, b, s3); AND : AND_GATE port map(c_in, s, s); OR : OR_GATE port map (s,s3, Carry); XOR: XOR_GATE port map (s,c_in, Sum); end structural; 3 Behavioral Model architecture BEHAV_FA of FULL_ADDER is signal int, int, int3: std_logic; Begin Process P that defines the first half adder P: process (A, B) int<= A xor B; int<= A and B; end process; Process P that defines the second half adder and the OR gate P: process (int, int, Cin) Sum <= int xor Cin; int3 <= int and Cin; Cout <= int or int3; end process; end BEHAV_FA; 33 Resister entity regis is port( rst, clk, load: in std_logic; input: in std_logic_vector( 3 downto 0 ); output: out std_logic_vector( 3 downto 0 ) ); end regis; architecture regis_arc of regis is process( rst, clk, load, input ) if( rst = '' ) then output <= "0000"; elsif( clk'event and clk = '') then if( load = '' ) then output <= input; end if; end if; end process; end regis_arc; 34 i =0 Simple FSM Design Example in VHDL Design a FSM that output iff the number of input sequence is odd i = i =0 S/0 S/ i = ENTITY FSM_Parity IS PORT (i: IN std_logic; o: OUT std_logic; CLK: IN std_logic; --Clock RST: IN std_logic --Reset ); END; Alternative: Less coding ARCHITECTURE FSM_Parity_arch OF FSM_Parity IS TYPE FSMStates IS (s, s); SIGNAL State, NextState: FSMStates; PROCESS (State, i) CASE State IS Important Note: every input to the state machine must be in the PROCESS sensitivity list WHEN s => if i= then NextState <= s; Important else NextState <= s; end if; o <= 0 ; WHEN s => if i= then NextState <= s; else NextState <= s; end if; o <= ; WHEN OTHERS => o <= ; NextState <= NextState; END CASE; Note: every WHEN must assign the same set of signals: i.e. NextState and o. if you miss one assignment latches will show up! 6

FSM controller: NextState Process PROCESS (CLK, RST) IF RST='' THEN -- Asynchronous Reset State <= s; ELSIF rising_edge(clk) THEN State <= NextState; END IF; END ARCHITECTURE; Init How to Write FSM is VHDL S0 S S 00000 000 xxx00 C= 0 C= S4 000 C= 0 S3 000 S5 ENTITY fsm IS PORT( rst, clk, proceed : IN std_logic; comparison: IN std_logic_vector( DOWNTO 0 ); enable, xsel, ysel, xld, yld: OUT std_logic ); END fsm; 38 FSM Architecture ARCHITECTURE fsm_arc OF fsm IS TYPE states IS ( init, s0, s, s, s3, s4, s5 ); SIGNAL nstate, cstate: states; Process: PROCESS( rst, clk ) IF( rst = '' ) THEN cstate <= init; ELSIF( clk'event and clk = '' ) THEN cstate <= nstate; END IF; 39 FSM Architecture: Continued Process: process( proceed, comparison, cstate ) variable : OP : std_loic_vector (4 downto 0); case cstate is when init => if( proceed = '0 ) then nstate <= init; else nstate <= s0; end if; when s0 => OP <= 00000 ; nstate <= s; when s => OP <= 0000 ; nstate <= s; when s => OP<= XXX0 ; if( comparison = "0" ) then nstate <= s3; elsif( comparison = "0" ) then nstate <= s4; elsif( comparison = "" ) then nstate <= s5; end if; when s3 => OP <= 000 nstate <= s; when s4 => OP <= 000 ; nstate <= s; when s5 => OP <= ; nstate <= s0; when others => nstate <= s0; end case; enable <= OP(4); xsel <= OP(3);ysel <= OP();xld <= OP();yld <= OP(0); end process; end fsm_arc; 40 Advanced topic related to FPGA How to use inbuilt components of FPGA? Block RAM, DSP Slices Vivado/ISE use by default based on your HDL coding sytle How to use PC to FPGA Communication : Via USB? So that, you can use the FPGA board as application accelerator How to use other part of FPGA Board? Network, HDMI, AV Port and Codecs Block RAM inferable code: RAM Example ENTITY ram_example IS PORT (Clk : in std_logic; address : in integer; we : in std_ logic; data_i : in BIT(7 DOWNTO 0); data_o : out BIT(7 DOWNTO 0) ); END ram_example; 4 4 7

Block RAM inferable code: RAM Example ARCHITECTURE Behavioral OF ram_example IS TYPE ram_t IS array (0 to 55) OF BIT(7 DOWNTO 0); signal ram : ram_t := (others => (others => '0')); PROCESS(Clk) if(rising_edge(clk)) then if(we='') then ram(address) <= data_i; end if; data_o <= ram(address); end if; END Behavioral; 43 DSP Slices inferable code library IEEE; use IEEE.STD_LOGIC_64.ALL; use IEEE.numeric_std.ALL; ENTITY FunctionExample IS Port ( x,x : IN BIT(7 downto 0); C : OUT BIT (9 downto 0)); END FunctionExample; ARCHITECTURE Behavioral OF FunctionExample IS constant A: integer:= 4; constant B: integer:= ; C <=TO_SIGNED(A*x + B*x,0); END Behavioral; 44 VHDL Tutorial Forwarded By Frank Vahid: Digital Design http://esd.cs.ucr.edu/labs/tutorial/ Google search VHDL Tutorial: Learn by Example Thanks 45 46 8