Top Banner
Advanced FPGA Based System Design Lecture-6 & 7 VHDL Data Types By: Dr Imtiaz Hussain [email protected] 1
41

Advanced FPGA Based System Design

Feb 23, 2016

Download

Documents

Selin Kesebir

Advanced FPGA Based System Design. Lecture-6 & 7 VHDL Data Types. By: Dr Imtiaz Hussain [email protected]. Contents. Data Types Bit & Bit Vectors Std_Logic and std_logic_vectors Std_Ulogic and std_Ulogic_vectors Arrays 1D , 2D , 1DX1D Records Signed & Unsigned - 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: Advanced FPGA Based System Design

1

Advanced FPGA Based System Design

Lecture-6 & 7VHDL

Data Types

By: Dr Imtiaz [email protected]

Page 2: Advanced FPGA Based System Design

2

Contents• Data Types– Bit & Bit Vectors– Std_Logic and std_logic_vectors– Std_Ulogic and std_Ulogic_vectors– Arrays• 1D, 2D, 1DX1D

– Records– Signed & Unsigned

• Data Conversion

Page 3: Advanced FPGA Based System Design

3

Data Types

• VHDL contains a series of pre-defined data types, specified through the IEEE 1076 and IEEE 1164 standards.

• Data type definitions can be found in the following packages / libraries:– Package standard of library std: Defines BIT,

BOOLEAN, INTEGER, and REAL data types.– Package std_logic_1164 of library ieee: Defines

STD_LOGIC and STD_ULOGIC data types.

Page 4: Advanced FPGA Based System Design

4

Data Types

– Package std_logic_arith of library ieee: Defines SIGNED and UNSIGNED data types, plus several data conversion functions, like conv_integer(p), conv_unsigned(p, b), conv_signed(p, b), and conv_std_logic_vector(p, b).

– Packages std_logic_signed and std_logic_unsigned of library ieee: Contain functions that allow operations with STD_LOGIC_VECTOR data to be performed as if the data were of type SIGNED or UNSIGNED, respectively.

Page 5: Advanced FPGA Based System Design

5

Data Types• BIT & BIT_VECTORS (2-Level Logic ‘0’ and ‘1’)

Page 6: Advanced FPGA Based System Design

6

Data Types• To assign a value to a signal ‘<=’ must be used

Page 7: Advanced FPGA Based System Design

7

Examples of BIT and BIT_VECTORS• Initialize a variable ‘var1’ with binary value ‘1’.• Initialize an 8-bit variable ‘var2’ with MSB=‘1’

and LSB= ‘0’ and all the values in between equal to 1.

• var3=10000100

• var4=1000100MSB

MSB

Page 8: Advanced FPGA Based System Design

8

Data Types• STD_LOGIC and STD_LOGIC_VECTOR (8 value

system)

Page 9: Advanced FPGA Based System Design

9

Data Types• STD_LOGIC and STD_LOGIC_VECTOR

Page 10: Advanced FPGA Based System Design

10

Data Types• STD_ULOGIC and STD_ULOGIC_VECTO R (9-

Level Logic system).

• STD_LOGIC is therefore defined as subtype of STD_ULOGIC.

Page 11: Advanced FPGA Based System Design

11

Examples of Data Types

Page 12: Advanced FPGA Based System Design

12

Data Types(Legal and Illegal operation B/W data of different types)

Page 13: Advanced FPGA Based System Design

13

Arrays• Arrays are collection of objects of same type.

• They can be one-dimensional (1D), two-dimensional (2D), or one-dimensional-by-one-dimensional (1Dx1D).

A single value (scalar)

A vector (1D array)

An array of vectors (1Dx1D array)

An array of scalars (2D array)

Page 14: Advanced FPGA Based System Design

14

Arrays

• To Specify a new array type

• To make use of new array type

Page 15: Advanced FPGA Based System Design

15

Arrays (Example of 1Dx1D array)

• Say that we want to build an array containing four vectors, each of size eight bits.

• Let us call each vector by row, and the complete array by matrix

• Additionally, say that we want the leftmost bit of each vector to be its MSB (most significant bit), and that we want the top row to be row 0. Then the array implementation would be the following.

Matrix (0 to 3)

row (7 down 0)

Page 16: Advanced FPGA Based System Design

16

Arrays (Example of 1Dx1D array)

• Another way

x=Matrix (0 to 3)

row (7 down 0)

Page 17: Advanced FPGA Based System Design

17

Arrays (Example of 2D array)

• Array below is a 2D array

Page 18: Advanced FPGA Based System Design

18

Arrays• Array Initialization

TYPE myarray IS ARRAY (3 DOWN 0) OF STD_LOGIC:=“0001”;

