Top Banner
INTRODUCTION TO VHDL Mridula Allani Fall 2010 (Refer to the comments if required) ELEC2200-001 Fall 2010, Nov 2 1 (Adopted from Profs. Nelson and Stroud)
39

Introduction to VHDL

Feb 24, 2016

Download

Documents

Introduction to VHDL. Mridula Allani Fall 2010 (Refer to the comments if required). HDLs in Digital System Design. Model and document digital systems Hierarchical models System, RTL (Register Transfer Level), gates Different levels of abstraction Behavior, structure - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Introduction to VHDL

1

INTRODUCTION TO VHDL

Mridula AllaniFall 2010

(Refer to the comments if required)

ELEC2200-001 Fall 2010, Nov 2

(Adopted from Profs. Nelson and Stroud)

Page 2: Introduction to VHDL

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

ELEC2200-001 Fall 2010, Nov 2 2(Adopted from Profs. Nelson and Stroud)

Page 3: Introduction to VHDL

Hardware Description Languages

VHDL = VHSIC Hardware Description Language (VHSIC = Very High Speed Integrated Circuits) Developed by DOD from 1983 – based on ADA IEEE Standard 1076-1987/1993/200x Based on the ADA language

Verilog – created in 1984 by Philip Moorby of Gateway Design Automation (merged with Cadence) IEEE Standard 1364-1995/2001/2005 Based on the C language IEEE P1800 “System Verilog” in voting stage &

will be merged with 1364ELEC2200-001 Fall 2010, Nov 2 3(Adopted from Profs. Nelson and Stroud)

Page 4: Introduction to VHDL

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

ELEC2200-001 Fall 2010, Nov 2 4

A

B

Cin

Sum

Cout

Full Adder

(Adopted from Profs. Nelson and Stroud)

Page 5: Introduction to VHDL

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;

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

ELEC2200-001 Fall 2010, Nov 2 5(Adopted from Profs. Nelson and Stroud)

Page 6: Introduction to VHDL

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; ELEC2200-001 Fall 2010,

Nov 2 6(Adopted from Profs. Nelson and Stroud)

mza0020
Use these two statements at the begining of your VHDL program.
Page 7: Introduction to VHDL

Entity formatENTITY 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;

ELEC2200-001 Fall 2010, Nov 2 7(Adopted from Profs. Nelson and Stroud)

mza0020
You can assign a value to a 'Generic' variable and use the variable thoughout the program. When you wish to change the value, you will not be required to change it in the entire program.
mza0020
'mode' in this case implies input and output (IN, OUT). 'signal_type' corresponds to std_logic, std_logic vector, etc.
mza0020
The semi-colon for the last sinal comes after to the closing paranthesis.
Page 8: Introduction to VHDL

ELEC2200-001 Fall 2010, Nov 2

(Adopted from Profs. Nelson and Stroud) 8

Full-Adder Adds Three Bits

a

b

XOR

AND

XOR

AND OR

c_in

sum

c_out

FAh_s(a, b)

c_o(a, b)

h_s(h_s(a, b), c_in)

c_o(h_s(a, b), c_in)

HA HA

mza0020
Refer to this schematic to compare the example entity and architecture.
Page 9: Introduction to VHDL

Entity example (1-Bit Full Adder)

ENTITY Full_adder IS PORT ( -- I/O ports

a: IN STD_LOGIC; -- a input b: IN STD_LOGIC; -- b input cin: IN STD_LOGIC; -- carry input sum: OUT STD_LOGIC; -- sum output cout: OUT STD_LOGIC); -- carry output

END Full_adder ;

ELEC2200-001 Fall 2010, Nov 2 9

A

B

Cin

Sum

Cout

Full Adder

(Adopted from Profs. Nelson and Stroud)

mza0020
STD_LOGIC, STD_LOGIC_VECTOR signal types are defined in IEEE.std_logic_1164.all library.
Page 10: Introduction to VHDL

Architecture formatARCHITECTURE 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;ELEC2200-001 Fall 2010, Nov 2 10(Adopted from Profs. Nelson and Stroud)

mza0020
Internal signals are the signals generated from individual components. These can be considered as wires connecting different components withing the system. Their signal type is 'std_logic'. The mode is not specified ad they do not form the I/O ports of the system.
mza0020
Component declarations are used in structural form of architecture where lower-level heirarchial componets (described in different VHDL files) are declared.The component declaration matches the respective component's netity declaration, except that the keyword 'entity' is repaced by the keyword 'component'.
Page 11: Introduction to VHDL

