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

Slides:



Advertisements
Similar presentations
Sequential-Circuit Building Blocks
Advertisements

CSCI 660 EEGN-CSCI 660 Introduction to VLSI Design Lecture 3 Khurram Kazi Some of the slides were taken from K Gaj ’ s lecture slides from GMU ’ s 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.
George Mason University ECE 448 – FPGA and ASIC Design with VHDL Finite State Machines State Diagrams, State Tables, Algorithmic State Machine (ASM) Charts,
ECE 448 Lecture 3 Combinational-Circuit Building Blocks Data Flow Modeling of Combinational Logic ECE 448 – FPGA and ASIC Design with VHDL.
George Mason University ECE 448 – FPGA and ASIC Design with VHDL Combinational-Circuit Building Blocks Data Flow Modeling of Combinational Logic ECE 448.
Simple Testbenches Behavioral Modeling of Combinational Logic
ECE 545 Lecture 7 Behavioral Modeling of Sequential-Circuit Building Blocks Mixing Design Styles Modeling of Circuits with a Regular Structure.
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.
Data Flow Modeling of Combinational Logic Simple Testbenches
A.7 Concurrent Assignment Statements Used to assign a value to a signal in an architecture body. Four types of concurrent assignment statements –Simple.
CprE / ComS 583 Reconfigurable Computing Prof. Joseph Zambreno Department of Electrical and Computer Engineering Iowa State University Lecture #17 – Introduction.
VHDL Introduction. V- VHSIC Very High Speed Integrated Circuit H- Hardware D- Description L- Language.
1 Sequential Logic Lecture #7. 모바일컴퓨팅특강 2 강의순서 Latch FlipFlop Shift Register Counter.
CprE / ComS 583 Reconfigurable Computing
CSET 4650 Field Programmable Logic Devices Dan Solarek VHDL Additional Details & Examples.
1 ECE 545 – Introduction to VHDL ECE 545 Lecture 4 Behavioral & Structural Design Styles.
George Mason University Modeling of Circuits with a Regular Structure Aliases, Attributes, Packages Mixing Design Styles ECE 545 Lecture 7.
VHDL for Combinational Circuits. VHDL We Know Simple assignment statements –f
1 ECE 545 – Introduction to VHDL Dataflow Modeling of Combinational Logic Simple Testbenches ECE 656. Lecture 2.
Mixed Style RTL Modeling
ECE 332 Digital Electronics and Logic Design Lab Lab 6 Concurrent Statements & Adders.
Introduction to VHDL Simulation … Synthesis …. The digital design process… Initial specification Block diagram Final product Circuit equations Logic design.
George Mason University Simple Testbenches ECE 545 Lecture 4.
George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7.
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
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.
Data Flow Modeling in VHDL
George Mason University ECE 448 – FPGA and ASIC Design with VHDL VHDL Coding for Synthesis ECE 448 Lecture 12.
CDA 4253 FPGA System Design Sequential Circuit Building Blocks Hao Zheng Dept of Comp Sci & Eng USF.
George Mason University Behavioral Modeling of Sequential-Circuit Building Blocks ECE 545 Lecture 8.
George Mason University Data Flow Modeling of Combinational Logic ECE 545 Lecture 5.
Sequential statements (1) process
Combinational logic circuit
Describing Combinational Logic Using Processes
Figure 7.1 Control of an alarm system
CHAPTER 17 VHDL FOR SEQUENTIAL LOGIC
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 9 Modeling of Circuits with a Regular Structure Aliases, Attributes, Packages.
Sequential-Circuit Building Blocks
ECE 448 Lecture 3 Combinational-Circuit Building Blocks Data Flow Modeling of Combinational Logic ECE 448 – FPGA and ASIC Design with VHDL.
CHAPTER 17 VHDL FOR SEQUENTIAL LOGIC
Non-synthesizable VHDL Poor Design Practices
ECE 448 Lecture 6 Modeling of Circuits with a Regular Structure Aliases, Constants, Packages Mixing Design Styles ECE 448 – FPGA and ASIC Design with.
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 (VHSIC Hardware Description Language)
ECE 545 Lecture 6 Behavioral Modeling of Sequential-Circuit Building Blocks Mixing Design Styles Modeling of Circuits with a Regular Structure.
Behavioral Modeling of Sequential-Circuit Building Blocks
Sequntial-Circuit Building Blocks
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.
Data Flow Description of Combinational-Circuit Building Blocks
ECE 545 Lecture 9 Behavioral Modeling of Sequential-Circuit Building Blocks Mixing Design Styles Modeling of Circuits with a Regular Structure.
ECE 448 Lecture 4 Modeling of Circuits with a Regular Structure Constants, Aliases, Packages ECE 448 – FPGA and ASIC Design with VHDL.
Modeling of Circuits with a Regular Structure
ECE 545 Lecture 5 Simple Testbenches.
ECE 448 Lecture 6 Finite State Machines State Diagrams, State Tables, Algorithmic State Machine (ASM) Charts, and VHDL code ECE 448 – FPGA and ASIC Design.
CprE / ComS 583 Reconfigurable Computing
Sequntial-Circuit Building Blocks
(Sequential-Circuit Building Blocks)
EEL4712 Digital Design.
EEL4712 Digital Design (Midterm 1 Review).
Presentation transcript:

George Mason University Behavioral Modeling of Sequential-Circuit Building Blocks ECE 545 Lecture 6 Mixing Design Styles

2 Required reading P. Chu, RTL Hardware Design using VHDL Chapter 5.1, VHDL Process Chapter 8, Sequential Circuit Design: Principle Slides for Chapter 8, available at

3ECE 448 – FPGA and ASIC Design with VHDL Behavioral Design Style: Registers & Counters

4 VHDL Design Styles Components and interconnects structural VHDL Design Styles dataflow Concurrent statements behavioral Registers Shift registers Counters State machines Sequential statements and more if you are careful synthesizable

5 Processes in VHDL Processes Describe Sequential Behavior Processes in VHDL Are Very Powerful Statements Allow to define an arbitrary behavior that may be difficult to represent by a real circuit Not every process can be synthesized Use Processes with Caution in the Code to Be Synthesized Use Processes Freely in Testbenches

6 Anatomy of a Process [label:] PROCESS [(sensitivity list)] [declaration part] BEGIN statement part END PROCESS [label]; OPTIONAL

7 PROCESS with a SENSITIVITY LIST List of signals to which the process is sensitive. Whenever there is an event on any of the signals in the sensitivity list, the process fires. Every time the process fires, it will run in its entirety. WAIT statements are NOT ALLOWED in a processes with SENSITIVITY LIST. label: process (sensitivity list) declaration part begin statement part end process;

8 Component Equivalent of a Process All signals which appear on the sensitivity list are inputs e.g. clk All signals which appear on the left of signal assignment statement (<=) are outputs e.g. y, z Note that not all inputs need to be included on the sensitivity list All signals which appear on the right of signal assignment statement (<=) or in logic expressions are inputs e.g. w, a, b, c priority: PROCESS (clk) BEGIN IF w(3) = '1' THEN y <= "11" ; ELSIF w(2) = '1' THEN y <= "10" ; ELSIF w(1) = c THEN y <= a and b; ELSE z <= "00" ; END IF ; END PROCESS ; w a y z priority b c clk

9ECE 448 – FPGA and ASIC Design with VHDL Registers

10 ClockD – Truth table Graphical symbol t 1 t 2 t 3 t 4 Time Clock D Q Timing diagram Q(t+1) Q(t) D latch D Q Clock

11 Clk D   Truth table t 1 t 2 t 3 t 4 Time Clock D Q Timing diagram Q(t+1) Q(t) D flip-flop D Q Clock Graphical symbol 0 – Q(t) 1 –

12 LIBRARY ieee ; USE ieee.std_logic_1164.all ; ENTITY latch IS PORT ( D, Clock : IN STD_LOGIC ; Q : OUT STD_LOGIC) ; END latch ; ARCHITECTURE behavioral OF latch IS BEGIN PROCESS ( D, Clock ) BEGIN IF Clock = '1' THEN Q <= D ; END IF ; END PROCESS ; END behavioral; D latch D Q Clock

13 LIBRARY ieee ; USE ieee.std_logic_1164.all ; ENTITY flipflop IS PORT ( D, Clock: INSTD_LOGIC ; Q: OUTSTD_LOGIC) ; END flipflop ; ARCHITECTURE behavioral2 OF flipflop IS BEGIN PROCESS ( Clock ) BEGIN IF rising_edge(Clock) THEN Q <= D ; END IF ; END PROCESS ; END behavioral2; D flip-flop D Q Clock

