George Mason University ECE 545 – Introduction to VHDL Data Flow & Structural Modeling of Combinational Logic ECE 545 Lecture 2.

Slides:



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

Introduction to VHDL (Lecture #5) ECE 331 – Digital System Design The slides included herein were taken from the materials accompanying Fundamentals of.
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.
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 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
EENG 2910 – Digital Systems Design Fall Course Introduction Class Time: M9:30am-12:20pm Location: B239, B236 and B227 Instructor: Yomi Adamo
Introduction to VHDL for Synthesis
VHDL Training ©1995 Cypress Semiconductor 1 Introduction  VHDL is used to:  document circuits  simulate circuits  synthesize design descriptions 
ECE 332 Digital Electronics and Logic Design Lab Lab 5 VHDL Design Styles Testbenches.
Data Flow Modeling of Combinational Logic Simple Testbenches
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.
VHDL Introduction. V- VHSIC Very High Speed Integrated Circuit H- Hardware D- Description L- Language.
George Mason University ECE 448 – FPGA and ASIC Design with VHDL George Mason University ECE 448 Lab 1 Developing Effective Testbenches.
1 ECE 545 – Introduction to VHDL ECE 545 Lecture 4 Behavioral & Structural Design Styles.
CprE / ComS 583 Reconfigurable Computing Prof. Joseph Zambreno Department of Electrical and Computer Engineering Iowa State University Lecture #16 – Introduction.
Introduction to VHDL Spring EENG 2920 Digital Systems Design Introduction VHDL – VHSIC (Very high speed integrated circuit) Hardware Description.
1 ECE 545 – Introduction to VHDL Dataflow Modeling of Combinational Logic Simple Testbenches ECE 656. Lecture 2.
George Mason University ECE 448 – FPGA and ASIC Design with VHDL VHDL Refresher Lecture 2.
1 component OR_3 port (A,B,C: in bit; Z: out bit); end component ; Reserved Words  Declarations of Components and Entities are similar  Components are.
ECE 332 Digital Electronics and Logic Design Lab Lab 6 Concurrent Statements & Adders.
(1) Basic Language Concepts © Sudhakar Yalamanchili, Georgia Institute of Technology, 2006.
Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.
George Mason University Simple Testbenches ECE 545 Lecture 4.
George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7.
9/9/2006DSD,USIT,GGSIPU1 Concurrent vs Sequential Combinational vs Sequential logic –Combinational logic is that in which the output of the circuit depends.
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.
ECOM 4311—Digital System Design with VHDL
Data Flow Modeling in VHDL
CDA 4253 FPGA System Design Introduction to VHDL
George Mason University ECE 448 – FPGA and ASIC Design with VHDL VHDL Coding for Synthesis ECE 448 Lecture 12.
Lecture 2 VHDL Refresher ECE 448 – FPGA and ASIC Design with VHDL.
George Mason University Introduction to VHDL for Synthesis Lecture 3.
George Mason University ECE 448 – FPGA and ASIC Design with VHDL VHDL Refresher Lecture 2.
George Mason University Behavioral Modeling of Sequential-Circuit Building Blocks ECE 545 Lecture 8.
CDA 4253 FPGA System Design Behavioral modeling of Combinational Circuits Hao Zheng Dept of Comp Sci & Eng USF.
ECE 448 Lab 1 Developing Effective Testbenches
VHDL 표현방식.
George Mason University Data Flow Modeling of Combinational Logic ECE 545 Lecture 5.
CDA 4253 FPGA System Design VHDL Testbench Development Hao Zheng Comp. Sci & Eng USF.
1 Introduction to Engineering Spring 2007 Lecture 18: Digital Tools 2.
Combinational logic circuit
Basic Language Concepts
ECE 448 Lecture 3 Combinational-Circuit Building Blocks Data Flow Modeling of Combinational Logic ECE 448 – FPGA and ASIC Design with VHDL.
ECE 448 Lab 1a Developing Effective Testbenches
ECE 448 Lecture 3 Combinational-Circuit Building Blocks Data Flow Modeling of Combinational Logic ECE 448 – FPGA and ASIC Design with VHDL.
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 Lab 1 Developing Effective Testbenches
ECE 448 Lecture 3 Combinational-Circuit Building Blocks Data Flow Modeling of Combinational Logic ECE 448 – FPGA and ASIC Design with VHDL.
Data Flow Modeling of Combinational Logic
Concurrent vs Sequential
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
ECE 448 Lab 1 Developing Effective Testbenches
Data Flow Description of Combinational-Circuit Building Blocks
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.
CprE / ComS 583 Reconfigurable Computing
CprE / ComS 583 Reconfigurable Computing
EEL4712 Digital Design (VHDL Tutorial).
(Carry Lookahead Adder)
(Simple Testbenches & Arithmetic Operations)
Presentation transcript:

George Mason University ECE 545 – Introduction to VHDL Data Flow & Structural Modeling of Combinational Logic ECE 545 Lecture 2

2ECE 545 – Introduction to VHDL Resources Sundar Rajan, Essential VHDL: RTL Synthesis Done Right Chapter 1, VHDL Fundamentals Chapter 2, Getting Your First Design Done Chapter 3, Gates, Decoders and Encoders Chapter 9, Design Partitioning (Design Hierarchy, Hierarchy in VHDL) Peter J. Ashenden, The Designer’s Guide to VHDL Chapter 1, Fundamental Concepts

3ECE 545 – Introduction to VHDL Register Transfer Logic (RTL) Design Description Combinational Logic Combinational Logic Registers … Today’s Topic

4ECE 545 – Introduction to VHDL VHDL Design Styles Components and interconnects structural VHDL Design Styles dataflow Concurrent statements behavioral Registers State machines Test benches Sequential statements Subset most suitable for synthesis

5ECE 545 – Introduction to VHDL VHDL Fundamentals

6ECE 545 – Introduction to VHDL Naming and Labeling (1) VHDL is not case sensitive Example: Names or labels databus Databus DataBus DATABUS are all equivalent

7ECE 545 – Introduction to VHDL Naming and Labeling (2) General rules of thumb (according to VHDL-87) 1.All names should start with an alphabet character (a-z or A-Z) 2.Use only alphabet characters (a-z or A-Z) digits (0-9) and underscore (_) 3.Do not use any punctuation or reserved characters within a name (!, ?,., &, +, -, etc.) 4.Do not use two or more consecutive underscore characters (__) within a name (e.g., Sel__A is invalid) 5.All names and labels in a given entity and architecture must be unique

8ECE 545 – Introduction to VHDL Free Format VHDL is a “free format” language No formatting conventions, such as spacing or indentation imposed by VHDL compilers. Space and carriage return treated the same way. Example: if (a=b) then or if (a=b)then or if (a = b) then are all equivalent

9ECE 545 – Introduction to VHDL Readability standards ESA VHDL Modelling Guidelines published by European Space Research and Technology Center in September 1994 available at the course web page

10ECE 545 – Introduction to VHDL Readability standards Selected issues covered by ESA Guidelines: Consistent Writing Style Consistent Naming Conventions Consistent Indentation Consistent Commenting Style Recommended File Headers File naming and contents Number of statements/declarations per line Ordering of port and signal declarations Constructs to avoid

11ECE 545 – Introduction to VHDL Comments Comments in VHDL are indicated with a “double dash”, i.e., “--”  Comment indicator can be placed anywhere in the line  Any text that follows in the same line is treated as a comment  Carriage return terminates a comment  No method for commenting a block extending over a couple of lines Examples: -- main subcircuit Data_in <= Data_bus; -- reading data from the input FIFO

12ECE 545 – Introduction to VHDL Comments Explain Function of Module to Other Designers Explanatory, Not Just Restatement of Code Locate Close to Code Described Put near executable code, not just in a header

13ECE 545 – Introduction to VHDL Modeling wires and buses

14ECE 545 – Introduction to VHDL Signals signal A : std_logic; signal B : std_logic_vector(7 downto 0); wire A bus B 1 8

15ECE 545 – Introduction to VHDL Standard Logic Vectors signal A: STD_LOGIC; signal B: STD_LOGIC_VECTOR(3 downto 0); signal C: STD_LOGIC_VECTOR(3 downto 0); signal D: STD_LOGIC_VECTOR(7 downto 0); signal E: STD_LOGIC_VECTOR(15 downto 0); signal F: STD_LOGIC_VECTOR(8 downto 0); ………. A <= ‘1’; B <= ”0000”; -- Binary base assumed by default C <= B”0000”; -- Binary base explicitly specified D <= ”0110_0111”; -- You can use ‘_’ to increase readability E <= X”AF67”; -- Hexadecimal base F <= O”723”; -- Octal base

16ECE 545 – Introduction to VHDL Describing Combinational Logic Using Dataflow Design Style

17ECE 545 – Introduction to VHDL Data-flow VHDL concurrent signal assignment (  ) conditional concurrent signal assignment (when-else) selected concurrent signal assignment (with-select-when) generate scheme for equations (for-generate) Major instructions Concurrent statements

18ECE 545 – Introduction to VHDL Data-flow VHDL concurrent signal assignment (  ) conditional concurrent signal assignment (when-else) selected concurrent signal assignment (with-select-when) generate scheme for equations (for-generate) Major instructions Concurrent statements

19ECE 545 – Introduction to VHDL Data-flow VHDL: Example

20ECE 545 – Introduction to VHDL Data-flow VHDL: Example LIBRARY ieee ; USE ieee.std_logic_1164.all ; ENTITY fulladd IS PORT (x, y, Cin: IN STD_LOGIC ; s, Cout: OUT STD_LOGIC ) ; END fulladd ; ARCHITECTURE LogicFunc OF fulladd IS BEGIN s <= x XOR y XOR Cin ; Cout <= (x AND y) OR (Cin AND x) OR (Cin AND y) ; END LogicFunc ;

21ECE 545 – Introduction to VHDL Logic Operators Logic operators Logic operators precedence and or nand nor xor not xnor not and or nand nor xor xnor Highest Lowest

22ECE 545 – Introduction to VHDL Wanted: Y = ab + cd Incorrect Y <= a and b or c and d equivalent to Y <= ((a and b) or c) and d equivalent to Y = (ab + c)d Correct Y <= (a and b) or (c and d) No Implied Precedence

23ECE 545 – Introduction to VHDL Concatenation signal A: STD_LOGIC_VECTOR(3 downto 0); signal B: STD_LOGIC_VECTOR(3 downto 0); signal C, D, E: STD_LOGIC_VECTOR(7 downto 0); A <= ”0000”; B <= ”1111”; C <= A & B; -- C = ” ” D <= ‘0’ & ” ”; -- D <= ” ” E <= ‘0’ & ‘0’ & ‘0’ & ‘0’ & ‘1’ & ‘1’ & ‘1’ & ‘1’; -- E <= ” ”

24ECE 545 – Introduction to VHDL Rotations in VHDL A(3) A(2) A(1) A(0) A(2)A(1)A(0)A(3) A<<<1 A_rotL <= A(2 downto 0) & A(3)

25ECE 545 – Introduction to VHDL Arithmetic Functions in VHDL (1) To use basic arithmetic operations involving std_logic_vectors you need to include the following library packages: library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all;

26ECE 545 – Introduction to VHDL Arithmetic Functions in VHDL (2) You can use standard +, - operators to perform addition and subtraction: signal A : STD_LOGIC_VECTOR(3 downto 0); signal B : STD_LOGIC_VECTOR(3 downto 0); signal C : STD_LOGIC_VECTOR(3 downto 0); …… C <= A + B;

27ECE 545 – Introduction to VHDL Data-flow VHDL concurrent signal assignment (  ) conditional concurrent signal assignment (when-else) selected concurrent signal assignment (with-select-when) generate scheme for equations (for-generate) Major instructions Concurrent statements

28ECE 545 – Introduction to VHDL Data Flow Instructions (1) target_signal <= value1 when condition1 else value2 when condition2 else... valueN-1 when conditionN-1 else valueN; When - Else.… Value N Value N-1 Condition N-1 Condition 2 Condition 1 Value 2 Value 1 Target Signal …

29ECE 545 – Introduction to VHDL Operators Relational operators Logic and relational operators precedence = /= >= not = /= >= and or nand nor xor xnor Highest Lowest

30ECE 545 – Introduction to VHDL compare a = bc Incorrect … when a = b and c else … equivalent to … when (a = b) and c else … Correct … when a = (b and c) else … Priority of logic and relational operators

31ECE 545 – Introduction to VHDL Data-flow VHDL concurrent signal assignment (  ) conditional concurrent signal assignment (when-else) selected concurrent signal assignment (with-select-when) generate scheme for equations (for-generate) Major instructions Concurrent statements

32ECE 545 – Introduction to VHDL Data Flow Instructions (2) with choice_expression select target_signal <= expression1 when choices1, expression2 when choices2,... expressionN when choicesN; With - Select choices1 choices2 choicesN expression1 target_signal choice expression expression2 expressionN

33ECE 545 – Introduction to VHDL MLU Example

34ECE 545 – Introduction to VHDL MLU: Block Diagram

35ECE 545 – Introduction to VHDL MLU: Entity Declaration library IEEE; use IEEE.STD_LOGIC_1164.all; entity MLU is port( NEG_A : in STD_LOGIC; NEG_B : in STD_LOGIC; NEG_Y : in STD_LOGIC; A : in STD_LOGIC; B : in STD_LOGIC; L1 : in STD_LOGIC; L0 : in STD_LOGIC; Y : out STD_LOGIC ); end MLU;

36ECE 545 – Introduction to VHDL MLU: Architecture Declarative Section architecture MLU_DATAFLOW of MLU is signal A1:STD_LOGIC; signal B1:STD_LOGIC; signal Y1:STD_LOGIC; signal MUX_0:STD_LOGIC; signal MUX_1:STD_LOGIC; signal MUX_2:STD_LOGIC; signal MUX_3:STD_LOGIC; signal L: STD_LOGIC_VECTOR(1 downto 0);

37ECE 545 – Introduction to VHDL MLU - Architecture Body begin A1<= not A when (NEG_A='1') else A; B1<= not B when (NEG_B='1') else B; Y <= not Y1 when (NEG_Y='1') else Y1; MUX_0 <= A1 and B1; MUX_1 <= A1 or B1; MUX_2 <= A1 xor B1; MUX_3 <= A1 xnor B1; L<=L1 & L0; with (L) select Y1 <= MUX_0 when "00", MUX_1 when "01", MUX_2 when "10", MUX_3 when others; end MLU_DATAFLOW;

38ECE 545 – Introduction to VHDL Data-flow VHDL concurrent signal assignment (  ) conditional concurrent signal assignment (when-else) selected concurrent signal assignment (with-select-when) generate scheme for equations (for-generate) Major instructions Concurrent statements

39ECE 545 – Introduction to VHDL PARITY Example

40ECE 545 – Introduction to VHDL PARITY: Block Diagram

41ECE 545 – Introduction to VHDL For Generate Statement For Generate name: for parameter_specification generate [Declaration Statements] begin {Concurrent Statements} end generate name;

42ECE 545 – Introduction to VHDL PARITY: Entity Declaration library IEEE; use IEEE.STD_LOGIC_1164.all; entity PARITY is port( Parity_in : in STD_LOGIC_VECTOR(7 downto 0); Parity_out : out STD_LOGIC ); end PARITY;

43ECE 545 – Introduction to VHDL PARITY: Block Diagram Xor_out(1) Xor_out(2) Xor_out(3) Xor_out(4) Xor_out(5) Xor_out(6) Xor_out(7)

44ECE 545 – Introduction to VHDL PARITY: Architecture architecture PARITY_DATAFLOW of PARITY is signal Xor_out: std_logic_vector (7 downto 1); begin Xor_out(1) <= Parity_in(0) xor Parity_in(1); G2: for i in 1 to 6 generate Xor_out(i+1) <= Xor_out(i) xor Parity_in(i+1); end generate G2; Parity_out <= Xor_out(7); end PARITY_DATAFLOW;

45ECE 545 – Introduction to VHDL Verifying the operation of the circuit using testbenches

46ECE 545 – Introduction to VHDL Testbench Block Diagram Testbench Processes Generating Stimuli Design Under Test (DUT) Observed Outputs

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

48ECE 545 – Introduction to VHDL Testbench Anatomy Entity TB is --TB entity has no ports End TB; Architecture arch_TB of TB is --Local signals and constants component TestComp --All Design Under Test component declarations port ( ); end component; for DUT:TestComp use entity work.TestComp(archName)--Specify entity/arch pair -- (OPTIONAL) begin testSequence: Process --Main test process end process; DUT:TestComp port map( --Port map all the DUTs ); End arch_TB;

49ECE 545 – Introduction to VHDL Testbench For XOR3 library ieee; use ieee.std_logic_1164.all; entity XOR3_TB is end XOR3_TB; architecture XOR3_TB_ARCHITECTURE of XOR3_TB is -- Component declaration of the tested unit component xor3 port( A : in std_logic; B : in std_logic; C : in std_logic; RESULT : out std_logic ); end component; -- Stimulus signals - signals mapped to the input and inout ports of tested entity signal TEST_VECTOR:STD_LOGIC_VECTOR(2 downto 0); signal TEST_RESULT: STD_LOGIC;

50ECE 545 – Introduction to VHDL Testbench For XOR Gate(2) begin UUT : xor3 port map ( A => TEST_VECTOR(0), B => TEST_VECTOR(1), C => TEST_VECTOR(2), RESULT => TEST_RESULT); ); TESTING: process begin TEST_VECTOR<="000"; wait for 10 ns; TEST_VECTOR<="001"; wait for 10 ns; TEST_VECTOR<="010"; wait for 10 ns; TEST_VECTOR<="011"; wait for 10 ns; TEST_VECTOR<="100"; wait for 10 ns; TEST_VECTOR<="101"; wait for 10 ns; TEST_VECTOR<="110"; wait for 10 ns; TEST_VECTOR<="111"; wait for 10 ns; end process TESTING; end XOR3_TB_ARCHITECTURE;

