Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design...

66
Chapter 5 Introduction to VHDL

Transcript of Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design...

Page 1: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

Chapter 5

Introduction to VHDL

Page 2: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

2

Hardware Description Language

• A computer language used to design circuits with text-based descriptions of the circuits.

• VHDL (VHSIC Very High Speed Integrated Circuit Hardware Description Language) is the industry-standard language used for programming PLDs.

Page 3: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

3

VHDL History

• Developed by defense contractors as a standard for programming circuits.

• Currently defined by IEEE Standard 1076-1993.

• Related standard for certain data types is IEEE Standard 1164-1993.

Page 4: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

4

VHDL – 1

• Used to describe the structure or behavior of hardware.

• Describes how the hardware should operate (modeling).

• Describes how how the hardware should be built (synthesis).

Page 5: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

5

VHDL – 2

• In VHDL the designer enters text according to the syntax of the language.

• Syntax: The rules of construction, or “grammar”, of a programming language.

Page 6: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

6

Entity and Architecture

• Two basic constructs required for all VHDL code.

• The entity declaration describes the inputs and outputs.

• The architecture body defines the relationships between the inputs and outputs.

Page 7: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

7

VHDL Entity

• Defines the external aspects of the function.

• Each input or output is a port.

• The type of port is defined by mode.

Page 8: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

8

AC BC AB Y

VHDL Entity

Page 9: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

9

VHDL Entity Declaration

ENTITY majority_vote IS PORT( a, b, c: IN BIT; y : OUT BIT);END majority_vote;

Page 10: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

10

VHDL Architecture Body

ARCHITECTURE maj_vote OF majority vote ISBEGIN y <= (a and b) or (b and c) or (a and c);END maj_vote;

Page 11: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

11

Port Types

• IN refers to a port used only for input.

• OUT refers to a port used only for output.

• BIT refers to the port type.

• A port designated as type BIT can have a value of either ‘0’ or ‘1’ .

Page 12: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

12

Boolean Operators in VHDL

• AND, OR, NOT, NAND, NOR, XOR, and XNOR are represented as written.

• VHDL has no order of precedence for Boolean operators.

• Expressions must be written explicitly with parentheses.

Page 13: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

13

Boolean Operators Example

• Y <= (a and(not b)) or ((not a) and b and (not c));

• Y <=not((a and b) or ((not a) and (not c)) or d);

CBA B AY

DCAAB Y

Page 14: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

14

Signal Concurrency

• Concurrent means simultaneous.• The statements in an architecture body are

evaluated at the same time, they are not dependent on the order in which they are written.

• A change in one input common to several circuits affects all the circuits at the same time.

Page 15: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

15

Signal Concurrency

Page 16: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

16

Signal Concurrency Example

• The order in which the statements are written is not important.

• Both are executed at the same time.

• This is how the hardware behaves.

b; and a carry_out

b; xora sum

Page 17: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

17

Making a VHDL File in Quartus II – 1

• Created using the Quartus II Text Editor

• Start a New File.

• Select VHDL File from the Device Design Files tab.

• The text editor automatically opens.

Page 18: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

18

Making a VHDL File in Quartus II – 2

• Name the file and save as type VHDL.

• Check Create new project based on this file.

• Click Save.

• Click Yes when asked if you want to create a new project from this file.

Page 19: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

19

Making a VHDL File in Quartus II – 2

Page 20: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

20

Making a VHDL File in Quartus II – 2

Page 21: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

21

Making a VHDL File in Quartus II – 2

Page 22: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

22

Making a VHDL File in Quartus II – 3

• VHDL code is entered in the Text Editor window.

• For reference, the text editor will number each line of code.

• Save and compile your completed VHDL code.

Page 23: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

23

Making a VHDL File in Quartus II – 3

Page 24: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

24

Simulation

Follow the process used for simulating a graphic design.

Page 25: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

25

Assigning Pin Numbers

Assigning pin numbers follows the same process for assigning pin numbers for a graphic design.

Page 26: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

26

Valid Names in VHDL – 1

Referenced in Altera’s style guideline from the help menu in Quartus II.

Page 27: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

27

Valid Names in VHDL – 2

• A valid name in Quartus is called a name identifier.

• All ports, signals, variables, entity names, architecture bodies, or similar objects must use names that are recognized by Quartus.

Page 28: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

28

Valid Names in VHDL – 3

• VHDL is not case sensitive.

• Name identifiers consists of a letter followed by any number of letters or numbers.

• A space in a name is considered invalid.

Page 29: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

29

Valid Names in VHDL – 4

• VHDL keywords should be capitalized.

• User names should be written in lowercase.

• An underscore can be written within a name but cannot start or end the name.

• Two consecutive underscores are not permitted.

Page 30: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

30

Reserved Keywords

• Reserved keywords are words that have a specific function in VHDL.

• They cannot be used as object names.

• A complete listing of the VHDL reserved keyword can be found in the Quartus II Help File.

Page 31: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

31

Comments

• A comment is explanatory text that is ignored by the compiler.

• Comments are preceded by two consecutive hyphens.

• Example: -- this is a comment.

Page 32: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

32

Port Modes – 1

• Defines the ports direction of data flow.• IN - data flows from an INPUT pin to the

CPLD's logic.• OUT – data flows from the CPLD's logic to an

OUTPUT.• INOUT - refers to a bidirectional port that

allows data to flow in both directions.

Page 33: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

33

Port Modes – 2

• BUFFER refers to a special case of OUT that has a feedback connection back into the CPLD logic that allows the port value to be changed by the CPLD.

Page 34: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

34

Port Modes – 3

Page 35: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

35

Port Modes – 4

Page 36: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

36

Type

• A type in VHDL is a property applied to a port, signal or variable that defines what values the object can have.