14 LIBRARY ieee ; USE ieee.std_logic_1164.all ; ENTITY flipflop IS PORT ( D, Clock: INSTD_LOGIC ; Q: OUTSTD_LOGIC) ; END flipflop ; ARCHITECTURE behavioral OF flipflop IS BEGIN PROCESS ( Clock ) BEGIN IF Clock'EVENT AND Clock = '1' THEN Q <= D ; END IF ; END PROCESS ; END behavioral ; D flip-flop D Q Clock

15 LIBRARY ieee ; USE ieee.std_logic_1164.all ; ENTITY flipflop_ar IS PORT ( D, Resetn, Clock : IN STD_LOGIC ; Q : OUT STD_LOGIC) ; END flipflop_ar ; ARCHITECTURE behavioral OF flipflop_ar IS BEGIN PROCESS ( Resetn, Clock ) BEGIN IF Resetn = '0' THEN Q <= '0' ; ELSIF rising_edge(Clock) THEN Q <= D ; END IF ; END PROCESS ; END behavioral ; D flip-flop with asynchronous reset D Q Clock Resetn

16 LIBRARY ieee ; USE ieee.std_logic_1164.all ; ENTITY flipflop_sr IS PORT ( D, Resetn, Clock : IN STD_LOGIC ; Q : OUT STD_LOGIC) ; END flipflop_sr ; ARCHITECTURE behavioral OF flipflop_sr IS BEGIN PROCESS(Clock) BEGIN IF rising_edge(Clock) THEN IF Resetn = '0' THEN Q <= '0' ; ELSE Q <= D ; END IF ; END PROCESS ; END behavioral ; D flip-flop with synchronous reset D Q Clock Resetn

17 Asychronous vs. Synchronous In the IF loop, asynchronous items are Before the rising_edge(Clock) statement In the IF loop, synchronous items are After the rising_edge(Clock) statement