51ECE 545 – Introduction to VHDL Execution of statements in a PROCESS The execution of statements continues sequentially till the last statement in the process. After execution of the last statement, the control is again passed to the beginning of the process. TESTING: process begin TEST_VECTOR<=“00”; wait for 10 ns; TEST_VECTOR<=“01”; wait for 10 ns; TEST_VECTOR<=“10”; wait for 10 ns; TEST_VECTOR<=“11”; wait for 10 ns; end process TESTING; Order of execution Program control is passed to the first statement after BEGIN

52ECE 545 – Introduction to VHDL PROCESS with a WAIT Statement The last statement in the PROCESS is a WAIT instead of WAIT FOR 10 ns. This will cause the PROCESS to suspend indefinitely when the WAIT statement is executed. This form of WAIT can be used in a process included in a testbench when all possible combinations of inputs have been tested or a non-periodical signal has to be generated. TESTING: process begin TEST_VECTOR<=“00”; wait for 10 ns; TEST_VECTOR<=“01”; wait for 10 ns; TEST_VECTOR<=“10”; wait for 10 ns; TEST_VECTOR<=“11”; wait; end process TESTING; Program execution stops here Order of execution

53ECE 545 – Introduction to VHDL Wait for vs. Wait Wait for: waveform will keep repeating itself forever Wait : waveform will keep its state after the last wait instruction … …

