Fall 09, Aug 19 ELEC 5200-001/6200-001 Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 1 ELEC 5200-001/6200-001 Computer Architecture.

Slides:



Advertisements
Similar presentations
Digital Design with VHDL Presented by: Amir Masoud Gharehbaghi
Advertisements

History TTL-logic PAL (Programmable Array Logic)
Mridula Allani Fall 2010 (Refer to the comments if required) ELEC Fall 2010, Nov 21(Adopted from Profs. Nelson and Stroud)
Modeling & Simulating ASIC Designs with VHDL Reference: Smith text: Chapters 10 & 12.
VHDL ELEC 418 Advanced Digital Systems Dr. Ron Hayne Images Courtesy of Thomson Engineering.
Introduction to VHDL (Lecture #5) ECE 331 – Digital System Design The slides included herein were taken from the materials accompanying Fundamentals of.
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.
ECE C03 Lecture 18ECE C03 Lecture 61 Lecture 18 VHDL Modeling of Sequential Machines Prith Banerjee ECE C03 Advanced Digital Design Spring 1998.
Introduction to VHDL CSCE 496/896: Embedded Systems Witawas Srisa-an.
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.
CSCI 660 EEGN-CSCI 660 Introduction to VLSI Design Lecture 2 Khurram Kazi Some of the slides were taken from K Gaj ’ s lecture slides from GMU ’ s VHDL.
ECE C03 Lecture 141 Lecture 14 VHDL Modeling of Sequential Machines Hai Zhou ECE 303 Advanced Digital Design Spring 2002.
VHDL. What is VHDL? VHDL: VHSIC Hardware Description Language  VHSIC: Very High Speed Integrated Circuit 7/2/ R.H.Khade.
Fall 08, Oct 29ELEC Lecture 7 (updated) 1 Lecture 7: VHDL - Introduction ELEC 2200: Digital Logic Circuits Nitin Yogi
Introduction to VHDL (part 2)
1 H ardware D escription L anguages Basic Language Concepts.
VHDL Training ©1995 Cypress Semiconductor 1 Introduction  VHDL is used to:  document circuits  simulate circuits  synthesize design descriptions 
Data Flow Modeling of Combinational Logic Simple Testbenches
1 Part I: VHDL CODING. 2 Design StructureData TypesOperators and AttributesConcurrent DesignSequential DesignSignals and VariablesState Machines A VHDL.
VHDL TUTORIAL Preetha Thulasiraman ECE 223 Winter 2007.
1 H ardware D escription L anguages Modeling Complex Systems.
CprE / ComS 583 Reconfigurable Computing Prof. Joseph Zambreno Department of Electrical and Computer Engineering Iowa State University Lecture #17 – Introduction.
A VHDL Tutorial ENG2410. ENG241/VHDL Tutorial2 Goals Introduce the students to the following: –VHDL as Hardware description language. –How to describe.
ENG6090 RCS1 ENG6090 Reconfigurable Computing Systems Hardware Description Languages Part 5: Modeling Structure.
VHDL Introduction. V- VHSIC Very High Speed Integrated Circuit H- Hardware D- Description L- Language.
ELEC / Computer Architecture and Design Fall 2009 ELEC / Computer Architecture and Design Fall 2009 Modeling for Synthesis.
VHDL IE- CSE. What do you understand by VHDL??  VHDL stands for VHSIC (Very High Speed Integrated Circuits) Hardware Description Language.
陳慶瀚 機器智慧與自動化技術 (MIAT) 實驗室 國立中央大學資工系 2009 年 10 月 8 日 ESD-04 VHDL 硬體描述語言概論 VHDL Hardware Description Language.
Fall 2004EE 3563 Digital Systems Design EE 3563 VHSIC Hardware Description Language  Required Reading: –These Slides –VHDL Tutorial  Very High Speed.
VHDL Very High Speed Integrated Circuit Hardware Description Language Shiraz University of shiraz spring 2011.
Fall 08, Oct 29ELEC Lecture 7 (updated) 1 Lecture 7: VHDL - Introduction ELEC 2200: Digital Logic Circuits Nitin Yogi
HARDWARE DESCRIPTION LANGUAGE (HDL). What is HDL? A type of programming language for sampling and modeling of electronic & logic circuit designs It can.
M. Balakrishnan Dept of Computer Science & Engg. I.I.T. Delhi
(1) Basic Language Concepts © Sudhakar Yalamanchili, Georgia Institute of Technology, 2006.
Introduction to VHDL Simulation … Synthesis …. The digital design process… Initial specification Block diagram Final product Circuit equations Logic design.
Hardware Description Languages Digital Logic Design Instructor: Kasım Sinan YILDIRIM.
Hardware languages "Programming"-language for modelling of (digital) hardware 1 Two main languages: VHDL (Very High Speed Integrated Circuit Hardware Description.
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)
Data Storage VHDL ET062G & ET063G Lecture 4 Najeem Lawal 2012.
CEC 220 Digital Circuit Design VHDL in Sequential Logic Wednesday, March 25 CEC 220 Digital Circuit Design Slide 1 of 13.
VHDL Programming Fundamentals Presented By Dr. Pradyut Kumar Biswal Department of Electronics, IIIT Bhubaneswar.
May 9, 2001Systems Architecture I1 Systems Architecture I (CS ) Lab 5: Introduction to VHDL Jeremy R. Johnson May 9, 2001.
Modeling & Simulating ASIC Designs with VHDL Reference: Smith text: Chapters 10 & 12.
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.
Case Study: Xilinx Synthesis Tool (XST). Arrays & Records 2.
Data Flow and Behavioral Modeling in VHDL 1 MS EMBEDDED SYSTEMS.
An Introduction to V.H.D.L.. Need of a Compiler… main( ) { int x=10,y=20,z; z = x + y ; printf ( “ %d “, z ); getch( ) ; } What’s That ? Give me only.
Sequential statements (1) process
Basic Language Concepts
Subject Name: FUNDAMENTALS OF HDL Subject Code: 10EC45
Registers and Counters
Introduction Introduction to VHDL Entities Signals Data & Scalar Types
CHAPTER 17 VHDL FOR SEQUENTIAL LOGIC
Sequential-Circuit Building Blocks
CHAPTER 17 VHDL FOR SEQUENTIAL LOGIC
VHDL VHSIC Hardware Description Language VHSIC
RTL Style در RTL مدار ترتيبي به دو بخش (تركيبي و عناصر حافظه) تقسيم مي شود. مي توان براي هر بخش يك پروسس نوشت يا براي هر دو فقط يك پروسس نوشت. مرتضي صاحب.
ELEC 5200/6200 Computer Architecture and Design Review of VHDL
VHDL (VHSIC Hardware Description Language)
Behavioral Modeling of Sequential-Circuit Building Blocks
Sequntial-Circuit Building Blocks
Figure 8.1. The general form of a sequential circuit.
Modeling Complex Behavior
CprE / ComS 583 Reconfigurable Computing
Sequntial-Circuit Building Blocks
(Sequential-Circuit Building Blocks)
VHDL - Introduction.
Presentation transcript:

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 1 ELEC / Computer Architecture and Design Fall 2009 Review of VHDL Nitin Yogi 08/19/2009

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 2 HDLs in Digital System Design Model and document digital systems –Hierarchical models System, RTL (Register Transfer Level), gates –Different levels of abstraction Behavior, structure Verify circuit/system design via simulation Synthesize circuits from HDL models

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 3 Hardware Description Languages VHDL = VHSIC Hardware Description Language (VHSIC = Very High Speed Integrated Circuits) –Developed by DOD from 1983 – based on ADA –IEEE Standard /1993/200x –Based on the ADA language Verilog – created in 1984 by Philip Moorby of Gateway Design Automation (merged with Cadence) –IEEE Standard /2001/2005 –Based on the C language –IEEE P1800 “System Verilog” in voting stage & will be merged with 1364

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 4 Other VHDL Standards –1999: VHDL-AMS (Analog & Mixed- Signal Extensions) –1996: Std. VHDL Mathematics Packages : Std. VHDL Synthesis Packages : Std. VITAL Modeling Specification (VHDL Initiative Towards ASIC Libraries) : Std. for VHDL Register Transfer Level (RTL) Synthesis : Std. Multivalue Logic System for VHDL Model Interoperability

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 5 Anatomy of a VHDL model “Entity” describes the external view of a design/component “Architecture” describes the internal behavior/structure of the component Example: 1-bit full adder 1-bit full adder A B Cin Sum Cout Full Adder

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 6 Entity Inputs/Outputs External view comprises input/output signals (“ports”) A “port” is defined by its signal name, direction and type: port_name: direction data_type; port_name: direction data_type; –direction: in - driven into the entity from an external source out - driven from within the entity inout - bidirectional – drivers within the entity and external –data_type: any scalar or aggregate signal type

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 7 Built-in Data Types Scalar (single-value) signal types: –bit - values are ‘0’ or ‘1’ –boolean – values are TRUE and FALSE –integer Aggregate (multi-value) signal types: –bit_vector – array of bits signal b: bit_vector(7 downto 0); signal c: bit_vector(0 to 7);

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 8 IEEE Standard 1164 Data Types Type std_logic data values: ‘U’, ‘X’ – uninitialized/unknown ‘0’, ‘1’ – strongly-driven 0/1 ‘L’, ‘H’ – weakly-driven 0/1 (resistive) ‘Z’, ‘W’ - strong/weak “floating” ‘-’ - don’t care Type std_logic_vector is array of std_logic Include package: library IEEE; use IEEE.std_logic_1164.all;

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 9 User-Defined Data Types Any abstract data type can be created Examples: type mnemonic is (add,sub,mov,jmp); signal op: mnemonic; type byte is array(0 to 7) of bit; signal dbus: byte;

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 10 entity format entity entity_name is generic (optional) (generic_name: type :=default_value; … generic_name: mode signal_type); port (signal_name: mode signal_type; … signal_name: mode signal_type); end entity entity_name;

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 11 entity example (1-Bit Full Adder) entity full_add1 is port ( -- I/O ports port ( -- I/O ports a: in bit; -- a input a: in bit; -- a input b: in bit; -- b input b: in bit; -- b input cin: in bit; -- carry input cin: in bit; -- carry input sum: out bit; -- sum output sum: out bit; -- sum output cout: out bit); -- carry output cout: out bit); -- carry output end full_add1 ; A B Cin Sum Cout Full Adder

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 12 architecture format architecture architecture_name of entity_name is -- data type definitions (ie, states, arrays, etc.) -- internal signal declarations -- component declarations -- function and procedure declarations begin -- behavior of the model is described here using: -- component instantiations -- concurrent statements -- processes end architecture architecture_name;

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 13 architecture example (behavioral) architecture dataflow of full_add1 is begin sum <= a xor b xor cin after 1 ns; cout <= (a and b) or (a and cin) or cout <= (a and b) or (a and cin) or (b and cin) after 1 ns; end;

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 14 Example using an internal signal architecture dataflow of full_add1 is signal x1: bit;-- internal signal signal x1: bit;-- internal signalbegin x1 <= a xor b after 1 ns; sum <= x1 xor cin after 1 ns; cout <= (a and b) or (a and cin) or cout <= (a and b) or (a and cin) or (b and cin) after 1 ns; end;

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 15 Event-Driven Simulation Example a <= b after 1ns; c <= a after 1ns; Time a b c T ‘0’ ‘0’ ‘0’ T ‘0’ ‘0’ ‘0’ T+1 ‘0’ ‘1’ ‘0’ - external event on b T+1 ‘0’ ‘1’ ‘0’ - external event on b T+2 ‘1’ ‘1’ ‘0’ - resulting event on a T+2 ‘1’ ‘1’ ‘0’ - resulting event on a T+3 ‘1’ ‘1’ ‘1’ - resulting event on c T+3 ‘1’ ‘1’ ‘1’ - resulting event on c

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 16 architecture example (Structural ) architecture structure of full_add1 is component xor is-- declare component to be used port (x,y: in bit; z: out bit); end component xor; signal x1: bit;-- signal internal to this component begin G1: xor port map (A, B, X1);-- instantiate 1 st xor gate G2: xor port map (X1, Cin, Sum); -- instantiate 2 nd xor gate …add circuit for carry output… …add circuit for carry output…end; A X1 Sum Cin

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 17 Example: D flip-flop entity DFF is port (Preset: in bit; port (Preset: in bit; Clear: in bit; Clear: in bit; Clock: in bit; Clock: in bit; Data: in bit; Data: in bit; Q: out bit; Q: out bit; Qbar: out bit); Qbar: out bit); end DFF; Data Clock Q Qbar Preset Clear

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) D flip-flop equations architecture eqns of DFF is signal A,B,C,D: bit; signal QInt, QBarInt: bit; begin A <= not (Preset and D and B) after 1 ns; B <= not (A and Clear and Clock) after 1 ns; C <= not (B and Clock and D) after 1 ns; D <= not (C and Clear and Data) after 1 ns; Qint <= not (Preset and B and QbarInt) after 1 ns; QBarInt <= not (QInt and Clear and C) after 1 ns; Q <= QInt; QBar <= QBarInt; end;

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 19 4-bit Register (Structural Model) entity Register4 is port ( D: in bit_vector(0 to 3); port ( D: in bit_vector(0 to 3); Q: out bit_vector(0 to 3); Q: out bit_vector(0 to 3); Clk: in bit; Clk: in bit; Clr: in bit; Clr: in bit; Pre: in bit); Pre: in bit); end Register4; D(3) Q(3) D(2) D(1) D(0) Q(2) Q(1) Q(0) CLK PRE CLR

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 20 Register Architecture architecture structure of Register4 is component DFF is-- declare library component to be used port (Preset: in bit; port (Preset: in bit; Clear: in bit; Clear: in bit; Clock: in bit; Clock: in bit; Data: in bit; Data: in bit; Q: out bit; Q: out bit; Qbar: out bit); Qbar: out bit); end component DFF; end component DFF; signal Qbar: bit_vector(0 to 3); -- dummy for unused FF output signal Qbar: bit_vector(0 to 3); -- dummy for unused FF output begin -- Signals connected to ports in order listed above F3: DFF port map (Pre, Clr, Clk, D(3), Q(3), Qbar(3)); F2: DFF port map (Pre, Clr, Clk, D(2), Q(2), Qbar(2)); F1: DFF port map (Pre, Clr, Clk, D(1), Q(1), Qbar(1)); F0: DFF port map (Pre, Clr, Clk, D(0), Q(0), Qbar(0)); end;

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 21 Register Architecture (short cut – “generate” statement) begin for k in 0 to 3 generate F: DFF port map (Pre, Clr, Clk, D(k), Q(k), Qbar(k)); F: DFF port map (Pre, Clr, Clk, D(k), Q(k), Qbar(k)); end generate; end; Generates multiple copies of the given statement(s) Value of k inserted where specified Iteration number k is appended to each label F Result is identical to previous example

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 22 Statements used for modeling Concurrent statements –Concurrent assignments –with – select – when –when – else Sequential statements using “process” –if – then – else –case – when –for – loop –while - loop

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 23 Concurrent assignments A <= not (Preset and D and B) after 1 ns; B <= not (A and Clear and Clock) after 1 ns; C <= not (B and Clock and D) after 1 ns; D <= not (C and Clear and Data) after 1 ns;

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 24 With – select - when with S select y <= a after 1 ns when “00”, b after 1 ns when “01”, c after 1 ns when “10”, d after 1 ns when “11”; (or: d after 1 ns when others;) (or: d after 1 ns when others;) abcdabcd S y 4-to-1 Mux

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 25 When - else y <= a after 1 ns when (S=“00”) else b after 1 ns when (S=“01”) else c after 1 ns when (S=“10”) else d after 1 ns; Any boolean expression can be used for each condition. Ex. y <= a after 1 ns when (F=‘1’) and (G=‘0’) … abcdabcd S y 4-to-1 Mux

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 26 Tristate buffer example library ieee; use ieee.std_logic_1164.all; entity tristate is port ( a: in bit; port ( a: in bit; y: out std_logic; y: out std_logic; en: in bit); en: in bit); end tristate; architecture a1 of tristate is begin y <= a after 1 ns when (en=‘1’) else ‘Z’ after 1 ns; ‘Z’ after 1 ns;end; -- Error: Type mismatch between y and a ya en

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 27 Tristate buffer example (correct) library ieee; use ieee.std_logic_1164.all; entity tristate is port ( a: in bit; port ( a: in bit; y: out std_logic; y: out std_logic; en: in bit); en: in bit); end tristate; architecture a1 of tristate is begin y <= ‘0’ after 1 ns when (en=‘1’) and (a=‘0’) else ‘1’ after 1 ns when (en=‘1’) and (a=‘1’) else ‘1’ after 1 ns when (en=‘1’) and (a=‘1’) else ‘Z’ after 1 ns; ‘Z’ after 1 ns;end; ya en

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 28 Tristate bus buffer example library ieee; use ieee.std_logic_1164.all; entity tristate is port ( a: in bit_vector(0 to 7); port ( a: in bit_vector(0 to 7); y: out std_logicvector(0 to 7); y: out std_logicvector(0 to 7); en: in bit); en: in bit); end tristate; architecture a1 of tristate is begin y <= to_stdlogicvector(a) after 1 ns when (en=‘1’) else “ZZZZZZZZ” after 1 ns; “ZZZZZZZZ” after 1 ns;end; ya en

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 29 VHDL “Process” Construct Allows conventional programming language methods to describe circuit behavior Supported language constructs (“sequential statements”) – only allowed within a process: –variable assignment –if-then-else (elsif) –case statement –while (condition) loop –for (range) loop

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 30 Process Format [label:] process (sensitivity list) declarations begin begin sequential statements end process; end process; Process statements executed once at start of simulation Process halts at “end” until an event occurs on a signal in the “sensitivity list”

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 31 Using a “process” to model sequential behavior entity DFF is port (D,CLK: in std_logic; port (D,CLK: in std_logic; Q: out std_logic); Q: out std_logic); end DFF; architecture behave of DFF is begin process(clk) -- “process sensitivity list” begin if (clk’event and clk=‘1’) then Q <= D after 1 ns; Q <= D after 1 ns; end if; end process; end; Process statements executed sequentially (sequential statements) clk’event is an attribute of signal clk which is TRUE if an event has occurred on clk at the current simulation time D Q CLK

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 32 Alternative to sensitivity list entity DFF is port (D,CLK: in std_logic; port (D,CLK: in std_logic; Q: out std_logic); Q: out std_logic); end DFF; architecture behave of DFF is begin process -- no “sensitivity list” begin wait on clk; -- suspend process until event on clk if (clk=‘1’) then Q <= D after 1 ns; Q <= D after 1 ns; end if; end process; end; Other “wait” formats: wait until (clk’event and clk=‘1’) wait for 20 ns; Process executes endlessly if no sensitivity list or wait statement! D Q CLK

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 33 D latch vs. D flip-flop entity Dlatch is port (D,CLK: in std_logic; port (D,CLK: in std_logic; Q: out std_logic); Q: out std_logic); end Dlatch; architecture behave of Dlatch is begin process(D, clk) begin if (clk=‘1’) then Q <= D after 1 ns; Q <= D after 1 ns; end if; end process; end; For latch, Q changes whenever the latch is enabled by CLK=‘1’ (rather than being edge-triggered) D Q CLK

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 34 Synchronous vs. Asynchronous Flip-Flop Inputs entity DFF is port (D,CLK: in std_logic; port (D,CLK: in std_logic; PRE,CLR: in std_logic; PRE,CLR: in std_logic; Q: out std_logic); Q: out std_logic); end DFF; architecture behave of DFF is beginprocess(clk,PRE,CLR)begin if (CLR=‘0’) then -- CLR has precedence Q <= ‘0’ after 1 ns; Q <= ‘0’ after 1 ns; elsif (PRE=‘0’) then -- Then PRE has precedence Q <= ‘1’ after 1 ns; Q <= ‘1’ after 1 ns; elsif (clk’event and clk=‘1’) then Q <= D after 1 ns; -- Only if CLR=PRE=‘1’ Q <= D after 1 ns; -- Only if CLR=PRE=‘1’ end if; end process; end; CLR D Q CLK PRE

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 35 Configurable N-bit register entity REG is generic (N:integer := 4) generic (N:integer := 4) port (D: in std_logic_vector(N-1 downto 0); port (D: in std_logic_vector(N-1 downto 0); CLK: in std_logic; CLK: in std_logic; Q: out std_logic_vector(N-1 downto 0)); Q: out std_logic_vector(N-1 downto 0)); end REG; architecture behave of REG is beginprocess(clk)begin if (clk’event and clk=‘1’) then Q <= D after 1 ns; Q <= D after 1 ns; end if; end process; end;

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 36 Signals vs Variables Signals –Signals follow the notion of ‘event scheduling’ –An event is characterized by a (time,value) pair –Signal assignment example: X ; means Schedule the assignment of the value of signal Xtmp to signal X at (Current time + ) Variables –Variables do not have notion of ‘events’ –Variables can be defined and used only inside the process block and some other special blocks.

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 37 Using a “variable” to describe sequential behavior within a process cnt: process(clk) variable count_v: std_logic_vector; -- internal counter variable signal count_s: std_logic_vector; -- internal counter signal begin if clk=‘1’ and clk’event then if load=‘1’ then count_v := Din; count_s <= Din after 1ns; elsif cnt=‘1’ then count_v := count_v + 1; -- use appropriate package for ‘+’ count_s <= count_s + 1 after 1ns; end if; DoutA <= count_v after 1ns; DoutB <= count_s after 1ns; DoutB <= count_s after 1ns; end process; end process; TimeclkloadDincount_vcount_sDoutADoutB

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 38 Sequential statements in process if-then-elsif-else statement if condition then (... sequence of statements...) elsif condition then (... sequence of statements...) else (... sequence of statements...) end if; case statement case expression is when choices => sequence of statements when choices => sequence of statements... when others => sequence of statements end case;

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 39 Sequential statements in process while loop [ label:] while condition loop... sequence of statements... end loop [label] ; while loop [ label:] while condition loop... sequence of statements... end loop [label] ; for loop [ label: ] for loop_variable in range loop... sequence of statements... end loop [label] ;

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 40 Modeling Finite State Machines (Synchronous Sequential Circuits) Comb. Logic FFs Inputs x Outputs z Next State Y Present State y Next State Y = f(x,y) Clock

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 41 Synchronous Sequential Circuit (FSM) Example

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 42 FSM Example – entity definition entity seqckt is port ( port ( x: in bit;-- FSM input z: out bit;-- FSM output clk: in bit );-- clock end seqckt;

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 43 FSM Example - behavioral model architecture behave of seqckt is type states is (A,B,C); -- symbolic state names signal curr_state,next_state: states; begin -- Model the memory elements of the FSM process (clk) begin if (clk’event and clk=‘1’) then pres_state <= next_state; end if; end process; (continue on next slide)

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 44 FSM Example - continued -- Model the next-state and output functions of the FSM process (x, pres_state) -- function inputs begin case pres_state is -- describe each state when A => if (x = ‘0’) then when A => if (x = ‘0’) then z <= ‘0’; z <= ‘0’; next_state <= A; else -- (x = ‘1’) else -- (x = ‘1’) z <= ‘0’; next_state <= B; end if; end if; (continue next slide for pres_state = B and C)

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 45 FSM Example (continued) when B => if (x=‘0’) then when B => if (x=‘0’) then z <= ‘0’; next_state <= A; else else z <= ‘1’; next_state <= C; end if; end if; when C => if (x=‘0’) then z <= ‘0’; next_state <= C; else else z <= ‘1’; next_state <= A; end if; end if; end case; end case; end process; end process;end;

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 46 64K x 8 Memory Example library ieee; use ieee.std_logic_1164.all; use work.qsim_logic.all;-- package with to_integer() func entity memory8 is port (dbus: inout std_logic_vector(0 to 7); port (dbus: inout std_logic_vector(0 to 7); abus: in std_logic_vector(0 to 15); abus: in std_logic_vector(0 to 15); ce: in bit;-- active low chip enable ce: in bit;-- active low chip enable oe: in bit;-- active low output enable oe: in bit;-- active low output enable we: in bit);-- active low write enable we: in bit);-- active low write enable end memory8;

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 47 64K x 8 Memory Example architecture reglevel of memory8 is begin process (ce,oe,we,abus,dbus) process (ce,oe,we,abus,dbus) type mem is array(natural range <>) of std_logic_vector(0 to 7); type mem is array(natural range <>) of std_logic_vector(0 to 7); variable M: mem(0 to 65535); variable M: mem(0 to 65535); begin begin if (ce='0') and (oe='0') then -- read enabled if (ce='0') and (oe='0') then -- read enabled dbus <= M(to_integer(abus));-- drive the bus dbus <= M(to_integer(abus));-- drive the bus elsif (ce='0') and (we='0') then -- write enabled elsif (ce='0') and (we='0') then -- write enabled dbus <= "ZZZZZZZZ";-- disable drivers dbus <= "ZZZZZZZZ";-- disable drivers M(to_integer(abus)) := dbus;-- write to M M(to_integer(abus)) := dbus;-- write to M else else dbus <= "ZZZZZZZZ";--disable drivers dbus <= "ZZZZZZZZ";--disable drivers end if; end if; end process; end process;end;

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 48 Miscellaneous VHDL Items Subtypes of previously-defined data types subtype int3 is integer range 0 to 7; Use of “alias” for existing elements signal instruc: bit_vector(0 to 31); alias opcode: bit_vector(0 to 5) is instruc(0 to 5); alias rd: bit_vector(0 to 4) is instruc(6 to 10); alias rs: bit_vector(0 to 4) is instruc(11 to 15); Fill a bit_vector with a constant (right-most bits): A ‘0’); B(15 downto 0) <= C(15 downto 0); B(31 downto 16) C(15)); -- sign extension! Concatenate bits and bit_vectors A <= B & C(0 to 3) & “00”; -- A is 16 bits, B is 10 bits

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 49 Unconstrained Bit Vectors Allows a generic component with different sizes: entity mux is port (a,b: in bit_vector; -- unconstrained c: out bit_vector; s: in bit ); end mux; end mux; architecture x of mux is begin c <= a when (s=‘0’) else b; end;

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 50 Unconstrained Bit Vectors Vector constrained when instantiated: architecture struct of my_design is signal s1,s2: bit; signal s1,s2: bit; signal a5,b5,c5: bit_vector (0 to 4); signal a32,b32,c32: bit_vector (0 to 31); component mux port (a,b: in bit_vector; -- unconstrained c: out bit_vector; s: in bit ); end component; end component;begin M5: mux port map (a5,b5,c5,s1); -- 5-bit mux M32: mux port map (a32,b32,c32,s2); bit mux end;

Fall 09, Aug 19 ELEC / Lecture 2 (from Prof. Nelson's and Prof. Stroud's course material) 51 Other VHDL resources VHDL mini-reference on Prof. Nelson’s website – VHDL resources on Prof. Stroud’s website – VHDL Tutorial: Learn by Example by Weijun Zhang –