Dataflow architecture example

ARCHITECTURE dataflow OF Full_adder ISBEGIN

sum <= a xor b xor cin; cout <= (a and b) or (a and cin) or

(b and cin);END dataflow;

ELEC2200-001 Fall 2010, Nov 2 11(Adopted from Profs. Nelson and Stroud)

mza0020
Signal assignment operator.
mza0020
Refer to slides 8 and 9 for the correlation.
mza0020
Refer to slides 8 and 9 for the correlation.
Page 12: Introduction to VHDL

Structural architecture example

ARCHITECTURE structure OF Full_adder ISCOMPONENT xor IS -- declare component to be usedPORT (x,y: IN STD_LOGIC;z: OUT STD_LOGIC);END COMPONENT xor;COMPONENT or IS -- declare component to be usedPORT (x,y: IN STD_LOGIC;z: OUT STD_LOGIC);END COMPONENT or;

COMPONENT and IS -- declare component to be usedPORT (x,y,z: IN STD_LOGIC;p: OUT STD_LOGIC);END COMPONENT xor;

SIGNAL x1,x2,x3,x4: STD_LOGIC; -- signal internal to this componentBEGIN

G1: xor PORT MAP (a, b, x1); -- instantiate 1st xor gateG2: xor PORT MAP (x1, Cin, Sum); -- instantiate 2nd xor gateG3: or PORT MAP (a, b, x2); -- instantiate 1st or gateG4: or PORT MAP (a, Cin, x3); -- instantiate 2nd or gateG5: or PORT MAP (b, Cin, x4); -- instantiate 3rd or gateG6: and PORT MAP (x2, x3, x4, Cout); -- instantiate and gate

END structure;

ELEC2200-001 Fall 2010, Nov 2 12(Adopted from Profs. Nelson and Stroud)

Full-adder

mza0020
mza002011/3/2010Component declarations are used in structural form of architecture where lower-level heirarchial componets (described in different VHDL files) are declared.The component declaration matches the respective component's netity declaration, except that the keyword 'entity' is repaced by the keyword 'component'.
mza0020
The order of input and output signals in the port list of Component intantiation statements should be the same as the order in their component declarations. Alternatively, we can assign the signals with signal assignment operator '<=' to indicate which signal in the component instantiation corresponds to which signal in th ecomponent declaration.For example,G1: xor PORT MAP (a<=x, b<=y, x1<=z);
Page 13: Introduction to VHDL

Alternative structural architecture example

ARCHITECTURE structural OF Full_adder IS

COMPONENT half_adderPORT(a,b : IN STD_LOGIC;sum, carry : OUT STD_LOGIC);END COMPONENT;

COMPONENT or_2PORT(a,b : IN STD_LOGIC;c : OUT STD_LOGIC);END COMPONENT;

SIGNAL int1, int2, int3 : STD_LOGIC;

BEGIN

H1: half_adder port map(a=>A, b=>B, sum=>int1, carry=>int3);H2: half_adder port map(a=>s1, b=>C_in, sum=>sum, carry=>s2);O1: or_2 port map(a=> int2, b=>int3, c=>C_out);

END structural;

13

ENTITY half_adder IS

PORT (a,b : IN STD_LOGIC ;sum,carry : OUT STD_LOGIC);

END half_adder;

ARCHITECTURE dataflow OF half_adder IS

BEGIN

sum<= a xor b;carry <= a and b;

END dataflow;

ENTITY or_2 IS

PORT (a,b : IN STD_LOGIC ;c : OUT STD_LOGIC);

END or_2;

ARCHITECTURE dataflow OF or_2 IS

BEGIN

c<= a or b;

END dataflow;

ELEC2200-001 Fall 2010, Nov 2

Each Half-adderFull-adder

Full-adder

(Adopted from Profs. Nelson and Stroud)

mza0020
mza002011/3/2010mza002011/3/2010Component declarations are used in structural form of architecture where lower-level heirarchial componets (described in different VHDL files) are declared.The component declaration matches the respective component's netity declaration, except that the keyword 'entity' is repaced by the keyword 'component'.
mza0020
mza002011/3/2010The order of input and output signals in the port list of Component intantiation statements should be the same as the order in their component declarations. Alternatively, we can assign the signals with signal assignment operator '<=' to indicate which signal in the component instantiation corresponds to which signal in th ecomponent declaration.For example,G1: xor PORT MAP (a<=x, b<=y, x1<=z);
Page 14: Introduction to VHDL

14

library  ieee;use  ieee.std_logic_1164.all;