54ECE 545 – Introduction to VHDL Sequential Statements (3) Loop Statement Repeats a Section of VHDL Code Example: process every element in an array in the same way for i in range loop statements end loop;

55ECE 545 – Introduction to VHDL TEST_DATA_GENERATOR: process begin TEST_AB<="00"; TEST_SEL<="00"; for I in 0 to 3 loop for J in 0 to 3 loop wait for 10 ns; TEST_AB<=TEST_AB+"01"; end loop; TEST_SEL<=TEST_SEL+"01"; end loop; end process; Loop Statement - Example

56ECE 545 – Introduction to VHDL Structural Design Style

57ECE 545 – Introduction to VHDL Structural VHDL component instantiation (port map) generate scheme for component instantiations (for-generate) component instantiation with generic (generic map, port map) Major instructions

58ECE 545 – Introduction to VHDL Structural VHDL component instantiation (port map) generate scheme for component instantiations (for-generate) component instantiation with generic (generic map, port map) Major instructions

59ECE 545 – Introduction to VHDL Structural Example: Component NAND2 Instantiated Four Time in1 in2 nand_out

60ECE 545 – Introduction to VHDL Structural VHDL component instantiation (port map) generate scheme for component instantiations (for-generate) component instantiation with generic (generic map, port map) Major instructions

