VHDL Unit 2 Part 2
VHDL Unit 2 Part 2
HDLs are indeed similar to programming languages but not exactly the same. We
utilize a programming language to build or create software, whereas we use a
hardware description language to describe or express the behavioral characteristics
of digital logic circuits.
Hardware description languages allow you to describe a circuit using words and
symbols, and then development software can convert that textual description into
configuration data that is loaded into the FPGA in order to implement the desired
functionality.
VHDL is a hardware description language that is used to describe the behavior and
structure of digital systems. The acronym VHDL stands for VHSIC Hardware
Description Language, and VHSIC in turn stands for Very High Speed Integrated
Circuit. However, VHDL is a general-purpose hardware description language which
can be used to describe and simulate the operation of a wide variety of digital
systems. Keep in mind it’s H D L…
Advantages of VHDL
– It’s like the assembly language of HDLs.
– Simple
VHDL a1 b1
VHDL 2
a2 b2
6
CODE Synthsize 3
a3
FPLD b3
7
4 8
Software a4
GND
0
b4
Widely used for FPGAs and military A better grasp on hardware modeling
VHDL Terminologies
1) Entity: All designs are expressed in terms of entities. An entity is
themost basic building block in a design.
2) Architecture: All entities that can be simulated have an architecture
description. The architecture describes the behavior
of the entity. A single entity can have multiple
architectures. One architecture might be behavioral while
another might be a structural description of the design.
3) Configuration: A configuration statement is used to bind a
component instance to an entity-architecture pair. A
configuration can be considered like a parts list
for a design. It describes which behavior to use for each entity,
much like a parts list describes which part to use for each part in
the design.
4) Package: A package is a collection (library) of
commonly used data types and subprograms
used in a design. Think of a package as a tool- box that
contains tools used to build designs.
5) Driver. This is a source on a signal. If a signal is driven by two
sources, then when both sources are active, the signal will have
two drivers.
6) Bus. The term “bus” usually brings to mind a group of signals
or a particular method of communication used in the design of
hardware. In VHDL, a bus is a special kind of signal that may
have its drivers turned off.
7) Attribute: An attribute is data that are
attached to VHDL objects or predefined data
about VHDL objects (type of objects like type
of variables in C). Examples are the current drive
capability of a buffer or the maximum operating temperature
of the device.
8) Generic: A generic is VHDL’s term for a parameter
that passes information to an entity. For
instance, if an entity is a gate level model with a
rise and a fall delay, values for the rise and
fall delays could be passed into the entity
with generics.
The following is an example of an entity for an AND gate that
has threegenerics associated with it:
LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;
ENTITY test IS
COMPONENT AND2
GENERIC(rise, fall : TIME; load : INTEGER);
PORT ( a, b : IN std_logic;
c : OUT std_logic);
END COMPONENT;
BEGIN
U1: AND2
GENERIC MAP(10 ns, 12 ns, 3 )
PORT MAP (ina, inb, out1 );
U2: AND2
GENERIC MAP(9 ns, 11 ns, 5 )
Structural Description
The circuit of Figure can also be described using structural VHDL code. To do so
requires that a two-input AND-gate component and a two-input
OR-gate component be declared and defined. Components may be
declared and defined either in a library or within the
architecture part of the VHDL code.
Lexical Elements
Lexical elements are basic syntactical units in a VHDL program and include
1) Comments:
Comments start with two dashes, e.g.,
-- This is a comment in VHDL
2) Identifiers:
An identifier can only contain alphabetic letters, decimal digits
and underscore; the first character must be a letter and the last character
cannot be an underscore. Also,two successive underscores are not allowed.
Valid examples:
A10, next_state, NextState, mem_addr_enable
Invalid examples:
sig#3, _X10, 7segment, X10_, hi_ _there
3) Reserved words
4) Numbers:
Integer: 0, 1234, 98E7
Real: 0.0, 1.23456 or 9.87E6
Base 2: 2#101101#
5) Characters
‘A’, ‘Z’, ‘1’
6) Strings
“Hello”, “1100111”
Note that 0 and ‘0’ are different
7) VHDL is case INsensitive, i.e., the following identifiers are the same
nextstate,NextState, NEXTSTATE, nEXTsTATE.
8) Use CAPITAL_LETTERs for constant names and the suffix_n to indicate active
low signals
Propagation Delay
When we initially describe a circuit, we may not be concerned about propagation
delays. If we write
C <= A and B;
E <= C or D;
this implies that the propagation delays are 0 ns. In this case, the
simulator will assume an infinitesimal delay referred to as Δ (delta).
Assume that initially A = 1 and B = C = D = E = 0. If B is changed to 1 at time = 1
ns, then C will change at time 1 + Δ and E will change at time 1 + 2 Δ.
Unlike a sequential program, the order of the above
concurrent statements is unimportant. If we write
E <= C or D;
C <= A and B;
the simulation results would be exactly the same as before. In general, a signal
assignment statement has the form
value of ‘sel’)
i1 AFTER 10 ns WHEN 1,
i2 AFTER 10 ns WHEN 2,
i3 AFTER 10 ns WHEN 3,
‘X’ AFTER 10 ns WHEN OTHERS;
Repeated Execution
Even if a VHDL program has no explicit loops, concurrent statements may execute
repeatedly as if they were in a loop. Figure shows an inverter with the output
connected back to the input. If the output is ‘0’, then this ‘0’ feeds back to the input
and the inverter output changes to ‘1’ after the inverter delay, assumed to be 10 ns.
Then, the ‘1’ feeds back to the input, and the output changes to ‘0’ after the inverter
delay. The signal CLK will continue to oscillate between ‘0’ and ‘1’, as shown in
the waveform. The corresponding concurrent VHDL statement will produce the
same result. If CLK is initialized to ‘0’, the statement executes and CLK changes to
‘1’ after 10 ns. Because CLK has changed, the statement executes again, and CLK
will change back to ‘0’ after another 10 ns. This process will continue indefinitely.
Syntax Rules
In general, VHDL is not case sensitive, that is, capital and
lower case letters are treated the same by the compiler and
the simulator. Thus, the statements
Clk <= NOT clk After 10 NS;
and CLK <= not CLK after 10 ns;
would be treated exactly the same.
Signal names and other VHDL identifiers may contain letters, numbers, and the
underscore character (_). An identifier must start with a letter, and it cannot end with
an underscore. Thus, C123 and ab_23 are legal identifiers, but 1ABC and ABC_ are
not. Every VHDL statement must be terminated with a
semicolon. Spaces, tabs, andcarriage returns are treated in the same way. This
means that a VHDL statement can be continued over several lines, or several
statements can be placed on one line. In a line of VHDL code, anything
following a double dash (--) is treated as a comment.Words such
as and, or, and after are reserved words (or keywords) which have a special
meaning to the VHDL compiler.
Figure shows three gates that have the signal A as a common input and the corresponding
VHDL code. The three concurrent statements execute simultaneously
whenever A changes, just as the three gates start processing the
signal change at the same time. This is Instantiation. If all 3 gates
have same propagation delays, output D,E and F after at the same
time. However, if the gates have different delays, the gate outputs
can change at different times. If the gates have delays of 2 ns, 1 ns,
and 3 ns, respectively, and A changes at time 5 ns, then the gate
outputs D, E, and F can change at times 7 ns, 6 ns, and 8 ns,
respectively. The VHDL statements work in the same way. Even
though the statements execute simultaneously, the signals D, E,
and F areupdated at times 7 ns, 6 ns, and 8 ns.
Figure shows a 2-to-1 multiplexer (MUX) with two data inputs and one
control input. The MUX output is F = A’.I0 + A·I1. The
corresponding VHDL statement is F <= (not A and I0) or
(A and I1);
Alternatively, we can represent the MUX by a Conditional Signal
Assignment Statement, as shown in Figure. This statement
executes whenever A, I0, or I1 changes. The MUX output is I0 when A
= ‘0’, and else it is I1. In the conditional statement, I0, I1, and F can
either be bits or bit-vectors.
The general form of a conditional signal assignment statement is:
when condition1
else expression2
when condition2
[else expressionN];
else
I1 when
A&B=“01”
else
I2 when
A&B=“10”
else I3;
else I1 when
else I2 when A
else I3;
Select Statement
A third way to model the MUX is to use a selected signal
assignment statement, as shown in Figure . A&B cannot be used in
this type of statement, so
...
[expression_n [after delay-time] when others];
Sequential Statements
1) IF Statement
IF condition THEN sequence_of_statements
{ELSIF condition THEN sequence_of_statements}
[ELSE
sequence_of_statements]
END IF;
Example:
2) CASE Statement
Example:
TYPE vectype IS ARRAY(0 TO 1) OF BIT;
VARIABLE bit_vec : vectype;
.
CASE bit_vec IS
WHEN “00” =>RETURN 0;
WHEN “01” =>RETURN 1;
WHEN “10” =>RETURN 2;
WHEN “11” =>RETURN 3;
END CASE;
3) LOOP Statement
Example:
Syntax is:
[label:] process (sensitivity list)
constant or variable declarations
begin
sequential statements;
end process [label];
Example:
PROCESS(i)
BEGIN
x <= i + 1; -- x is a signal
FOR i IN 1 to a/2 LOOP
q(i) := a; -- q is a variable
END LOOP;
END PROCESS;
5) NEXT Statement:
The process statement contains one LOOP statement. This LOOP statement logically
“and”s the bits of arrays a and b and puts the results in array q. The NEXT statement
allows the designer the ability to stop execution of this iteration and go on to the next
iteration. There are other cases when the need exists to stop execution of a loop
completely. This capability is provided with the EXIT statement. This behavior
continues whenever the flag in array done is not true. If the done flag is already set for
this value of index i, then the NEXT statement is executed. If the value of the done
array is not true, then the NEXT statement is not executed, and execution continues with
the statement contained in the ELSE clause for the IF statement.
Example:
PROCESS(A, B)
CONSTANT max_limit : INTEGER := 255;BEGIN
FOR i IN 0 TO max_limit LOOP
IF (done(i) = TRUE) THEN
NEXT;
ELSE
done(i) := TRUE;
END IF;
q(i) <= a(i) AND b(i);
END LOOP;
END PROCESS;
6) EXIT Statement
During the execution of a LOOP statement, it may be necessary to jump out of the loop.
This can occur because a significant error has occurred during the execution of the model
or all of the processing has finished early. The VHDL EXIT statement allows the
designer to exit or jump out of a LOOP statement currently in execution.
Example:
PROCESS(a)
variable int_a : integer;
BEGIN
int_a := a;
y <= q;
END PROCESS;
7) WAIT Statements
The WAIT statement gives the designer the ability to suspend the sequential execution of
a process or subprogram. The conditions for resuming execution of the suspended process
or subprogram can be specified by the following three different means:
WAIT ON signal changes
WAIT UNTIL an expression is true
WAIT FOR a specific amount of time
PROCESS
BEGIN
WAIT UNTIL clock = ‘1’ AND clock’EVENT;
q <= d;
END PROCESS;
This process is used to generate a flip-flop that clocks the value of d into q when the
clock input has a rising edge. The attribute ‘EVENT attached to input clock is true
whenever the clock input has had an event during the current delta timepoint. The
effect is that the process is held at the WAIT statement until the clock has a rising
edge. Then the current value of d is assigned to q.
Reading this description into a synthesis tool creates a D flip-flop without a set or reset
input. A synchronous reset can be created by the following:
PROCESS
BEGIN
WAIT UNTIL clock = ‘1’ AND clock’EVENT;
IF (reset = ‘1’) THEN
q <= ‘0’;
ELSE
q <= d;
END IF;
END PROCESS;
PROCESS
BEGIN
IF (reset = ‘1’) THEN
q <= ‘0’;
ELSIF clock’EVENT AND clock = ‘1’ THEN
q <= d;
END IF;
To write a complete VHDL module, we must declare all of the input and output
signals using an entity declaration, and then specify the internal operation of the
module using an architecture declaration.
As an example, consider above Figure. The entity declaration gives the name “two_gates” to the
module. The port declaration specifies the inputs and outputs to the module. A, B, and D are
input signals of type bit, and E is an output signal of type bit. The architecture is named “gates”.
The signal C is declared within the architecture because it is an internal signal. The two
concurrent statements that describe the gates are placed between the keywords begin and end.
When we describe a system in VHDL, we must specify an entity and an architecture at the top
level, and also specify an entity and architecture for each of the component modules that are
part of the system (see below figure).
Entity Declaration
Each entity declaration includes a list of interface signals that can be used to connect to other
modules or to the outside world. We will use entity declarations of the form:
entity entity-name is
[port(interface-signal-declaration);]
end [entity] [entity-name];
A system (an entity) can be specified with different architectures.