Introduction to VHDL 182007 L 2 VHDL Introcution

  • Slides: 22
Download presentation
Introduction to VHDL 1/8/2007 - L 2 VHDL Introcution © Copyright 2012 - Joanne

Introduction to VHDL 1/8/2007 - L 2 VHDL Introcution © Copyright 2012 - Joanne De. Groat, ECE, OSU 1

Lecture overview o o An introduction to VHLD At the structural level At the

Lecture overview o o An introduction to VHLD At the structural level At the mixed level At the behavioral level 1/8/2007 - L 2 VHDL Introcution © Copyright 2012 - Joanne De. Groat, ECE, OSU 2

Overview o HDL – Hardware Description Language n o o o A language that

Overview o HDL – Hardware Description Language n o o o A language that allows description of hardware for documentation, simulation, synthesis, verification, … To use an HDL you need a CAD system that supports it. Major CAD systems support VHDL, Verilog, System C, System Verilog CAD systems (just some of them) n n n Cadence Mentor Graphics (Model Sim) – Model. Sim, Questa Altera, XILINX (are a part of Mentor) Synopsis – Typical tools but mainly toward synthesis and ASIC production from HDL descriptions In the formal space there are many small companies 1/8/2007 - L 2 VHDL Introcution © Copyright 2012 - Joanne De. Groat, ECE, OSU 3

Common to all systems o o Have source HDL file Structure of generated files

Common to all systems o o Have source HDL file Structure of generated files is common 1/8/2007 - L 2 VHDL Introcution © Copyright 2012 - Joanne De. Groat, ECE, OSU 4

A First Example o o Desire to do a VHDL description of a full

A First Example o o Desire to do a VHDL description of a full adder. A device consists of n An Interface n An operational part Interface – The INPUTS AND OUTPUTS Operational Part – The FUNCTIONAL BEHAVIOR 1/8/2007 - L 2 VHDL Introcution © Copyright 2012 - Joanne De. Groat, ECE, OSU 5

VHDL Entity Design Unit o o Specifies the interface part Format n n n

VHDL Entity Design Unit o o Specifies the interface part Format n n n o For a full adder would have: n n n o ENTITY unit_name IS [port_clause] END unit_name; ENTITY full_adder IS PORT(a, b, cin : IN bit; sum : OUT bit; cout : OUT bit); END full_adder; The PORT portion is termed a Port Clause n Signals specified in the port clause have scope over all architectures of this entity 1/8/2007 - L 2 VHDL Introcution © Copyright 2012 - Joanne De. Groat, ECE, OSU 6