61ECE 545 – Introduction to VHDL Iterative circuits: 8-bit comparator A(7)B(7) CMP_IN(1) CMP_IN(0) A(6)B(6)A(0)B(0) CMP_OUT(1) CMP_OUT(0) entity COMPARE8 is port( A, B: in STD_LOGIC_VECTOR(7 downto 0); CMP_IN: in STD_LOGIC_VECTOR(1 downto 0); CMP_OUT: out STD_LOGIC_VECTOR(1 downto 0)); end COMPARE8; COMPARE8

62ECE 545 – Introduction to VHDL 8-bit comparator: Truth Table CMP_INCMP_OUT if A=B 10 if A>B 01 if A<B independently of A and B independently of A and B 11 (invalid inputs) --

63ECE 545 – Introduction to VHDL AB X_OUT Y_OUT BIT_COMPARE entity BIT_COMPARE is port(A, B, X_IN, Y_IN: in STD_LOGIC; X_OUT, Y_OUT: out STD_LOGIC); end BIT_COMPARE; X_IN Y_IN Basic building block

64ECE 545 – Introduction to VHDL X_IN & Y_INX_OUT & Y_OUT if A=B 10 if A=‘1’ and B=‘0’ 01 if A=‘0’ and B=‘1’ independently of A and B independently of A and B 11 (invalid inputs) -- Basic building block – Truth Table

