33
Data Types Feb 2012 © Ruchi Rastogi Bani 1

Data Types · Std_logic type is the data type defined in the std_logic_1164 package of the IEEE library. It defines a number of the states for a digital signal which helps in simulation

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Data Types · Std_logic type is the data type defined in the std_logic_1164 package of the IEEE library. It defines a number of the states for a digital signal which helps in simulation

Data Types

Feb 2012 © Ruchi Rastogi Bani 1

Page 2: Data Types · Std_logic type is the data type defined in the std_logic_1164 package of the IEEE library. It defines a number of the states for a digital signal which helps in simulation

VHDL supports a variety of data types and operators.

Users can define their own data types and operators in user defined packages.

There are three basic classes to define data objects in VHDL.

◦ signal - represents interconnections that connect components and ports.

◦ variable - used for local storage within a process. ◦ constant - a fixed value The data object could be a scalar or an array (one-

dimensional as well as multi-dimensional)

Page 3: Data Types · Std_logic type is the data type defined in the std_logic_1164 package of the IEEE library. It defines a number of the states for a digital signal which helps in simulation

Feb 2012 © Ruchi Rastogi Bani 3

Lexical Elements 1. Identifier 2. Delimiters Object Classes 1. Signals 2. Variables 3. Constant 4. Alias

Types and Subtypes 1. Bit Type 2. Boolean Type 3. Character Type 4. Integer Type 5. Real Type 6. Physical Type 7. Std_logic Type Operators and Operator

Precedence 1. Logical 2. Relational 3. Shift

Page 4: Data Types · Std_logic type is the data type defined in the std_logic_1164 package of the IEEE library. It defines a number of the states for a digital signal which helps in simulation

Identifiers are names that identify various VHDL

objects, procedures, functions, processes, etc.

Eight rules to follow ,

1. Can only contain alphabet, number and underscores.

2. Can be of any length as long as entire identifier is

appears within a line.

3. Identifiers will not be distinguishable if differing only

by upper case and lower case.

4. Can not have same name as the keyword.

Feb 2012 © Ruchi Rastogi Bani 4

Page 5: Data Types · Std_logic type is the data type defined in the std_logic_1164 package of the IEEE library. It defines a number of the states for a digital signal which helps in simulation

5. Must begin with letter.

6. Underscore should not be at start, end and side by side.

7. Underscore should be used to increase the readability.

8. No space is allowed within a basic identifier.

Ex:

Intg-5 “-” is illegal

Zero_to_3 Legal

Valid User-defined identifiers:

COUNT, cout, C_out, A_B_C

Invalid User defined Identifiers:

2AB, H$B, LOOP, _ABC, DECODE_, A__B

Feb 2012 © Ruchi Rastogi Bani 5

Page 6: Data Types · Std_logic type is the data type defined in the std_logic_1164 package of the IEEE library. It defines a number of the states for a digital signal which helps in simulation

Delimiters are symbols that have special meaning

within VHDL.

Ex: & ‘ * + - < > = ;

Compound delimiter refers to a sequence of two

delimiters.

Ex: <= := == /=

Feb 2012 © Ruchi Rastogi Bani 6

Page 7: Data Types · Std_logic type is the data type defined in the std_logic_1164 package of the IEEE library. It defines a number of the states for a digital signal which helps in simulation

Feb 2012 © Ruchi Rastogi Bani 7

Lexical Elements 1. Identifier 2. Delimiters Object Classes 1. Signals 2. Variables 3. Constant

Types and Subtypes 1. Bit Type 2. Boolean Type 3. Character Type 4. Integer Type 5. Real Type 6. Physical Type 7. Std_logic Type Operators and Operator

Precedence 1. Logical 2. Relational 3. Shift

Page 8: Data Types · Std_logic type is the data type defined in the std_logic_1164 package of the IEEE library. It defines a number of the states for a digital signal which helps in simulation

Used to represent value of a digital system

Values allowed are ‘0’ and ‘1’

Bit vector is expressed as a string of bit literals

enclosed in double quotes

Ex: ‘1’ , ‘0’, “1011”, X”7CEF” ( hex ), O”5673” ( octal )

Ex: signal valid : bit

Feb 2012 © Ruchi Rastogi Bani 8