• Common types: BIT, STD_LOGIC and INTEGER.

Page 37: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

37

BIT

• BIT can have only two values ‘0’ and ‘1’.

• Values are placed in single quotes.

• VHDL treats them like ASCII characters.

Page 38: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

38

BIT_VECTOR

• BIT_VECTOR: a one-dimensional array of elements, each of type BIT.

• The range of the array is indicated by listing its upper and lower bounds.

• d: IN BIT_VECTOR (3 downto 0).

• d: IN BIT_VECTOR (0 to 3).

Page 39: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

39

IN BIT_VECTOR (3 downto 0)

d(3) <= ‘0’; d <= “0101”;

d(2) <= ‘1’;

d(1) <= ‘0’;

d(0) <= ‘1’

Page 40: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

40

IN BIT_VECTOR (0 to 3)

d(3) <= ‘0’; d <= “1010”;

d(2) <= ‘1’;

d(1) <= ‘0’;

d(0) <= ‘1’

Page 41: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

41

IN BIT_VECTOR (0 to 3)

Page 42: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

42

Making a Symbol from VHDL

• Open the VHDL file and its associated project.

• Select Create/Update from the File menu.

• Select Create Symbol Files for the Current File.

Page 43: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

43

VHDL Input & Output Definition

• A graphic symbol is derived from VHDL code: – VHDL code defining the inputs and outputs

as separate ports shows the inputs and outputs as thin lines.

– VHDL code defining inputs and outputs as vectors shows the inputs and outputs as thick lines.

Page 44: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

44

VHDL Input & Output Definition

Page 45: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

45

VHDL Input & Output Definition

Page 46: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

46

VHDL Input & Output Definition

Page 47: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

47

Selected Signal Assignment Statements

• Selected Signal Assignment Statements list alternatives that are available for each value of an expression, then select a course of action based on the value of the expression.

Page 48: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

48

D2 D1 D0 Y

0 0 0 0

0 0 1 0

0 1 0 1

0 1 1 0

1 0 0 0

1 0 1 0

1 1 0 0

1 1 1 1

012012

ExpressionBoolean

DD D DDD Y

Page 49: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

49

Signal Assignment Statements – 1

• For

• WITH d SELECT

y <= ‘1’ WHEN “010”,

‘1‘ WHEN “111”,

‘0’ WHEN others;

012012 DD D DDD Y

Page 50: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

50

STD_LOGIC or STD_LOGIC VECTOR

• IEEE Std. 1164 Multi-Valued Logic.

• Gives a broader range of output values than just ‘0’ and ‘1’.

• Can be any of nine values.

Page 51: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

51

' U ' Uninitialized ' X ' Forcing Unknown ' 0 ' Forcing 0 ' 1 ' Forcing 1 ' Z ' High Impedance ' W ' Weak Unknown ' L ' Weak 0 ' H ' Weak 1 ' - ' Don't Care

IEEE Std. 1164 Multi-Valued Logic – 1

Page 52: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

52

IEEE Std. 1164 Multi-Valued Logic – 2

• The majority of applications can be handled by ‘X’ , ‘0’, ‘1’, and ‘Z’ values.

• To use STD_LOGIC in a VHDL file:– Include reference to the ieee VHDL library and the

std_logic_1164 package before the entity statement.

• The std_logic_1164 package contains all type definitions of the STD_LOGIC types.

Page 53: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

53

Integers – 1

• VHDL INTEGER types are represented by the range of 32-bit positive and negative numbers.

• –2,147,483,648 to +2,147,483,647.

Page 54: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

54

Integers – 2

• The following two expressions produce the same result in hardware:– d: IN_BIT_VECTOR (3 downto 0);– d: IN_BIT_INTEGER RANGE (0 to 7);

• Refer to Example 5.6

Page 55: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

55

NATURAL & POSITIVE Subtypes

• NATURAL:– The set of all integers greater than or equal

to ‘0’.

• POSITIVE:– The set of all integers greater than or equal

to 1.

• Constants in all these types are written in VHDL without quotes (e.g., y <= 3;).

Page 56: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

56

Signals in VHDL

• A signal is defined as an internal connection within a VHDL architecture that connects parts of the design together.

• Acts like an internal wire inside the design.

Page 57: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

57

Signals in VHDL

Page 58: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

58

A B C W X Y Z

0 0 0 1 0 0 0

0 0 1 0 1 0 0

0 1 0 0 1 1 0

0 1 1 1 0 0 1

1 0 0 0 1 1 0

1 0 1 0 0 0 1

1 1 0 1 0 0 1

1 1 1 0 0 1 0

Signals in

VHDL

Page 59: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

59

Signals in VHDL

Page 60: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

60

Concatenate

• Bundling or linking the ports together.

• Uses the & operator.

• inputs <= a & b & c;

Page 61: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

61

Concatenate

Page 62: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

62

Defining the OUTPUT Ports

• Using a concurrent signal assignment statement for each output: w <= outputs (3);

x <= outputs (2);

y <= outputs (1);

z <= outputs (0);

Page 63: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

63

Defining the OUTPUT Ports

Page 64: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

64

Defining the OUTPUT Ports

Page 65: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

65

Single- & Multiple-Bit Signals

• 3-bit port defined as:– d: IN_STD_LOGIC_VECTOR (2 downto 0);

• Single-bit port defined as:– enable: IN-STD_LOGIC;

Page 66: Chapter 5 Introduction to VHDL. 2 Hardware Description Language A computer language used to design circuits with text-based descriptions of the circuits.

66

Combining Single- & Multiple-Bit Signals

• Define the signal: – SIGNAL : inputs STD_LOGIC_VECTOR (3

downto 0);

• Concatenate the ports into a signal:– inputs <= enable & d;