65ECE 545 – Introduction to VHDL 8-bit comparator - Architecture A(7)B(7) CMP_IN(1) CMP_IN(0) A(6)B(6)A(0)B(0) CMP_OUT(1) CMP_OUT(0) INT_X(7) INT_X(1) INT_Y(7) INT_Y(1) INT_X(6) INT_Y(6)

66ECE 545 – Introduction to VHDL architecture STRUCTURE of COMPARE8 is component BIT_COMPARE port(A, B, X_IN, Y_IN: in STD_LOGIC; X_OUT, Y_OUT: out STD_LOGIC); end component; signal INT_X, INT_Y: STD_LOGIC_VECTOR(7 downto 1); begin C7: BIT_COMPARE port map(A(7), B(7), CMP_IN(1), CMP_IN(0), INT_X(7), INT_Y(7)); C6: BIT_COMPARE port map(A(6), B(6), INT_X(7), INT_Y(7), INT_X(6), INT_Y(6));... C0: BIT_COMPARE port map(A(0), B(0), INT_X(1), INT_Y(1), CMP_OUT(0), CMP_OUT(1)); end STRUCTURE; Architecture without for-generate

67ECE 545 – Introduction to VHDL 8-bit comparator - Architecture A(7)B(7) CMP_IN(1) CMP_IN(0) A(6)B(6)A(0)B(0) CMP_OUT(1) CMP_OUT(0) INT_X(7)INT_X(1) INT_Y(7) INT_Y(1) INT_X(8) INT_Y(8) INT_X(0) INT_Y(0)