Page 19: Advanced FPGA Based System Design

19

Example

• Write the syntax of following arrays

(a)

(b)

(c)

(d)

Page 20: Advanced FPGA Based System Design

20

Examples• Write syntax for following– (A)

– (B)

– (C)

– (d)

1 0 1 1

1 0 1 1

1 1 0 00 0 1 1

1 0

0 1

1 0 1

0 0 1

Page 21: Advanced FPGA Based System Design

21

Examples (legal and illegal assignments)

Page 22: Advanced FPGA Based System Design

22

Examples (legal and illegal assignments)

row

array1

Page 23: Advanced FPGA Based System Design

23

Examples (legal and illegal assignments)

array2

array3

Page 24: Advanced FPGA Based System Design

24

Examples (legal and illegal assignments)

Page 25: Advanced FPGA Based System Design

25

Page 26: Advanced FPGA Based System Design

26

Page 27: Advanced FPGA Based System Design

27

Records

• Records are similar to arrays, with the only difference that they contain objects of different types.

Page 28: Advanced FPGA Based System Design

28

Signed & Unsigned Data Types

• These types are defined in the std_logic_arith package of the ieee library.

• SIGNED and UNSIGNED data types are intended mainly for arithmetic operations.

• Their syntax is illustrated in the examples below.

Page 29: Advanced FPGA Based System Design

29

Signed & Unsigned Data Types• An UNSIGNED value is a number never lower than

zero. • For example, ‘‘0101’’ represents the decimal 5, while

‘‘1101’’ signifies 13.• If type SIGNED is used instead, the value can be

positive or negative (in two’s complement format).• Therefore, ‘‘0101’’ would represent the decimal 5,

while ‘‘1101’’ would mean -3.• Logical operations are not allowed but there are no

restrictions to relational (comparison) operations.

Page 30: Advanced FPGA Based System Design

30

Legal/illegal operations with Signed & Unsigned Data Types

Page 31: Advanced FPGA Based System Design

31

Legal/illegal operations with std_logic_vector

Page 32: Advanced FPGA Based System Design

32

Data Conversion• VHDL does not allow direct operations (arithmetic,

logical, etc.) between data of different types.

• Therefore, it is often necessary to convert data from one type to another.

• This can be done in basically two ways: – write a piece of VHDL code – invoke a FUNCTION from a pre-defined PACKAGE which

is capable of doing it for us.

Page 33: Advanced FPGA Based System Design

33

Data Conversion• If the data are closely related (that is, both operands

have the same base type, despite being declared as belonging to two different type classes), then the std_logic_1164 of the ieee library provides straightforward conversion functions.

Page 34: Advanced FPGA Based System Design

34

Data Conversion• Several data conversion functions can be found in the

std_logic_arith package of the ieee library. They are:– conv_integer(p) : Converts a parameter p of type INTEGER,

UNSIGNED, SIGNED, or STD_ULOGIC to an INTEGER value.– conv_unsigned(p, b): Converts a parameter p of type INTEGER,

UNSIGNED, SIGNED, or STD_ULOGIC to an UNSIGNED value with size b bits.

– conv_signed(p, b): Converts a parameter p of type INTEGER, UNSIGNED, SIGNED, or STD_ULOGIC to a SIGNED value with size b bits.

– conv_std_logic_vector(p, b): Converts a parameter p of type INTEGER, UNSIGNED, SIGNED, or STD_LOGIC to a STD_LOGIC_VECTOR value with size b bits.

Page 35: Advanced FPGA Based System Design

35

Example Data Conversion

Page 36: Advanced FPGA Based System Design

36

The Fundamental Synthesizable VHDL data types

Page 37: Advanced FPGA Based System Design

37

Examples• Single bit vs. Bit vector

Page 38: Advanced FPGA Based System Design

38

Examples• Figure shows the top-level diagram of a 4-bit adder. The

circuit has two inputs (a, b) and one output (sum).

Sum(4:0)

B(3:0)

A(3:0)

Page 39: Advanced FPGA Based System Design

39

Examples• Figure shows the top-level diagram of a 4-bit adder. The

circuit has two inputs (a, b) and one output (sum).

Sum(4:0)

B(3:0)

A(3:0)

Page 40: Advanced FPGA Based System Design

40

Problems• The problems below are based on the following TYPE

definitions and SIGNAL declarations:

Page 41: Advanced FPGA Based System Design

41

Problems

• Problem#1: – Determine the dimensionality (scalar, 1D, 2D, or

1Dx1D) of the signals given. Also, write down a numeric example for each signal.

• Problem#2: – Determine which among the assignments in table

(available in class) are legal and which are illegal. Briefly justify your answers. Also, determine the dimensionality of each assignment (on both sides).