Digital Logic Circuits: Unit V: VHDL

VHDL Data Objects

Signal, Variable, Constant, File

• A data object holds a value or a range of values of a specified type. It is created by means of an object declaration. In VHDL, there are four classes of data objects, signals, variables, constants and file.

VHDL Data Objects

• A data object holds a value or a range of values of a specified type. It is created by means of an object declaration. In VHDL, there are four classes of data objects, signals, variables, constants and file.

 

1. Signal

• A signal is data object which holds a list of values. These values include the current value of the signal and also a set of possible future values that are to appear on the signal. The signal represents a wire/logic signal in a circuit. In VHDL, the signal can be placed in any of the following three places,

a) An entity declaration,

b) The declaration section of an architecture,

c) The declarative section of a package.

• The syntax for declaring signal is as follows :

SIGNAL signal_name : typename;

In this, the type_name indicates the legal value of the signal. The different signal types are : BIT, BIT.VECTOR,      BOOLEAN,         INTEGER,ENUMERATION, SIGNED, UNSIGNED, STD_LOGIC, STD_LOGIC_VECTOR, STD_ULOGIC etc.

The examples are given below.

SIGNAL X : BIT;

• This signal declares the signal object X which is of type BIT. The initial value of this signal is 'O' as 'O' is the leftmost value of type BIT.

 

2. Variable

• A variable is used to hold a signal value of a given type. Unlike a signal, a variable does not necessarily represent a wire in a circuit. Variables can be assigned a single value of a specific type. The different values can be assigned to the variable at different times. For this a variable assignment statement is used. The variable declaration has the following form :

VARIABLE variablename : variabletype : = initial value; For example,

VARIABLE index : INTEGER RANGE 0 TO 20 : = 0;

• Here, the variable 'index' is an integer having values between 0 and 20 and is initialized to the value 0.

• The variables are used for computations within procedures, functions and processes. The variables are sometimes used for the index variables in loops. 

They are also sometimes used to hold the results of computations.

 

3. Constant

• The syntax for declaring a constant in a VHDL is given below.

CONSTANT constant_name : type_name : = value;

For example,

CONSTANT BUS_SIZE : INTEGER := 32; - width of component

• It is to be noted that the value of a constant can be a simple expression.

 

4. File

• This is a special class of data objects. It serves as the interface between VHDL programs and the host environment. There are some special operations that can be performed only on files. These are reading and writing files. The basic operations that we need for reading and writing files are as given below.

• Declaration of a file type

■ Declaration of a file

■ Opening and closing a file of a specified type

■ Reading from a file and writing to a file

• Now we will discuss each operation with example.

1. File type declarations

• While declaring a file, we should ensure that the host environment correctly interprets the format of the data which is stored in the file. So before declaration of the file, it is necessary to declare its type. For example, text file. This file consists of text strings of variable length. The syntax of a file type declaration is as given below,

TYPE file_type_name IS FILE OF type_name;

The type_name is the type of values contained in the file. For example,

TYPE TEXT IS FILE OF string;

This defines a file of type TEXT that has a sequence of strings as values in it.

2. File declarations

• After declaring a particular type of a file, we can declare a file object. The syntax of a file declaration is as given below,

FILE file_names : file_type_name [open mode] IS string_expression;

• The file can be used as a read-only, write-only or in the append mode. The mode in the syntax specifies any of these utilization. The host-environment interprets the string expression as the physical name of a file. For example,

FILE Input_File : TEXT OPEN READ-MODE IS

"/user/home/add.txt";

• Here, a file Input_File is declared to be of file type TEXT. That is, it has a sequence of strings. The READ_MODE specifies that the file will be opened in read-only mode. The string expression given after the keyword 'IS' specifies the path name to a physical file in the host environment.

3. Opening and closing files

• After declaring file of a specific type, it is necessary to open the file before using it and to close it before terminating the program. There are procedures and functions to open and close a file. These are given below :

PROCEDURE FILE_OPEN (FILE FI: file_type_name;

file_name : IN STRING;

OPENKIND : IN FILEOPENKIND : =

READMODE);

- - Opens the file FI that points to the physical file specified in the string file_name - - with the specified mode. Type FILE_OPEN_KIND has value READ_MODE.

A file can be opened in three modes, READ_MODE, WRITE_MODE and APPEND_MODE. The default mode is READ_MODE.

PROCEDURE FILE_OPEN (file_status : OUT

FILE_OPEN_STATUS;

file FI : file_type_name;

file_name : IN STRING

OPEN KIND : IN FILE OPEN KIND : = READ MODE);

- - This procedure returns the file open status, (other things are -similar to the first procedure).

The FILE_OPEN_STATUS has a value returned by the procedure.

• This parameter may have one of the following four values.

1. OPEN_OK : File open operation was successful. 

2. STATUS_ERROR : Attempted to open an already open file.

3. NAME_ERROR : File not found or not accessible.

4. MODE_ERROR : File cannot be opened in this mode.

• The value of FILE_OPEN_STATUS can be checked to ensure that the FILE_OPEN call was successful.

PROCEDURE FILE_CLOSE (File F : file_type_name);

• The FILE_CLOSE procedure closes the file. There exists an implicit call to FILE_CLOSE procedure which is called when execution terminates.

4. Reading and writing files

• We need procedures and functions to read and write files of the declared type. The standard VHDL procedures and function can be declared as given below.

PROCEDURE READ (FILE F : file_type_name; value : OUT type);

PROCEDURE WRITE (FILE F : file_typename; value : IN type);

FUNCTION ENDFILE (FILE F : file_type_name)

RETURN BOOLEAN;

• The above I/O procedures are implicitly declared following a file type declaration. It is not required to declare these procedures prior to their use. The procedures READ and WRITE are used for I/O operations. When we are reading from files, the ENDFILE function is used to test for the end of file. The different data types such as character, integer, real etc. can be read or written with a set of procedures supported by VHDL.

Review Question

1. With the help of suitable examples explain the data objects : constant, variable, signal and file.


Digital Logic Circuits: Unit V: VHDL : Tag: : Signal, Variable, Constant, File - VHDL Data Objects