68ECE 545 – Introduction to VHDL architecture STRUCTURE of COMPARE8 is component BIT_COMPARE port(A, B, X_IN, Y_IN: in STD_LOGIC; X_OUT, Y_OUT: out STD_LOGIC); end component; signal INT_X, INT_Y: STD_LOGIC_VECTOR(8 downto 0); begin INT_X(8) <= CMP_IN(1); INT_Y(8) <= CMP_IN(0); CASCADE: for I in 7 downto 0 generate C: BIT_COMPARE port map(A(I), B(I), INT_X(I+1), INT_Y(I+1), INT_X(I), INT_Y(I)); end generate; CMP_OUT(1) <= INT_X(0); CMP_OUT(0) <= INT_Y(0); end STRUCTURE; Architecture with for-generate

69ECE 545 – Introduction to VHDL Structural VHDL component instantiation (port map) generate scheme for component instantiations (for-generate) component instantiation with generic (generic map, port map) Major instructions

70ECE 545 – Introduction to VHDL N-bit Comparator – Entity declaration entity COMPAREN is generic(N: positive); -- N – width of operands port( A, B: in BIT_VECTOR(N-1 downto 0); CMP_IN: in BIT_VECTOR(1 downto 0); CMP_OUT: out BIT_VECTOR(1 downto 0)); end COMPAREN;

71ECE 545 – Introduction to VHDL architecture STRUCTURE of COMPAREN is component BIT_COMPARE port(A, B, X_IN, Y_IN: in STD_LOGIC; X_OUT, Y_OUT: out STD_LOGIC); end component; signal INT_X, INT_Y: STD_LOGIC_VECTOR(N downto 0); begin INT_X(N) <= CMP_IN(1); INT_Y(N) <= CMP_IN(0); CASCADE: for I in N-1 downto 0 generate C: BIT_COMPARE port map(A(I), B(I), INT_X(I+1), INT_Y(I+1), INT_X(I), INT_Y(I)); end generate; CMP_OUT(1) <= INT_X(0); CMP_OUT(0) <= INT_Y(0); end STRUCTURE; N-bit Comparator – Architecture

72ECE 545 – Introduction to VHDL component COMPAREN generic(N: positive); -- N – width of operands port( A, B: in STD_LOGIC_VECTOR(N downto 0); CMP_IN: in STD_LOGIC_VECTOR(1 downto 0); CMP_OUT: out STD_LOGIC_VECTOR(1 downto 0)); end component; ……… CMP8: COMPAREN generic map(N => 16) port map(A => P1, B => P2, CMP_IN => SIG_IN, CMP_OUT => SIG_OUT ); N-bit Comparator – Instantiation