Page 9: Data Types · Std_logic type is the data type defined in the std_logic_1164 package of the IEEE library. It defines a number of the states for a digital signal which helps in simulation

Represents true or false value

Values allowed are ◦ true(TRUE,True) ◦ false(FALSE,False) Ex: signal busactive : boolean; ... busactive <= true; ... if (busactive and valid = ‘1’) then data_out <= din; valid_out <= ‘1’; end if;

Feb 2012 © Ruchi Rastogi Bani 9

Page 10: Data Types · Std_logic type is the data type defined in the std_logic_1164 package of the IEEE library. It defines a number of the states for a digital signal which helps in simulation

The package STANDARD predefines a set of

character literals.

Character literals are enclosed in single quotes

Ex: ‘a’ , ‘A’, ‘1’ , ‘!’

An array of character literals is enclosed in double

quotes

Ex: “Warning : timing violation”

Feb 2012 © Ruchi Rastogi Bani 10

Page 11: Data Types · Std_logic type is the data type defined in the std_logic_1164 package of the IEEE library. It defines a number of the states for a digital signal which helps in simulation

Defines a value with integers

Values are called integer literals

They can be either positive or negative

Exponents have to be integers

Ex: 3, -1, 47E23 , -4E-2, 345

Feb 2012 © Ruchi Rastogi Bani 11

Page 12: Data Types · Std_logic type is the data type defined in the std_logic_1164 package of the IEEE library. It defines a number of the states for a digital signal which helps in simulation

architecture int_datatype of datatype is

begin

process

variable a : integer;

begin

a := 1; -- ok

a := -1; -- ok

a := 1.0; -- error

end process

end int_datatype;

Page 13: Data Types · Std_logic type is the data type defined in the std_logic_1164 package of the IEEE library. It defines a number of the states for a digital signal which helps in simulation

Defines a value with real numbers

They can be either positive or negative

Values are called real literal

Exponents have to be integers

Ex: 3.23, -1.78946, 4.78E23 , -4.23E-2, 0.345

Feb 2012 © Ruchi Rastogi Bani 13

Page 14: Data Types · Std_logic type is the data type defined in the std_logic_1164 package of the IEEE library. It defines a number of the states for a digital signal which helps in simulation

architecture real_datatype of datatype is

begin

signal a : real;

begin

a <= 1.0; -- ok

a <= 1; -- error

a <= -1.0E10; -- ok

a <= 1.5E-20; -- ok

a <= -1.0E10; -- ok

a <= 5.3 ns; -- error

end real_datatype;

Page 15: Data Types · Std_logic type is the data type defined in the std_logic_1164 package of the IEEE library. It defines a number of the states for a digital signal which helps in simulation

Used to represent physical quantities like distance, current, time etc

Values are physical literals

The only predefined physical type time is defined in package STANDARD

Ex: signal tpd : time := 100 ns ;

The predefined function “now” returns the current simulation time

The range of a physical type is always in terms of its base unit

User can define their own physical types

Feb 2012 © Ruchi Rastogi Bani 15

Page 16: Data Types · Std_logic type is the data type defined in the std_logic_1164 package of the IEEE library. It defines a number of the states for a digital signal which helps in simulation

type current is range -2147484638 to 2147484637

units

nA; -- Base Unit nano ampere

uA = 1000 nA; -- micro ampere

mA = 1000 uA; -- milli ampere

A = 1000 mA; -- ampere

end units;

Page 17: Data Types · Std_logic type is the data type defined in the std_logic_1164 package of the IEEE library. It defines a number of the states for a digital signal which helps in simulation

Std_logic type is the data type defined in the std_logic_1164 package of the IEEE library.

It defines a number of the states for a digital signal which helps in simulation and debugging.

It is enumerated type and is defined as,

type std_logic is (‘U’,‘X’,‘0’,‘1’,‘Z’,‘W’,‘L’,‘H’,‘-’);

where

‘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

Feb 2012 © Ruchi Rastogi Bani 17

Page 18: Data Types · Std_logic type is the data type defined in the std_logic_1164 package of the IEEE library. It defines a number of the states for a digital signal which helps in simulation

Subtype is a type with a range constraint

Subtypes are compatible with their base type

Ex:

o subtype Count16 is integer range 0 to 16;

o subtype digit is integer range 0 to 9;

o subtype nanosec is time range 0 ns to 1 us;

Feb 2012 © Ruchi Rastogi Bani 18

Page 19: Data Types · Std_logic type is the data type defined in the std_logic_1164 package of the IEEE library. It defines a number of the states for a digital signal which helps in simulation

An enumeration type defines a set of user defined

values consisting of identifiers and character

literals

The enumerated literals are listed in the

ascending order

Actual numeric value can be assigned to the

literals during compile time

Enumerated types allows us to use symbolic

values instead of numeric values

The boolean, bit, character etc. are some of the

predefined enumerated

Feb 2012 © Ruchi Rastogi Bani 19

Page 20: Data Types · Std_logic type is the data type defined in the std_logic_1164 package of the IEEE library. It defines a number of the states for a digital signal which helps in simulation

Syntax:

Type enumerated_name is (enumerated literal1, literal2….);

Ex:

type color is (Red, Blue, Green);

type boolean is (false, true);

type Instruction is (add, sub, div, mul, load, store, or, and, not);

type stateMachine is (Idle, load, start, stop, store);

Feb 2012 © Ruchi Rastogi Bani 20

Page 21: Data Types · Std_logic type is the data type defined in the std_logic_1164 package of the IEEE library. It defines a number of the states for a digital signal which helps in simulation

There are two composite type 1. Array : contains many elements of same type. 2. Records : contains elements of different type.

Arrays can be uni or multi dimensional. Array Declaration Syntax

type array_name is array (index range) of element_type; examples: type byte is array (7 downto 0) of std_logic; -- unconstrained array type word is array (integer range <>) of std_logic;

Feb 2012 © Ruchi Rastogi Bani 21

Page 22: Data Types · Std_logic type is the data type defined in the std_logic_1164 package of the IEEE library. It defines a number of the states for a digital signal which helps in simulation

Declaration example

signal A : std_logic_vector(3 downto 0) := “1011”;

signal B : std_logic_vector(0 to 3) := “1011”;

signal C : std_logic_vector(6 downto 0);

A(3) A(2) A(1) A(0)

1 0 1 1

B(0) B(1) B(2) B(3)

Feb 2012 © Ruchi Rastogi Bani 22

Page 23: Data Types · Std_logic type is the data type defined in the std_logic_1164 package of the IEEE library. It defines a number of the states for a digital signal which helps in simulation

A <= (‘1’, ‘0’, others => ‘1’); --aggregation A <= “1011”; A <= “10” & ”11”; --concatenation A <= ( ‘1’, ‘0’, ‘1’, ‘1’); A <= “101” & ‘1’; A <= ‘1’ & ’0’ & ’1’ & ’1’; C <= A & B; A <= C( 5 downto 2 ); --slicing A(2 downto 1) <= C(6 downto 5); A <= (others => ‘0’); A <= (1 => ‘0’, others => ‘1’ ); A <= (2 | 0 => ‘1’ , others => ‘0’); A <= (0 to 3 => ‘0’);

Feb 2012 © Ruchi Rastogi Bani 23

Page 24: Data Types · Std_logic type is the data type defined in the std_logic_1164 package of the IEEE library. It defines a number of the states for a digital signal which helps in simulation

type array_name is array (index_range, index_range) of element_type;

eg:

type memory is array(3 downto 0, 7 downto 0) of bit;

-- 4 X 8 memory

For synthesis tools that do not accept multidimensional arrays , one can declare

two uni-dimensional arrays .

eg:

type byte is array(7 downto 0) of std_logic;

type mem is array(3 downto 0) of byte;

Initialization and reference

constant ROM: mem := (“10101010”, ”10101010”,

”10101010”, ”10101010”);

rom_bit <= ROM(3, 4); one_more_bit <= ROM(3)(0);

Feb 2012 © Ruchi Rastogi Bani 24

Page 25: Data Types · Std_logic type is the data type defined in the std_logic_1164 package of the IEEE library. It defines a number of the states for a digital signal which helps in simulation

Declaration example:

type my_type is record is_valid : boolean; value : std_logic_vector(7 downto 0); when_updated : time; end record; signal my_element : my_type; assignment example:

my_element <= (is_valid => true; value => “00110011”; when_updated => now ); one more way of assignment:

my_element.value <= “10111011”;

Feb 2012 © Ruchi Rastogi Bani 25

Page 26: Data Types · Std_logic type is the data type defined in the std_logic_1164 package of the IEEE library. It defines a number of the states for a digital signal which helps in simulation

Syntax

signal signal_name : signal_type [range_constraint] [:= int. value]

It connects design entities together and communicate

changes in value within a design.

Signals can be declared in,

1. entity - can be seen by all the architecture

2. arch -local to the architecture

3. package -globally available to the user of the package

4. as parameter in subprograms like functions & procedure.

Feb 2012 © Ruchi Rastogi Bani 26

Page 27: Data Types · Std_logic type is the data type defined in the std_logic_1164 package of the IEEE library. It defines a number of the states for a digital signal which helps in simulation

A signal has three properties,

1. Type and Type attributes

2. Value

3. Time

Assignment is done by using “<=“ symbol.

Ex: c <= ‘1’;

Signal assignment is concurrent outside the process and sequential

inside process.

Signal updates can have a delay specified in their assignment

statements.

Ex: clk <= not clk after 10 ns;

Feb 2012 © Ruchi Rastogi Bani 27

Page 28: Data Types · Std_logic type is the data type defined in the std_logic_1164 package of the IEEE library. It defines a number of the states for a digital signal which helps in simulation

Syntax

variable variable_name : variable_type [ range ] [:= initial value ]; e.g. : variable index : integer range 0 to 15;

variable count : std_logic_vector( 3 downto 0 ) := “0000”;

Variables are assigned values using the ‘:=‘ symbol.

Variables are the identifiers within a process or a subprogram. Their

visibility is limited only to its process or subprogram.

Feb 2012 © Ruchi Rastogi Bani 28

Page 29: Data Types · Std_logic type is the data type defined in the std_logic_1164 package of the IEEE library. It defines a number of the states for a digital signal which helps in simulation

Variable assignment occurs immediately.

Variables have only type and value attached to it.

They don’t have a past history unlike the signal.

Requires less memory and result in fast memory.

Feb 2012 © Ruchi Rastogi Bani 29

Page 30: Data Types · Std_logic type is the data type defined in the std_logic_1164 package of the IEEE library. It defines a number of the states for a digital signal which helps in simulation

A constant is an object whose value may not change.

Syntax

constant constant_name : constant_type [:= value ] ;

e.g. : constant pi : real := 3.147592;

constant datawidth : natural := 32;

It is used in the place of the value to make the code more readable.

The constant has just type and a value associated with it.

Constants are used to define data parameters ( buswidth, time delay

etc.) and lookup tables ( ROM etc)

Feb 2012 © Ruchi Rastogi Bani 30

Page 31: Data Types · Std_logic type is the data type defined in the std_logic_1164 package of the IEEE library. It defines a number of the states for a digital signal which helps in simulation

Feb 2012 © Ruchi Rastogi Bani 31

Precedence Operator Class Operators

Low

Hi

Logical And or Nand Nor Xor xnor

Relational = /= < <= > >=

Shift sll srl sla sra rol ror

Adding + - &

Sign + -

Multiplying * / mod rem

Miscellaneous ** abs not

Page 32: Data Types · Std_logic type is the data type defined in the std_logic_1164 package of the IEEE library. It defines a number of the states for a digital signal which helps in simulation

Logical Operators

◦ Logical operations on variables and signals of type std_logic, Bit and Boolean

◦ Can not be applied to any user defined data types.

◦ ex: y <= a and b;

Relational Operators

◦ Used in expression when it is necessary to compare the values of objects.

◦ Value returned by such expression is Boolean.

◦ May be applied to any built-in and user-defined scalar data object.

Adding Operators

◦ Concatenation produces a new one-dimensional array using two, one-dimensional array of the same data type.

Feb 2012 © Ruchi Rastogi Bani 32

Page 33: Data Types · Std_logic type is the data type defined in the std_logic_1164 package of the IEEE library. It defines a number of the states for a digital signal which helps in simulation

Lexical Elements

Data Types and subtypes

Object Classes

Operators

Feb 2012 © Ruchi Rastogi Bani 33