ENTITY adder_4bit IS     PORT (a, b: IN STD_LOGIC_VECTOR(3 DOWNTO 0);           Cin : IN STD_LOGIC;                sum: OUT STD_LOGIC_VECTOR (3 DOWNTO

0);                Cout: OUT STD_LOGIC);     END adder_4bit;

ARCHITECTURE structural OF adder_4bit IS

     SIGNAL c: STD_LOGIC_VECTOR (4 DOWNTO 0);

COMPONENT Full_adder           PORT(a, b, c: IN STD_LOGIC; sum, carry: OUT STD_LOGIC);           END COMPONENT;

ELEC2200-001 Fall 2010, Nov 2

Extending full-adder circuit to multiple-bit adition

BEGIN

           FA0: Full_adder                PORT MAP (a(0), b(0), Cin, sum(0), c(1));           FA1: Full_adder                PORT MAP (a(1), b(1), C(1), sum(1), c(2));           FA2: Full_adder                PORT MAP (a(2), b(2), C(2), sum(2), c(3));           FA3: Full_adder                PORT MAP (a(3), b(3), C(3), sum(3), c(4));                     Cout <= c(4);

END structural;

(Adopted from Profs. Nelson and Stroud)

mza0020
mza002011/3/2010The order of input and output signals in the port list of Component intantiation statements should be the same as the order in their component declarations. Alternatively, we can assign the signals with signal assignment operator '<=' to indicate which signal in the component instantiation corresponds to which signal in th ecomponent declaration.For example,G1: xor PORT MAP (a<=x, b<=y, x1<=z);
mza0020
mza002011/3/2010mza002011/3/2010mza002011/3/2010Component declarations are used in structural form of architecture where lower-level heirarchial componets (described in different VHDL files) are declared.The component declaration matches the respective component's netity declaration, except that the keyword 'entity' is repaced by the keyword 'component'.
Page 15: Introduction to VHDL

Behavioral architecture example ARCHITECTURE behavioral OF

Full_adder ISBEGIN

Sum: PROCESS(a, b, cin)BEGIN

sum <= a xor b xor cin;END PROCESS Sum;Carry: PROCESS(a, b, cin)BEGIN

cout <= (a and b) or (a and cin) or (b and cin);

END PROCESS Carry;END behavioral;

ELEC2200-001 Fall 2010, Nov 2 15

ARCHITECTURE behavioral OF Full_adder IS

BEGINPROCESS(a, b, cin)BEGIN

sum <= a xor b xor cin;

cout <= (a and b) or (a and cin) or (b and cin);

END PROCESS;END behavioral;

(Adopted from Profs. Nelson and Stroud)

mza0020
Process statemnt is an important part of Behavioral architecture. All behavioral statements should lie withing the process statement. The sensitivity list of the process statement includes all the inputs which affect the internal signals and outputs of the process. The statements within the process execute sequentially whenever any of the inputs in its sensitivity list change.There can be one or multiple processes in an architecture.
Page 16: Introduction to VHDL

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

ELEC2200-001 Fall 2010, Nov 2 16(Adopted from Profs. Nelson and Stroud)

Page 17: Introduction to VHDL

Process Format[label:] process (sensitivity list)

declarations begin

sequential statements 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”

ELEC2200-001 Fall 2010, Nov 2 17(Adopted from Profs. Nelson and Stroud)

mza0020
mza002011/3/2010Process statemnt is an important part of Behavioral architecture. All behavioral statements should lie withing the process statement. The sensitivity list of the process statement includes all the inputs which affect the internal signals and outputs of the process. The statements within the process execute sequentially whenever any of the inputs in its sensitivity list change.There can be one or multiple processes in an architecture.
mza0020
All signal (interanl signals) or variable declarations should be done before the 'BEGIN" statement.
Page 18: Introduction to VHDL

Using a “process” to model sequential behavior

ENTITY dff IS PORT (d,clk: IN STD_LOGIC;

q: OUT STD_LOGIC);END dff;

ARCHITECTURE behavioral OF dff ISBEGIN

PROCESS(clk) -- “process sensitivity list”BEGINIF (clk’event and clk=‘1’) THEN q <= d AFTER 1 ns;END IF;END PROCESS;

END behavioral; 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

ELEC2200-001 Fall 2010, Nov 2 18

D Q

CLK

(Adopted from Profs. Nelson and Stroud)

mza0020
Clock event is any transtion (rising or falling).Clock event and clock = 1 implies that it is a rising transition.
mza0020
1ns is the delay. The ouput changes 1ns after the input is changed.Delay here is optional. If delay is not mentioned, the statement becomes...q<=d;
Page 19: Introduction to VHDL