18 8-bit register with asynchronous reset LIBRARY ieee ; USE ieee.std_logic_1164.all ; ENTITY reg8 IS PORT ( D: IN STD_LOGIC_VECTOR(7 DOWNTO 0) ; Resetn, Clock: IN STD_LOGIC ; Q : OUT STD_LOGIC_VECTOR(7 DOWNTO 0) ) ; END reg8 ; ARCHITECTURE behavioral OF reg8 IS BEGIN PROCESS ( Resetn, Clock ) BEGIN IF Resetn = '0' THEN Q <= " " ; ELSIF rising_edge(Clock) THEN Q <= D ; END IF ; END PROCESS ; END behavioral ;` Resetn Clock reg8 88 DQ

19 N-bit register with asynchronous reset LIBRARY ieee ; USE ieee.std_logic_1164.all ; ENTITY regn IS GENERIC ( N : INTEGER := 16 ) ; PORT ( D: IN STD_LOGIC_VECTOR(N-1 DOWNTO 0) ; Resetn, Clock: IN STD_LOGIC ; Q: OUT STD_LOGIC_VECTOR(N-1 DOWNTO 0) ) ; END regn ; ARCHITECTURE behavioral OF regn IS BEGIN PROCESS ( Resetn, Clock ) BEGIN IF Resetn = '0' THEN Q '0') ; ELSIF rising_edge(Clock) THEN Q <= D ; END IF ; END PROCESS ; END behavioral ; Resetn Clock regn NN DQ

20 A word on generics Generics are typically integer values In this class, the entity inputs and outputs should be std_logic or std_logic_vector But the generics can be integer Generics are given a default value GENERIC ( N : INTEGER := 16 ) ; This value can be overwritten when entity is instantiated as a component Generics are very useful when instantiating an often-used component Need a 32-bit register in one place, and 16-bit register in another Can use the same generic code, just configure them differently

21 Use of OTHERS OTHERS stand for any index value that has not been previously mentioned. Q ‘1’, OTHERS => ‘0’) Q ‘1’, 0 => ‘1’, OTHERS => ‘0’) or Q ‘1’, OTHERS => ‘0’) Q ‘1’, OTHERS => ‘0’)

22 Component Instantiation in VHDL-87 U1: regn GENERIC MAP (N => 4) PORT MAP (D => z, Resetn => reset, Clock => clk, Q => t );

23 U1: work.regne(behavioral) GENERIC MAP (N => 4) PORT MAP (D => z, Resetn => reset, Clock => clk, Q => t ); Component Instantiation in VHDL-93

24 LIBRARY ieee ; USE ieee.std_logic_1164.all ; ENTITY regne IS GENERIC ( N : INTEGER := 8 ) ; PORT (D : IN STD_LOGIC_VECTOR(N-1 DOWNTO 0) ; Enable, Clock: IN STD_LOGIC ; Q : OUT STD_LOGIC_VECTOR(N-1 DOWNTO 0) ) ; END regne ; ARCHITECTURE behavioral OF regne IS BEGIN PROCESS (Clock) BEGIN IF rising_edge(Clock) THEN IF Enable = '1' THEN Q <= D ; END IF ; END PROCESS ; END behavioral ; N-bit register with enable Q D Enable Clock regn NN

25ECE 448 – FPGA and ASIC Design with VHDL Counters

26 LIBRARY ieee ; USE ieee.std_logic_1164.all ; USE ieee.std_logic_unsigned.all ; ENTITY upcount IS PORT (Clear, Clock: IN STD_LOGIC ; Q : OUT STD_LOGIC_VECTOR(1 DOWNTO 0) ) ; END upcount ; ARCHITECTURE behavioral OF upcount IS SIGNAL Count : std_logic_vector(1 DOWNTO 0); BEGIN upcount: PROCESS ( Clock ) BEGIN IF rising_edge(Clock) THEN IF Clear = '1' THEN Count <= "00" ; ELSE Count <= Count + 1 ; END IF ; END PROCESS; Q <= Count; END behavioral; 2-bit up-counter with synchronous reset Q Clear Clock upcount 2

27 LIBRARY ieee ; USE ieee.std_logic_1164.all ; USE ieee.std_logic_unsigned.all ; ENTITY upcount_ar IS PORT ( Clock, Resetn, Enable : IN STD_LOGIC ; Q : OUT STD_LOGIC_VECTOR (3 DOWNTO 0)) ; END upcount_ar ; 4-bit up-counter with asynchronous reset (1) Q Enable Clock upcount 4 Resetn

28 ARCHITECTURE behavioral OF upcount _ar IS SIGNAL Count : STD_LOGIC_VECTOR (3 DOWNTO 0) ; BEGIN PROCESS ( Clock, Resetn ) BEGIN IF Resetn = '0' THEN Count <= "0000" ; ELSIF rising_edge(Clock) THEN IF Enable = '1' THEN Count <= Count + 1 ; END IF ; END PROCESS ; Q <= Count ; END behavioral ; 4-bit up-counter with asynchronous reset (2) Q Enable Clock upcount 4 Resetn

29ECE 448 – FPGA and ASIC Design with VHDL Shift Registers

30 Shift register – internal structure DQ Sin Clock DQDQDQ Q(3) Q(2) Q(1)Q(0) Enable

31 Shift Register With Parallel Load D(3) DQ Clock Enable Sin D(2) DQ D(1) DQ D(0) DQ Q(0)Q(1)Q(2)Q(3) Load

32 LIBRARY ieee ; USE ieee.std_logic_1164.all ; ENTITY shift4 IS PORT ( D : IN STD_LOGIC_VECTOR(3 DOWNTO 0) ; Enable: IN STD_LOGIC ; Load: IN STD_LOGIC ; Sin : IN STD_LOGIC ; Clock : IN STD_LOGIC ; Q : OUT STD_LOGIC_VECTOR(3 DOWNTO 0) ) ; END shift4 ; 4-bit shift register with parallel load (1) Q Enable Clock shift4 4 D Load Sin 4

33 ARCHITECTURE behavioral OF shift4 IS SIGNAL Qt : STD_LOGIC_VECTOR(3 DOWNTO 0); BEGIN PROCESS (Clock) BEGIN IF rising_edge(Clock) THEN IF Enable = ‘1’ THEN IF Load = '1' THEN Qt <= D ; ELSE Qt <= Sin & Qt(3 downto 1);END IF ; END IF; END PROCESS ; Q <= Qt; END behavioral ; 4-bit shift register with parallel load (2) Q Enable Clock shift4 4 D Load Sin 4

34 LIBRARY ieee ; USE ieee.std_logic_1164.all ; ENTITY shiftn IS GENERIC ( N : INTEGER := 8 ) ; PORT (D : IN STD_LOGIC_VECTOR(N-1 DOWNTO 0) ; Enable: IN STD_LOGIC ; Load: IN STD_LOGIC ; Sin : IN STD_LOGIC ; Clock : IN STD_LOGIC ; Q : OUT STD_LOGIC_VECTOR(N-1 DOWNTO 0) ) ; END shiftn ; N-bit shift register with parallel load (1) Q Enable Clock shiftn N D Load Sin N

35 ARCHITECTURE behavioral OF shiftn IS SIGNAL Qt: STD_LOGIC_VECTOR(N-1 DOWNTO 0); BEGIN PROCESS (Clock) BEGIN IF rising_edge(Clock) THEN IF Enable = ‘1’ THEN IF Load = '1' THEN Qt <= D ; ELSE Qt <= Sin & Qt(N-1 downto 1);END IF ; END IF; END PROCESS ; Q <= Qt; END behavior al; N-bit shift register with parallel load (2) Q Enable Clock shiftn N D Load Sin N

36ECE 448 – FPGA and ASIC Design with VHDL Generic Component Instantiation

37 LIBRARY ieee ; USE ieee.std_logic_1164.all ; ENTITY regn IS GENERIC ( N : INTEGER := 8 ) ; PORT (D : IN STD_LOGIC_VECTOR(N-1 DOWNTO 0) ; Enable, Clock: IN STD_LOGIC ; Q : OUT STD_LOGIC_VECTOR(N-1 DOWNTO 0) ) ; END regn ; ARCHITECTURE Behavior OF regn IS BEGIN PROCESS (Clock) BEGIN IF (Clock'EVENT AND Clock = '1' ) THEN IF Enable = '1' THEN Q <= D ; END IF ; END PROCESS ; END Behavior ; N-bit register with enable Q D Enable Clock regn NN

38 Circuit built of medium scale components w 0 w 3 y 1 y 0 z w 1 w 2 w 1 En y 3 w 0 y 2 y 1 y 0 s(0) 0 1 s(1) 0 1 r(0) r(1) r(2) r(3) r(4) r(5) p(0) p(1) p(2) p(3) q(1) q(0) ena z(3) z(2) z(1) z(0) dec2to4 priority t(3)t(3) t(2)t(2) t(1)t(1) t(0)t(0) regne DQ Clk Clock Enable En

39 Structural description – example (1) LIBRARY ieee ; USE ieee.std_logic_1164.all ; ENTITY priority_resolver IS PORT (r: IN STD_LOGIC_VECTOR(5 DOWNTO 0) ; s : IN STD_LOGIC_VECTOR(1 DOWNTO 0) ; clk : IN STD_LOGIC; en : IN STD_LOGIC; t : OUT STD_LOGIC_VECTOR(3 DOWNTO 0) ) ; END priority_resolver; ARCHITECTURE structural OF priority_resolver IS SIGNAL p : STD_LOGIC_VECTOR (3 DOWNTO 0) ; SIGNAL q : STD_LOGIC_VECTOR (1 DOWNTO 0) ; SIGNAL z : STD_LOGIC_VECTOR (3 DOWNTO 0) ; SIGNAL ena : STD_LOGIC ;

40 Structural description – example (2) VHDL-87 COMPONENT mux2to1 PORT (w0, w1, s : INSTD_LOGIC ; f : OUTSTD_LOGIC ) ; END COMPONENT ; COMPONENT priority PORT (w: IN STD_LOGIC_VECTOR(3 DOWNTO 0) ; y: OUT STD_LOGIC_VECTOR(1 DOWNTO 0) ; z: OUT STD_LOGIC ) ; END COMPONENT ; COMPONENT dec2to4 PORT (w: IN STD_LOGIC_VECTOR(1 DOWNTO 0) ; En : IN STD_LOGIC ; y : OUT STD_LOGIC_VECTOR(3 DOWNTO 0) ) ; END COMPONENT ;

41 Structural description – example (3) VHDL-87 COMPONENT regn GENERIC ( N : INTEGER := 8 ) ; PORT (D : IN STD_LOGIC_VECTOR(N-1 DOWNTO 0) ; Enable, Clock: IN STD_LOGIC ; Q : OUT STD_LOGIC_VECTOR(N-1 DOWNTO 0) ) ; END COMPONENT ;

42 Structural description – example (4) VHDL-87 BEGIN u1: mux2to1 PORT MAP (w0 => r(0), w1 => r(1), s => s(0), f => p(0)); p(1) <= r(2); p(2) <= r(3); u2: mux2to1 PORT MAP (w0 => r(4), w1 => r(5), s => s(1), f => p(3)); u3: priority PORT MAP (w => p, y => q, z => ena); u4: dec2to4 PORT MAP (w => q, En => ena, y => z);

43 Structural description – example (5) VHDL-87 u5: regn GENERIC MAP (N => 4) PORT MAP (D => z, Enable => En, Clock => Clk, Q => t ); END structural;

44 Structural description – example (6) VHDL-93 BEGIN u1: work.mux2to1(dataflow) PORT MAP (w0 => r(0), w1 => r(1), s => s(0), f => p(0)); p(1) <= r(2); p(1) <= r(3); u2: work.mux2to1(dataflow) PORT MAP (w0 => r(4), w1 => r(5), s => s(1), f => p(3)); u3: work.priority(dataflow) PORT MAP (w => p, y => q, z => ena);

45 Structural description – example (7) VHDL-93 u4: work.dec2to4 (dataflow) PORT MAP (w => q, En => ena, y => z); u5: work.regne(behavioral) GENERIC MAP (N => 4) PORT MAP (D => z, Enable => En, Clock => Clk, Q => t ); END structural;

46ECE 448 – FPGA and ASIC Design with VHDL Constants

47 Constants Syntax: CONSTANT name : type := value; Examples: CONSTANT init_value : STD_LOGIC_VECTOR(3 downto 0) := "0100"; CONSTANT ANDA_EXT : STD_LOGIC_VECTOR(7 downto 0) := X"B4"; CONSTANT counter_width : INTEGER := 16; CONSTANT buffer_address : INTEGER := 16#FFFE#; CONSTANT clk_period : TIME := 20 ns; CONSTANT strobe_period : TIME := ms;

48 Constants - features Constants can be declared in a PACKAGE, ENTITY, ARCHITECTURE When declared in a PACKAGE, the constant is truly global, for the package can be used in several entities. When declared in an ARCHITECTURE, the constant is local, i.e., it is visible only within this architecture. When declared in an ENTITY declaration, the constant can be used in all architectures associated with this entity.

49ECE 448 – FPGA and ASIC Design with VHDL Packages

50 Explicit Component Declaration versus Package Explicit component declaration is when you declare components in main code When have only a few component declarations, this is fine When have many component declarations, use packages for readability Packages also help with portability and sharing of libraries among many users in a company Remember, the actual instantiations always take place in main code Only the declarations can be in main code or package

51 For simple projects put entity.vhd files all in same directory Declare components in main code If using Aldec, make sure compiler knows the correct hierarchy From lowest to highest Xilinx will figure out hierarchy automatically Explicit Component Declaration Tips

52 METHOD #2: Package component declaration Components declared in package Actual instantiations and port maps always in main code

53 Packages Instead of declaring all components can declare all components in a PACKAGE, and INCLUDE the package once This makes the top-level entity code cleaner It also allows that complete package to be used by another designer A package can contain Components Functions, Procedures Types, Constants

54 Package – example (1) LIBRARY ieee ; USE ieee.std_logic_1164.all ; PACKAGE GatesPkg IS COMPONENT mux2to1 PORT (w0, w1, s : INSTD_LOGIC ; f : OUTSTD_LOGIC ) ; END COMPONENT ; COMPONENT priority PORT (w: IN STD_LOGIC_VECTOR(3 DOWNTO 0) ; y: OUT STD_LOGIC_VECTOR(1 DOWNTO 0) ; z: OUT STD_LOGIC ) ; END COMPONENT ;

55 Package – example (2) COMPONENT dec2to4 PORT (w: IN STD_LOGIC_VECTOR(1 DOWNTO 0) ; En : IN STD_LOGIC ; y : OUT STD_LOGIC_VECTOR(0 TO 3) ) ; END COMPONENT ; COMPONENT regn GENERIC ( N : INTEGER := 8 ) ; PORT (D : IN STD_LOGIC_VECTOR(N-1 DOWNTO 0) ; Enable, Clock: IN STD_LOGIC ; Q : OUT STD_LOGIC_VECTOR(N-1 DOWNTO 0) ) ; END COMPONENT ;

56 constant ADDAB : std_logic_vector(3 downto 0) := "0000"; constant ADDAM : std_logic_vector(3 downto 0) := "0001"; constant SUBAB : std_logic_vector(3 downto 0) := "0010"; constant SUBAM : std_logic_vector(3 downto 0) := "0011"; constant NOTA : std_logic_vector(3 downto 0) := "0100"; constant NOTB : std_logic_vector(3 downto 0) := "0101"; constant NOTM : std_logic_vector(3 downto 0) := "0110"; constant ANDAB : std_logic_vector(3 downto 0) := "0111"; END GatesPkg; Package – example (3)

57 Package usage (1) LIBRARY ieee ; USE ieee.std_logic_1164.all ; USE work.GatesPkg.all; ENTITY priority_resolver1 IS PORT (r: IN STD_LOGIC_VECTOR(5 DOWNTO 0) ; s : IN STD_LOGIC_VECTOR(1 DOWNTO 0) ; clk : IN STD_LOGIC; en : IN STD_LOGIC; t : OUT STD_LOGIC_VECTOR(3 DOWNTO 0) ) ; END priority_resolver1; ARCHITECTURE structural OF priority_resolver1 IS SIGNAL p : STD_LOGIC_VECTOR (3 DOWNTO 0) ; SIGNAL q : STD_LOGIC_VECTOR (1 DOWNTO 0) ; SIGNAL z : STD_LOGIC_VECTOR (3 DOWNTO 0) ; SIGNAL ena : STD_LOGIC ;

58 BEGIN u1: mux2to1 PORT MAP (w0 => r(0), w1 => r(1), s => s(0), f => p(0)); p(1) <= r(2); p(2) <= r(3); u2: mux2to1 PORT MAP (w0 => r(4), w1 => r(5), s => s(1), f => p(3)); u3: priority PORT MAP (w => p, y => q, z => ena); u4: dec2to4 PORT MAP (w => q, En => ena, y => z); u5: regn GENERIC MAP (N => 4) PORT MAP (D => z, Enable => En, Clock => Clk, Q => t ); END structural; Package usage (2)

59 Aldec Compilation Order Include package before top-level

60ECE 448 – FPGA and ASIC Design with VHDL Mixing Design Styles Inside of an Architecture

61 VHDL Design Styles Components and interconnects structural VHDL Design Styles dataflow Concurrent statements behavioral Registers Shift registers Counters State machines Sequential statements synthesizable

62 architecture ARCHITECTURE_NAME of ENTITY_NAME is Here you can declare signals, constants, functions, procedures… Component declarations begin Concurrent statements: Concurrent simple signal assignment Conditional signal assignment Selected signal assignment Generate statement Component instantiation statement Process statement inside process you can use only sequential statements end ARCHITECTURE_NAME; Mixed Style Modeling Concurrent Statements

63 PRNG Example (1) library IEEE; use IEEE.STD_LOGIC_1164.all; use work.prng_pkg.all; ENTITY PRNG IS PORT( Coeff : in std_logic_vector(4 downto 0); Load_Coeff : in std_logic; Seed : in std_logic_vector(4 downto 0); Init_Run : in std_logic; Clk : in std_logic; Current_State : out std_logic_vector(4 downto 0)); END PRNG; ARCHITECTURE mixed OF PRNG is signal Ands : std_logic_vector(4 downto 0); signal Sin : std_logic; signal Coeff_Q : std_logic_vector(4 downto 0); signal Shift5_Q : std_logic_vector(4 downto 0);

64 PRNG Example (2) -- Data Flow Sin <= Ands(0) XOR Ands(1) XOR Ands(2) XOR Ands(3) XOR Ands(4); Ands <= Coeff_Q AND Shift5_Q; Current_State <= Shift5_Q; -- Behavioral Coeff_Reg: PROCESS(Clk) BEGIN IF rising_edge(Clk) THEN IF Load_Coeff = '1' THEN Coeff_Q <= Coeff; END IF; END PROCESS; -- Structural Shift5_Reg : Shift5 PORT MAP ( D => Seed, Load => Init_Run, Sin => Sin, Clock => Clk, Q => Shift5_Q); END mixed;

George Mason University ECE 448 – FPGA and ASIC Design with VHDL Non-synthesizable VHDL

66 Delays Delays are not synthesizable Statements, such as wait for 5 ns a <= b after 10 ns will not produce the required delay, and should not be used in the code intended for synthesis.

67 Initializations Declarations of signals (and variables) with initialized values, such as SIGNAL a : STD_LOGIC := ‘0’; cannot be synthesized, and thus should be avoided. If present, they will be ignored by the synthesis tools. Use set and reset signals instead.

68 Dual-edge triggered register/counter (1) In FPGAs register/counter can change only at either rising (default) or falling edge of the clock. Dual-edge triggered clock is not synthesizable correctly, using either of the descriptions provided below.

69 Dual-edge triggered register/counter (2) PROCESS (clk) BEGIN IF (clk’EVENT AND clk=‘1’ ) THEN counter <= counter + 1; ELSIF (clk’EVENT AND clk=‘0’ ) THEN counter <= counter + 1; END IF; END PROCESS;

70 Dual-edge triggered register/counter (3) PROCESS (clk) BEGIN IF (clk’EVENT) THEN counter <= counter + 1; END IF; END PROCESS; PROCESS (clk) BEGIN counter <= counter + 1; END PROCESS;

71ECE 448 – FPGA and ASIC Design with VHDL Combinational Logic Synthesis for Beginners

72 concurrent signal assignment (  ) conditional concurrent signal assignment (when-else) selected concurrent signal assignment (with-select-when) generate scheme for equations (for-generate) Simple rules for beginners For combinational logic, use only concurrent statements

73 concurrent signal assignment (  ) Simple rules for beginners For circuits composed of - simple logic operations (logic gates) - simple arithmetic operations (addition, subtraction, multiplication) - shifts/rotations by a constant use

74 Simple rules for beginners For circuits composed of - multiplexers - decoders, encoders - tri-state buffers use conditional concurrent signal assignment (when-else) selected concurrent signal assignment (with-select-when) (ending with WHEN OTHERS;)

75 Example: VHDL code for a 4-to-1 MUX LIBRARY ieee ; USE ieee.std_logic_1164.all ; ENTITY mux4to1 IS PORT (w0, w1, w2, w3: IN STD_LOGIC ; s: IN STD_LOGIC_VECTOR(1 DOWNTO 0) ; f: OUT STD_LOGIC ) ; END mux4to1 ; ARCHITECTURE dataflow OF mux4to1 IS BEGIN WITH s SELECT f <= w0 WHEN "00", w1 WHEN "01", w2 WHEN "10", w3 WHEN OTHERS ; END dataflow ;

76 Left vs. right side of the assignment <= <= when-else with-select <= Left side Right side Internal signals (defined in a given architecture) Ports of the mode - out - inout Expressions including: Internal signals (defined in a given architecture) Ports of the mode - in - inout

77 Arithmetic operations Synthesizable arithmetic operations: Addition, + Subtraction, - Comparisons, >, >=, <, <= Multiplication, *

78ECE 448 – FPGA and ASIC Design with VHDL Arithmetic operations The result of synthesis of an arithmetic operation is a - combinational circuit - without pipelining. The exact internal architecture used (and thus delay and area of the circuit) may depend on the timing constraints specified during synthesis (e.g., the requested maximum clock frequency).

79ECE 448 – FPGA and ASIC Design with VHDL Sequential Logic Synthesis for Beginners

80ECE 448 – FPGA and ASIC Design with VHDL For Beginners Use processes with very simple structure only to describe - registers - shift registers - counters - state machines. Use examples discussed in class as a template. Create generic entities for registers, shift registers, and counters, and instantiate the corresponding components in a higher level circuit using GENERIC MAP PORT MAP. Supplement sequential components with combinational logic described using concurrent statements.

81ECE 448 – FPGA and ASIC Design with VHDL Sequential Logic Synthesis for Intermediates

82 For Intermmediates 1.Use Processes with IF and CASE statements only. Do not use LOOPS or VARIABLES. 2.Sensitivity list of the PROCESS should include only signals that can by themsleves change the outputs of the sequential circuit (typically, clock and asynchronous set or reset) 3.Do not use PROCESSes without sensitivity list (they can be synthesizable, but make simulation inefficient)

83 For Intermmediates (2) Given a single signal, the assignments to this signal should only be made within a single process block in order to avoid possible conflicts in assigning values to this signal. Process 1: PROCESS (a, b) BEGIN y <= a AND b; END PROCESS; Process 2: PROCESS (a, b) BEGIN y <= a OR b; END PROCESS;