VHDL MINI-REFERENCE (E-Note) : Entity Declaration Format
VHDL MINI-REFERENCE (E-Note) : Entity Declaration Format
DSD by S.S.JAIN
entity name is
port( port definition list );-- input/output signal ports
generic( generic list); -- optional generic list
end name;
Port declaration format: port_name: mode data_type;
The mode of a port defines the directions of the singals on that pirt, and is one of: in, out, buffer,
or inout.
Port Modes:
An in port
can be read but not updated within the module, carrying information into the module. (An
in port cannot appear on the left hand side of a signal assignment.)
An out port
can be updated but not read within the module, carrying information out of the module.
(An out port cannot appear on the right hand side of a signal assigment.)
A buffer port
likewise carries information out of a module, but can be both updated and read within the
module.
An inout port
is bidirectional and can be both read and updated, with multiple update sources possible.
NOTE: A buffer is strictly an output port, i.e. can only be driven from within the module,
while inout is truly bidirectional with drivers both within and external to the module.
Example
entity counter is
port (Incr, Load, Clock: in bit;
Carry: out bit;
Data_Out: buffer bit_vector(7 downto 0);
Data_In: in bit_vector(7 downto 0));
end counter;
Generics allow static information to be communicated to a block from its environment for all
architectures of a design unit. These include timing information (setup, hold, delay times), part
sizes, and other parameters.
Example
entity and_gate is
port(a,b: in bit;
c: out bit);
generic (gate_delay: time := 5ns);
end and_gate;
Architecture
An architecture defines one particular implementation of a design unit, at some desired level of
abstraction.
architecture arch_name of entity_name is
DSD by S.S.JAIN
... declarations ...
begin
... concurrent statements ...
end
Declarations include data types, constants, signals, files, components, attributes, subprograms,
and other information to be used in the implementation description. Concurrent statements
describe a design unit at one or more levels of modeling abstraction, including dataflow,
structure, and/or behavior.
VHDL PACKAGES
A VHDL package contains subprograms, constant definitions, and/or type definitions to be used
throughout one or more design units. Each package comprises a "declaration section", in which
the available (i.e. exportable) subprograms, constants, and types are declared, and a "package
body", in which the subprogram implementations are defined, along with any internally-used
constants and types. The declaration section represents the portion of the package that is "visible"
to the user of that package. The actual implementations of subroutines in the package are
typically not of interest to the users of those subroutines.
Example:
package ee530 is
constant maxint: integer := 16#ffff#;
type arith_mode_type is (signed, unsigned);
function minimum(constant a,b: in integer) return integer;
end ee530;
Example:
DSD by S.S.JAIN
package body ee530 is
function minimum (constant a,b: integer) return integer is
variable c: integer; -- local variable
begin
if a < b then
c := a; -- a is min
else
c := b; -- b is min
end if;
return c; -- return min value
end;
end ee530;
Package Visibility
To make all items of a package "visible" to a design unit, precede the desired design unit with a
"use" statement:
Example:
use library_name.package_name.all
A "use" statement may precede the declaration of any entity or architecture which is to utilize
items from the package. If the "use" statement precedes the entity declaration, the package is also
visible to the architecture.
User-Developed Packages
Example
This package contained in the 'ieee' library supports multi-valued logic signals with type
declarations and functions. To make visible:
library ieee; -- VHDL Library stmt
use ieee.std_logic_1164.all;
DSD by S.S.JAIN
Special 12-valued data types/functions to interface with QuickSim II and
schematic diagrams.
library mgc_portable; -- Special Mentor Graphics Library
use mgc_portable.qsim_logic.all; -- Quicksim portable data types
Identifiers in VHDL must begin with a letter, and may comprise any combination of letters,
digits, and underscores. Note that VHDL internally converts all characters to UPPER CASE.
Examples
Numeric Constants
Numeric contants can be defined, and can be of any base (default is decimal). Numbers may
include embedded underscores to improve readability.
Examples
16#9fba# (hexadecimal)
2#1111_1101_1011# (binary)
16#f.1f#E+2 (floating-point, exponent is decimal)
Examples
Expressions in VHDL are similar to those of most high-level languages. Data elements must be
of the type, or subtypes of the same base type. Operators include the following:
DSD by S.S.JAIN
Logical: and, or, nand, nor, xor, not (for boolean or bit ops)
Relational: =, /=, <, <=, >, >=
Arithmetic: +, -, *, /, mod, rem, **, abs
(a mod b takes sign of b, a rem b takes sign of a)
Concatenate: &
(ex. a & b makes one array)
Examples
a <= b nand c;
d := g1 * g2 / 3;
Bus_16 <= Bus1_8 & Bus2_8;
VHDL Standard:
'U' = uninitialized
'X' = unknown
'W' = weak 'X'
'Z' = floating
'H'/'L' = weak '1'/'0'
'-' = don't care
DSD by S.S.JAIN
Predefined VHDL Aggregate Data Types
Examples
An enumerated data type can be created by explicitely listing all possible values.
Example
Custom data types can include arrays, constrained and unconstrained, and record structures.
Example
Unconstrained array: Indexes are specified when a signal or variable of that type is
declared.
Examples
DSD by S.S.JAIN
type memory is array (integer range <>) of bit_vector(0 to 7);
-- a type which is an arbitrary-sized array of 8-bit vectors
variable memory256: memory(0 to 255); -- a 256-byte memory array
variable stack: memory(15 downto 0); -- a 16-byte memory array
Examples
Aliases
An alias" defines an alternate name for a signal or part of a signal. Aliases are often used to refer
to selected slices of a bit_vector.
Example
A constant associates a value to a symbol of a given data type. The use of constants may
improve the readability of VHDL code and reduce the likelihood of making errors. The
declaration syntax is:
constant symbol: type := value;
Examples
Variables
DSD by S.S.JAIN
aggregate data type, and is utilized primarily in behavioral descriptions. It can optionally be
assigned initial values (done only once prior to simulation). The declaration syntax is:
variable symbol: type [:= initial_value];
Examples
process
variable count: integer := 0;
variable rega: bit_vector(7 downto 0);
begin
...
count := 7; -- assign values to variables
rega := x"01";
...
end;
Signals
A signal is an object with a history of values (related to "event" times, i.e. times at which the
signal value changes).
Signals are declared via signal declaration statements or entity port definitions, and may be of
any data type. The declaration syntax is:
Examples
Event Values
Times
NOTE: If no delay is specified, the signal event is scheduled for one infinitessimally-small
"delta" delay from the current time. The signal change will occur in the next simulation cycle.
DSD by S.S.JAIN
Examples
Examples
NOTE: The std_logic and std_logic_vector types from the ieee library have predefined resolution
functions:
Example
CONCURRENT STATEMENTS
DSD by S.S.JAIN
Concurrent statements are included within architecture definitions and within "block" statements,
representing concurrent behavior within the modelled design unit. These statements are executed
in an asynchronous manner, with no defined order, modeling the behavior of independent
hardware elements within a system.
A signal assignment statement represents a process that assigns values to signals. It has three
basic formats.
1. A <= B; A <= B when condition1 elseC when condition2 else D when condition3 else E;
2. with expression select A <= B when choice1, C when choice2, D when choice3, E when
others;
For each of the above, waveforms (time-value pairs) can also be specified.
Examples
-- A is a 16-bit vector
A <= (others => '0'); -- set all bits of A to '0'
The keyword "others" in the last example indicates that all elements of A not explicitly listed are
to be set to '0'.
Process Statement
An independent sequential process represents the behavior of some portion of a design. The body
of a process is a list of sequential statements.
DSD by S.S.JAIN
Syntax:
Example
Block Statement
A block is a grouping of related concurrent statements that can be used in representing designs in
a hierarchical manner.
Syntax:
Examples
end block;
DSD by S.S.JAIN
block (Clock'EVENT and Clock = '0')
begin
Q <= guarded D after 5ns;
end block;
In the last example, B is assigned to signal A only when GUARD is true, which implies Enable =
'1'.
Example
Component instantiation
Instantiates (i.e. create instances of) predefined components within a design architecture. Each
such component is first declared in the declaration section of that architecture, and then
"instantiated" one or more times in the body of the architecture.
In the declaration section: list the "component declaration" and one or more
"configuration specifications".
The "component declaration" defines the component interface, which corresponds to the
component's entity declaration. This allows the VHDL compiler to check signal
compatibilities.
Example
component adder
port(a,b: in bit_vector(7 downto 0);
s: out bit_vector(7 downto 0);
cin: in bit;
cout: out bit);
end component;
DSD by S.S.JAIN
The "configuration specification" identifies specific architecture(s) to be used for each
instance of the component. (There may be multiple architectures for a given component.)
Examples
In all three examples, the prefix work. indicates that the current working library contains
the indicated component models. In the first example, architecture equations of entity
comp1 is used for all instances of comp1. In the other examples, architecture equations is
to be used for instance ADDER1 of component adder, and architecture dataflow is to be
used for instance ADDER2 of component adder.
Example
Example:
architecture r1 of register is
component jkff
port(J,K,CLK: in bit;
Q,QN: out bit);
end component;
for ALL: jkff use entity work.jkff (equations);
-- Use architecture equations of entity jkff
for all instances
component dff
port(D,CLK: in bit;
Q,QN: out bit);
end component;
DSD by S.S.JAIN
for DFF1: dff use entity work.dff (equations);
for DFF2: dff use entity work.dff (circuit);
--Use different architectures of dff for instances
DFF1 and DFF2
begin
JKFF1: jkff port map (j1,k1,clk,q1,qn1);
JKFF2: jkff port map (j2,k1,clk,q2,qn2);
DFF1: dff port map (d1,clk,q4,qn4);
DFF2: dff port map (d2,clk,q5,qn5);
end.
Concurrent assertion
A concurrent assertion statement checks a condition (occurrence of an event) and issues a report
if the condition is not true. This can be used to check for timing violations, illegal conditions, etc.
An optional severity level can be reported to indicate the nature of the detected condition.
Syntax:
Generate statement
Example
SEQUENTIAL STATEMENTS
Sequential statements are used to define algorithms to express the behavior of a design entity.
These statements appear in process statements and in subprograms (procedures and functions).
Wait statement
DSD by S.S.JAIN
- suspends process/subprogram execution until a signal changes, a condition becomes true, or a
defined time period has elapsed. Combinations of these can also be used.
Syntax:
Example
Suspend execution until one of the two conditions becomes true, or for 25ns, whichever occurs
first.
wait until clock = '1' or enable /='1' for 25ns;
Example
Example
A := B and C;
D := A; -- value of D is new A value
Procedure call
Conditional Statements
Standard if..then and case constructs can be used for selective operations.
if condition then
... sequence of statements...
elsif condition then
... sequence of statements...
else
... sequence of statements...
end if;
DSD by S.S.JAIN
NOTE: elsif and else clauses are optional.
case expression is
when choices => sequence of statements
when choices => sequence of statements
...
when others => sequence of statements
end case;
NOTE: case choices can be expressions or ranges.
Loop statements
Sequences of statements can be repeated some number of times under the control of while or for
constructs.
label: while condition loop
... sequence of statements ...
end loop label;
label: for loop_variable in range loop
... sequence of statements...
end loop label;
NOTE: the label is optional.
PROCEDURES
A procedure is a subprogram that is passed parameters and may return values via a parameter
list.
Example
DSD by S.S.JAIN
Procedure call: proc_name(clk1, d1, dout);
FUNCTIONS
A function is a subprogram that is passed parameters and returns a single value. Unlike
procedures, functions are primarily used in expressions.
Example
Function Calls:
DSD by S.S.JAIN
Other "ieee.std_logic_1164" functions
a + b, a - b, a * b, a / b, a mod b, a rem b
Logical operations between all signal types and vectors of signal types in the "ieee" library.
Type conversion:
OBJECT ATTRIBUTES
An object attribute returns information about a signal or data type.
DSD by S.S.JAIN
Examples
Examples
DSD by S.S.JAIN
B'BEHAVIOR - true if block B contains no component instantiations
B'STRUCTURE - true if no signal assignment statements in block B
Data Types:
Example Declarations
readline(F, L)
Read one line from "text" file F to "line" L
writeline(F, L);
Write one line to "text" file F from "line" L
DSD by S.S.JAIN