Alternative to sensitivity listENTITY dff IS PORT (d,clk: IN STD_LOGIC;

q: OUT STD_LOGIC);END dff;ARCHITECTURE behavioral OF dff ISBEGIN

PROCESS -- no “sensitivity list”BEGINWAIT ON clk; -- suspend process until event on clkIF (clk=‘1’) THEN q <= d AFTER 1 ns;END IF;END PROCESS;

END behavioral;

Other “wait” formats: WAIT UNTIL (clk’event and clk=‘1’) WAIT FOR 20 ns;

Process executes endlessly if no sensitivity list or wait statement!

ELEC2200-001 Fall 2010, Nov 2 19

D Q

CLK

(Adopted from Profs. Nelson and Stroud)

Page 20: Introduction to VHDL

Sequential statements in process

if-then-elsif-else statementif condition then       

(... sequence of statements...)      elsif condition then       

(... sequence of statements...)else        

(... sequence of statements...)     end if;

case statementcase expression is       

when choices => sequence of statements        when choices => sequence of statements        ...        when others => sequence of statements    

end case; ELEC2200-001 Fall 2010, Nov 2 20(Adopted from Profs. Nelson and Stroud)

Page 21: Introduction to VHDL

Sequential statements in process

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];

ELEC2200-001 Fall 2010, Nov 2 21(Adopted from Profs. Nelson and Stroud)

Page 22: Introduction to VHDL

Behavioral architecture example using conditional statements

ARCHITECTURE functional OF Full_adder IS BEGIN

PROCESS(A,B,Cin) BEGIN If (Cin = '0' and A = '0'

and B = '0' ) then sum<= '0'; Cout <=

'0'; elsif(Cin = '0' and A =

'0' and B = '1') then sum <= '1' ; Cout <=

'0'; elsif(Cin = '0' and A =

'1' and B = '0' ) then sum <= '1' ; Cout <=

'0'; elsif(Cin = '0' and A =

'1' and B = '1' ) then sum<= '0'; Cout <=

'1';

elsif(Cin = '1' and A = '0' and B = '0' ) then sum <= '1' ; Cout <= '0'; elsif(Cin = '1' and A = '0' and B = '1' ) then sum<= '0'; Cout <= '1'; elsif(Cin = '1' and A = '1' and B = '0' ) then sum<= '0'; Cout <= '1'; elsif(Cin = '1' and A = '1' and B = '1' ) then sum <= '1' ; Cout <= '1'; else sum <= 'X' ; Cout <= 'X'; end if;

END PROCESS; END functional;

ELEC2200-001 Fall 2010, Nov 2 22(Adopted from Profs. Nelson and Stroud)

mza0020
This example illustrates the truth table of a full-adder for the sum output using if-elsif-else conditional statements.
Page 23: Introduction to VHDL

Sequential architecture example

ELEC2200-001 Fall 2010, Nov 2 23

ENTITY counter_4bit IS PORT(Ld, Clr, Clk: IN

STD_LOGIC; D: IN STD_LOGIC_VECTOR

(3 DOWNTO 0); Cout: OUT STD_LOGIC; Qout: OUT

STD_LOGIC_VECTOR (3 DOWNTO 0));

END counter_4bit;

ARCHITECTURE behavioral OF counter_4bit ISSIGNAL Q: STD_LOGIC_VECTOR(3 DOWNTO 0); BEGIN Qout <= Q; Cout <= Q(3) and Q(2) and Q(1) and Q(0); PROCESS(Clk) BEGIN IF Clk'event and Clk = '1' THEN IF Clr = '0' THEN

Q <= "0000"; ELSIF Ld = '0' THEN

Q <= D; ELSE

Q <= Q + 1; END IF; END IF; END PROCESS;END behavioral;

(Adopted from Profs. Nelson and Stroud)

mza0020
A std_logic_vector (multiple bits) are enclosed in double-quotation marks.A single bit is enclosed in single-quotation marks.
mza0020
A bit counter counts form 0 to 15.
Page 24: Introduction to VHDL

ELEC2200-001 Fall 2010, Nov 2 24

References VHDL mini-reference on Prof. Nelson’s website

http://www.eng.auburn.edu/department/ee/mgc/vhdl.html VHDL resources on Prof. Stroud’s website

http://www.eng.auburn.edu/~strouce/elec4200.html VHDL resources on Prof. Agrawal’s website

http://www.eng.auburn.edu/~agrawvd/COURSE/E6200_Fall10/course.html