Signals/Port Modes/Types o o PORT(a, b, cin: IN bit; sum: OUT bit; cout: OUT

Signals/Port Modes/Types o o PORT(a, b, cin: IN bit; sum: OUT bit; cout: OUT bit); Signals: Names referenced in the Port Clause are signals. n n o A, b, cin, sum, cout represent wires of the physical unit. SIGNALS are objects that have both a value and a time component. Port Modes: In this example you have inputs and outputs. The Port Mode specifies the direction of the signal transfer and imply a couple of other properties of the port. 1/8/2007 - L 2 VHDL Introcution © Copyright 2012 - Joanne De. Groat, ECE, OSU 7

Signals/Port Modes/Types o Modes: n n IN – signal can only be used (i.

Signals/Port Modes/Types o Modes: n n IN – signal can only be used (i. e. , can only be read or can only be used on the right-hand-side of an equation). CANNOT BE ASSIGNED TO!! OUT – signal value can only be written. Cannot be seen or used in the design as it is an output and therefore external. INOUT – signal can be both written to (assigned to) and read (used). However, signals of this type are connected to busses and therefore this signal mode requires the signal to be resolved. BUFFER – signal value can be written to and used internally in the design. 1/8/2007 - L 2 VHDL Introcution © Copyright 2012 - Joanne De. Groat, ECE, OSU 8

Basic Types o o Built in – part of the standard and the language

Basic Types o o Built in – part of the standard and the language proper. TYPE BIT – your typical binary type with values of ‘ 0’ and ‘ 1’. n Declaration that established this type o n n n o TYPE BIT is (‘ 0’, ‘ 1’); Use of SIGNALS of TYPE bit a <= ‘ 0’; b <= x AND y OR z; Note that the value is either ‘ 0’ or ‘ 1’ 1/8/2007 - L 2 VHDL Introcution © Copyright 2012 - Joanne De. Groat, ECE, OSU 9

Architectural Design Unit o Specifies the operational part n n n ARCHITECTURE identifier OF

Architectural Design Unit o Specifies the operational part n n n ARCHITECTURE identifier OF entity_id IS [declarations] BEGIN [architecture_statement_part] END [identifier]; [architecture_statement_part] – Any concurrent statement of the language 1/8/2007 - L 2 VHDL Introcution © Copyright 2012 - Joanne De. Groat, ECE, OSU 10

Example of Architecture o For a full adder n n n o ARCHITECTURE one

Example of Architecture o For a full adder n n n o ARCHITECTURE one OF fulladder IS BEGIN sum <= a XOR b XOR cin; cout <= (a AND b) OR (a AND cin) OR (b AND cin); END one; Architecture has 2 concurrent statements 1/8/2007 - L 2 VHDL Introcution © Copyright 2012 - Joanne De. Groat, ECE, OSU 11

Consider a 4 bit Adder o o o This hardware is to be modeled

Consider a 4 bit Adder o o o This hardware is to be modeled in VHDL First will do a dataflow model for the unit as a whole. Will create two alternative dataflow models. Then will create a structural model where the leaf units are basic gates. 1/8/2007 - L 2 VHDL Introcution © Copyright 2012 - Joanne De. Groat, ECE, OSU 12

A Multibit Adder Example o Will model using a dataflow style n n o

A Multibit Adder Example o Will model using a dataflow style n n o Bit Vectors for ports and individual signals internally Bit Vectors for ports and bit vectors internally The Entity Design Unit (same for both) n n n ENTITY mb_adder IS PORT(a, b : IN bit_vector(3 downto 0); cin : IN bit; cout : OUT bit; sum : OUT bit_vector(3 downto 0)); END mb_adder; 1/8/2007 - L 2 VHDL Introcution © Copyright 2012 - Joanne De. Groat, ECE, OSU 13

The first dataflow Architecture o o o o o ARCHITECTURE one OF mb_adder IS

The first dataflow Architecture o o o o o ARCHITECTURE one OF mb_adder IS SIGNAL c : BIT_VECTOR (4 downto 0); BEGIN c(0) <= cin; sum(0) <= a(0) XOR b(0) XOR c(0); sum(1) <= a(1) XOR b(1) XOR c(1); sum(2) <= a(2) XOR b(2) XOR c(2); sum(3) <= a(3) XOR b(3) XOR c(3); c(1) <= (a(0) AND b(0)) OR (a(0) AND c(0)) OR (b(0) AND c(0)); c(2) <= (a(1) AND b(1)) OR (a(1) AND c(1)) OR (b(1) AND c(1)); c(3) <= (a(2) AND b(2)) OR (a(2) AND c(2)) OR (b(2) AND c(2)); c(4) <= (a(3) AND b(3)) OR (a(3) AND c(3)) OR (b(3) AND c(3)); Cout <= c(4); END one; 1/8/2007 - L 2 VHDL Introcution © Copyright 2012 - Joanne De. Groat, ECE, OSU 14

The Second Dataflow Architecture n n n n n o o ARCHITECTURE two OF

The Second Dataflow Architecture n n n n n o o ARCHITECTURE two OF mb_adder IS SIGNAL c : BIT_VECTOR (4 downto 0); BEGIN c(0) <= cin; sum <= a XOR b XOR c(3 downto 0); c(4 downto 1) <= (a(3 downto 0) AND b(3 downto 0)) OR (a(3 downto 0) AND c(3 downto 0)) OR (b(3 downto 0) AND c(3 downto 0)); Cout <= c(4); END two; Note the power of this HDL specification The Carry ripples through repeated evaluations of the equation as whenever a signal on the right-hand-side changes, the equation is re -evaluated and a new value scheduled for assignment to the signal. 1/8/2007 - L 2 VHDL Introcution © Copyright 2012 - Joanne De. Groat, ECE, OSU 15

Operations on Type BIT o Consider the following declaration n o Logical Operations n

Operations on Type BIT o Consider the following declaration n o Logical Operations n n n n o SIGNAL x, y : bit; x AND y Also have shift operations x OR y arithmetic shifts ASR ASL x NAND y x NOR y logical shifts LSR LSL x XOR y x XNOR y these work on vectors NOT y NOTE: For logical expressions the equation is only evaluated until the result is determined. 1/8/2007 - L 2 VHDL Introcution © Copyright 2012 - Joanne De. Groat, ECE, OSU 16

Assignment and Relational Operators o Assignment Operators n n o For signal <= For

Assignment and Relational Operators o Assignment Operators n n o For signal <= For variables : = Relational Operators n n n (x=y) (x/=y) (x<=y) (x>=y) Example of use (x=‘ 1’) AND (y=‘ 0’) 1/8/2007 - L 2 VHDL Introcution © Copyright 2012 - Joanne De. Groat, ECE, OSU 17

Structural Example o o o Again consider the full adder Before doing a structural

Structural Example o o o Again consider the full adder Before doing a structural description must have the components that are going to be wired together. These must first be written and compiled into the library. Only the ENTITIES are given. Each would have an architecture. n n n o ENTITY and 2 IS PORT (A, B : IN BIT; Z : OUT BIT); END and 2; ENTITY xor 2 IS PORT (A, B : IN BIT; Z : OUT BIT); END xor; n n n ENTITY or 3 IS PORT (A, B, C : IN BIT; Z : OUT BIT); END or 3; 1/8/2007 - L 2 VHDL Introcution © Copyright 2012 - Joanne De. Groat, ECE, OSU 18

Structural Example for a full adder o The first part n n n n

Structural Example for a full adder o The first part n n n n n ARCHITECTURE structural OF full_adder IS -- Must declare the components that are to be used COMPONENT and 2 PORT (A, B : IN BIT; Z : OUT BIT); END COMPONENT ; COMPONENT xor 2 PORT (A, B : IN BIT; Z : OUT BIT); END COMPONENT ; COMPONENT or 3 PORT (A, B, C : IN BIT; Z : OUT BIT); END COMPONENT ; -- State which library to find them in and which architecture to use. FOR ALL : and 2 USE ENTITY WORK. and 2(behavioral); FOR ALL : xor 2 USE ENTITY WORK. xor 2(behavioral); FOR ALL : or 3 USE ENTITY WORK. or 3(behavioral); -- Declare local signals required. SIGNAL addt. ct 1, ct 2, ct 3 : BIT; 1/8/2007 - L 2 VHDL Introcution © Copyright 2012 - Joanne De. Groat, ECE, OSU 19

The second part of the Architecture o From the BEGIN n n n BEGIN

The second part of the Architecture o From the BEGIN n n n BEGIN G 1: xor 2 PORT MAP(a, b, addt); G 2: xor 2 PORT MAP(addt, cin, sum); G 3: and 2 PORT MAP(a, b, ct 1); G 4: and 2 PORT MAP(a, cin, ct 2); G 5: and 2 PORT MAP(b, cin, ct 3); G 6: or 3 PORT MAP(ct 1, ct 2, ct 3, cout); END Structural; 1/8/2007 - L 2 VHDL Introcution © Copyright 2012 - Joanne De. Groat, ECE, OSU 20

Multibit adder o o Can use the structural full adder to wire up a

Multibit adder o o Can use the structural full adder to wire up a multibit adder The ENTITY Design Unit n n n o ENTITY mb_adder IS PORT (a, b : IN BIT_VECTOR(3 downto 0); cin : IN BIT; cout : OUT BIT; sum: OUT BIT_VECTOR(3 downto 0)); END mb_adder; Entity is the same as before 1/8/2007 - L 2 VHDL Introcution © Copyright 2012 - Joanne De. Groat, ECE, OSU 21

The multibit Architecture o o o o ARCHITECTURE structural OF mb_adder IS -- Must

The multibit Architecture o o o o ARCHITECTURE structural OF mb_adder IS -- Must declare the components that are to be used COMPONENT full_adder PORT( a, b, cin : IN BIT; sum : OUT BIT; cout : OUT BIT); END COMPONENT; FOR ALL full_adder USE ENTITY work. full_adder(structural); SIGNAL ic 1, ic 2, ic 3 : BIT; BEGIN U 0: full_adder(a(0), b(0), cin, sum(0), ic 1); U 1: full_adder(a(1), b(1), ic 1, sum(1), ic 2); U 2: full_adder(a(2), b(2), ic 2, sum(2), ic 3); U 3: full_adder(a(3), b(3), ic 3, sum(3), cout); END structural; 1/8/2007 - L 2 VHDL Introcution © Copyright 2012 - Joanne De. Groat, ECE, OSU 22