http://esd.cs.ucr.edu/labs/tutorial/ http://www.seas.upenn.edu/~ese201/vhdl/vhdl_primer.html#_Toc5260613

44

http://www.vhdl.org/ http://www.doulos.com/knowhow/vhdl_designers_guide/ http://www.altera.com/support/examples/vhdl/vhdl.html http://www.vhdl-online.de/tutorial/ http://www.people.vcu.edu/~rhklenke/tutorials/vhdl/modules/m12_23/sld0

06.htm

http://www.doc.ic.ac.uk/~ih/teaching/lectures/comparch/logic/adder/ (Adopted from Profs. Nelson and

Stroud)

Page 25: Introduction to VHDL

25

Using Modelsim Modelsim PE (Student Edition) can be

downloaded fromhttp://model.com/content/modelsim-pe-student-edition-hdl-simulation?quicktabs_4=1#quicktabs-4 Modelsim is installed on the Windows7

platform in Lab 310, Broun Hall.

ELEC2200-001 Fall 2010, Nov 2

(Adopted from Profs. Nelson and Stroud)

Page 26: Introduction to VHDL

26

Using Modelsim

ELEC2200-001 Fall 2010, Nov 2

(Adopted from Profs. Nelson and Stroud)

Page 27: Introduction to VHDL

27

Using Modelsim

ELEC2200-001 Fall 2010, Nov 2 (Adopted from Profs. Nelson and Stroud)

Page 28: Introduction to VHDL

28

Using Modelsim

ELEC2200-001 Fall 2010, Nov 2 (Adopted from Profs. Nelson and Stroud)

Page 29: Introduction to VHDL

29

Using Modelsim

ELEC2200-001 Fall 2010, Nov 2

(Adopted from Profs. Nelson and Stroud)

mza0020
The file-extension is '.vhd'
Page 30: Introduction to VHDL

30

Using Modelsim

ELEC2200-001 Fall 2010, Nov 2 (Adopted from Profs. Nelson and Stroud)

mza0020
The file-extension is '.vhd'
Page 31: Introduction to VHDL

31

Using Modelsim

ELEC2200-001 Fall 2010, Nov 2 (Adopted from Profs. Nelson and Stroud)

mza0020
Start writing your code here.
Page 32: Introduction to VHDL

32

Using Modelsim

ELEC2200-001 Fall 2010, Nov 2 (Adopted from Profs. Nelson and Stroud)

Page 33: Introduction to VHDL

33

Using Modelsim

ELEC2200-001 Fall 2010, Nov 2 (Adopted from Profs. Nelson and Stroud)

mza0020
You get the success message here, if your code is compiled successfully.
mza0020
You get a green 'tick-mark' here, if your code is compiled successfully.
Page 34: Introduction to VHDL

34

Using Modelsim

ELEC2200-001 Fall 2010, Nov 2 (Adopted from Profs. Nelson and Stroud)

mza0020
mza002011/3/2010You get a red 'cross-mark' here, if your code is compiled successfully.
mza0020
You get the error message here, if your code is compiled successfully.
mza0020
This pop-up window is seen when you double-click on the error message below.It lists all the errors in your code.You can double-click on any of the errors to go to the corresponding line in your code.
mza0020
The line that contains an error is highlighted when you double-click on the corresponding error message.
Page 35: Introduction to VHDL

35

Using Modelsim

ELEC2200-001 Fall 2010, Nov 2 (Adopted from Profs. Nelson and Stroud)

mza0020
Select your top-level heirarchial entity name from the work folder and click 'OK' to simulate.
Page 36: Introduction to VHDL

36

Using Modelsim

ELEC2200-001 Fall 2010, Nov 2(Adopted from Profs. Nelson and

Stroud)

mza0020
Select the signals that you wish to see in the wave format.
Page 37: Introduction to VHDL

37

Using Modelsim

ELEC2200-001 Fall 2010, Nov 2

(Adopted from Profs. Nelson and Stroud)

mza0020
Force all inputs to some value. You can change it again after running the simulation desired number of times.
mza0020
Assign the input signal a binary value.
Page 38: Introduction to VHDL

38

Using Modelsim

ELEC2200-001 Fall 2010, Nov 2 (Adopted from Profs. Nelson and Stroud)

Page 39: Introduction to VHDL

39

Using Modelsim

ELEC2200-001 Fall 2010, Nov 2

(Adopted from Profs. Nelson and Stroud)

mza0020
mza002011/3/2010Select the signals that you wish to see in the list format.