VHDL
VHDL
VHDL
VHDL
As the size and complexity of digital systems increase, they cannot be designed manually; their design
becomes highly complex. At their most detailed level, the circuit consists of millions of elements. So
Computer Aided Design (CAD) tools are used in the design of such systems. One such a tool is a Hardware
Description Language (HDL).
VHDL is an acronym for VHSIC Hardware Description Language (VHSIC- Very High Speed Integrated
Circuit). It is a hardware description language that can be used to model a digital system.
The basic elements of the language are – data objects, literals and operators.
Data objects-that store values of a given type.
Literals represent constant values.
Operatorsoperate on data object.
Identifiers
An identifier in VHDL is a sequence of one or more characters. There are two types if identifiers.
A basic identifier composed of sequence of legal character is an upper-case letter (A... Z), or a lower-case
letter (a. .. z), or a digit (0 . . . 9) or the underscore ( _ ) character.
1. The first character in an identifier must be a letter and the last character may not be an
underscore.
2. Lower-case and upper-case letters are considered to be identical when used in an identifier;
3. Also,-two underscore characters cannot appear consecutively.
Example:
\TEST\, \-25\ , \2FOR$\ , \process\ etc.
Comments in a description must be preceded by two consecutive hyphens (--); the comment extends to
the end of the line.
The language defines a set of reserved words. These words are called keywords, have a specific meaning
in the language, and cannot be used as identifiers.
Data Objects
A data object holds a value of a specified type. It is created by means of an object declaration.
2
Data objects
1. Constant:An object of constant class can hold a single value of a given type. This value is assigned
to the object before simulation starts and the value cannot be changed during the course of the
simulation.
Syntax:
CONSTANTconst-name: TYPE [:= value];
Examples:
constantRISE_TIME: TIME := 10ns;
constantBUS_WIDTH: INTEGER := 8:
constantNO_OF_INPUTS: INTEGER;
The first declaration declares the object RISE_TIME that can hold a value of type TIME predefined
and the value assigned to the object at the start of simulation is 10 ns.
The second constant declaration declares constant BUS_WIDTH of type INTEGER with a value of 8.
In the third declaration, the value of the constant has not been specified in this case. Such a
constant is called a deferred constant
2. Variable:An object of variable class can also hold a single value of a given type. But different
values can be assigned to the object at different times using a variable assignment statement.
Syntax:
VARIABLE var-name: TYPE [:= initial value];
Examples:
variableCTRL_STATUS: BIT_VECTOR(10 downto0);
variableSUM: INTEGER range Oto 100 := 10;
The first declaration specifies a variable object CTRL_STATUS as an array of II elements, with each
array element of type BIT.
In the second declaration, an explicit initial value has been assigned to the variable SUM. When
simulation starts, SUM will have an initial value of 10
3. Signal:signals are data objects in VHDL that are used to model interconnections and capable of
holding the list of values. An object belonging to the signal class has a past history of values, a
current value, and a set of future values. Future values can be assigned to a signal object using a
signal assignment statement. Signal objects can be regarded as wires in a circuit. Signal objects are
typically used to model wires and flip-flops while variable and constant objects are typically used
to model the behavior of the circuit.
Syntax:
SIGNAL sig -name: TYPE [:= initial value];
3
Examples:
signalCLOCK: BIT;
signalDATA_BUS: BIT_VECTOR(0 to 7);
signalGATE_DELAY: TIME := 10 ns;
The first signal declaration declares the signal object CLOCK of type BIT and gives it an initial value of '0'
('0' being the leftmost value of type BIT). The third signal declaration declares a signal object GATE_DELAY
of type TIME that has an initial value of 10 ns.
4. File:An object belonging to file class contains a sequence of values. Values can be read or written
Using file read procedures and write procedures.
Syntax:
Examples:
file STIMULUS:TEXT open READ_MODE is “/usr/home/jb/add.sti”;
file VECTORS:BIT FILE is “/usr/home/james/add.vec”;
In the first example, a file STIMULUS is declared to be a predefined file type TEXT; that is a file may
contain indefinite number of strings. The mode value READ_MODE specifies that the file will be opened in
read only mode and the string expression keyword is specifies the path name.
In the second example, VECTORS is declared as a file, containing an indefinite number of bit
vectors. This declaration also specifies the link to the file in the host environment. Since no mode is
specified, the default mode, READ_MODE is used.
Data Types
VHDL has a set of standard data types (predefined / built-in). It is also possible to have user defined data
types and subtypes. i.e., in VHDL the data types can be classified into
1. Predefined type
2. User defined type
Some of the predefined data types in VHDL are: BIT, BOOLEAN and INTEGER.
The STD_LOGIC and STD_LOGIC_VECTOR data types are not built-in VHDL data types, but are defined in
the standard logic 1164 package of the IEEE library.
BIT: it is the simplest and most important data type for a digital system based on the logic values
‘0’ and ‘1’. Any data object can be declared of the type bit before being used as Signal, Variable or
Constant
Boolean: It is predefined type that has values TRUE & FALSE. Some of the predefined operators
are and,or,not,nand,nor.
INTEGER: it is a predefined type with the set of values being integers in the range from
-(231 – 1) to + (231 -1).
1. Scalar Types
The values belonging to this type appear in sequential order. There are four different kinds of scalar types. These
types are
a. Enumeration
b. Integer
c. Physical
d. Floating point.
Integer types, floating point types, and physical types are classified as numeric types since the values associated
with these types are numeric.
a. Enumeration Types
An enumeration type declaration defines a type that has a set of user-defined values consisting of identifiers and
character literals. i. e., it can take value from a defined list. These values may be integers, identifiers or single
character literals.
SYNTAX:
TYPE nameIS
Examples :
Type MVL is ('U','0','1','Z);
Type BITis ('0','1');
TypeCAR_STATE is (STOP, SLOW, MEDIUM, FAST);
Type Boolean is (True ,False );
Type SEVERITY_LEVEL is (NOTE, WARNING, ERROR, FAILURE);
Type FILE_ OPEN_KIND is (READ_MODE, WRITE MODE , APPEND MODE);
Type FILE_ OPEN_KIND is (READ_MODE, WRITE MODE , APPEND MODE);
b. Integer Types
An integer type defines all integer values whose set of values fall within the specified range. The values can be
positive or negative. The range of the INTEGER type is in the range -(2^ 31 - 1) to +(2^31 - 1).
5
Values belonging to an integer type are called integer literals. Examples of integer literals are
56349 6E2 0 98_71_28
Literal 6E2 refers to the decimal value 6 * (10^2) = 600. The underscore ( _ ) character can be used freely in writing
integer literals and has no impact on the value of the literal; 98_71_28 is same as 987128.
CURRENT is defined to be a physical type that contains values from 0 nA to 10^9 nA. The base unit is a nano-
ampere while all others are derived units.
2. Composite Types
A composite type represents a collection of values of similar or different type. There are two types:
An array type and
A record type.
6
2. type DATEis
record
DAY: integer_range 1 to 31;
MONTH:month_name;
YEAR:integer_range0 to 4000;
end record;
3. type FORECASTis
record
Temp: integer_range20 to 200;
Day: Real;
Condition: Boolean;
end record;
Values can be assigned to a record type object using a single assignment statement.
3. Access Types
Access type points to address a particular type of object and is useful for accessing dynamically allocated objects.
Examples:
typePTR is access MODULE;
typeFIFO is array (0 to 63, 0 to 7) of BIT;
PTR is an access type whose values are addresses that point to objects of type MODULE.
4. File Types:
A file is a stream of values of specified type which can be read or written during simulation. Files belong to special
kind of data type called “file type”.
Syntax
typefile-type-name Is file of type-name,
The type-name is the type of values contained in the file.
Examples.
typeVECTORS is file of BIT_VECTOR;
typeNAMES is file of STRING;
A file of type VECTORS has a sequence of values of type BIT_VECTOR; a file of type NAMES has a sequence of
strings as values in it.
7
OPERATORS
An operator is a logical or mathematical function which takes one or two values and produces a single result.
The predefined operators in the language are classified into the following five categories:
1. Logical operators
2. Relational operators
3. Shift operators.
4. Adding operators
5. Multiplying operators
6. Miscellaneous operators
The precedence of operators are from (6) to (1). That is, the miscellaneous operators have highest precedence
while logical operators have lowest precedence. Operators in the same category have the same precedence and
evaluation is done left to right. Parentheses may be used to override the left to right evaluation.
1. Logical Operators
The seven logical operators are
And or nand nor xorxnor not
These operators are defined for the predefined types BIT and BOOLEAN and one-dimensional arrays of BIT and
BOOLEAN. During evaluation, bit values '0' and 1' are treated as FALSE and TRUE values of the BOOLEAN type,
respectively. The result of a logical operation has the same type as its operands. The not operator is a unary logical
operator and has the same precedence as that of miscellaneous operators.
2. Relational Operators
These are
= /= <<=>>=
The result types for all relational operations are always BOOLEAN (TRUE or FALSE). The = (equality) and the /=
(inequality) operators are permitted on any type except file types. The remaining four relational operators are
permitted on any scalar type.
For example,
BIT_VECTOR'('0', '1', '1') < BIT_VECTOR'('1', '0', '1')
is true, since the first element in the first array aggregate is less than the first element in the second aggregate.
Example:
a<= 101001
b<= a sla2 = 100111
d) sra– (shift right arithmetic):
It is an arithmetic shift operation which shifts the bits to right and thus the vacated bits to left are
replicated with leftmost bit. (Filled value is left hand bit)
Example:
a<= 101001 ;b<= a sra 2 = 111010
e) rol – rotate left:
It is a circular rotation operation which rotates the bits to left.
Example:
a<= 101001; b<= a rol 2 = 100110
f) ror – rotate right:
It is a circular rotation operation which rotates the bits to right.
Example:
a<= 101001; b<= a ror 2 = 011010
4. Adding Operators
These are
+ -&
The operands for the + (addition) and - (subtraction) operators must be of the same numeric type with the result
being of the same numeric type. The operands for the & (concatenation) operator can be either a
I-dimensional array type or an element type.
Example,
'0' & '1' results in an array of characters "01".
'C' & 'A' &'T' results in the value "CAT".
"BA" & "LL" creates an array of characters "BALL".
5. Multiplying Operators
These are
* / mod rem
Multiplication and Division: The * (multiplication) and / (division) operators are binary operators in which both the
operandsare of the same integer or floating point type. The result is also of the same type.
Remainder (rem): The rem (remainder) is a binary operator which returns the remainder of the division of two
integer values. The result is also of the same type, but the sign of the first operand.
A rem B = A - ( A / B ) * B
Example:
9
Modulus (Mod):The mod operator is a binary operator which works on integer values . The result of a mod
operator has the sign of the second operand and is defined as
A mod B = A – B * N -For some integer N.
Example:
N is the smallest value for which the result is that of the second operand.
6. Miscellaneous Operators
The miscellaneous operators are
abs**
The abs (absolute) operator is defined for any numeric type.
The ** (exponentiation) operator is defined for the left operand to be of integer or floating point type and
the exponent operator for the integer type only.
************************
Operator priority:
BEHAVIORAL MODELING
In behavioral style of modeling the behavior of the entity is expressed using sequentially executed,
procedural type code. The key features of this modeling are -
The behavioral modeling describes the system by showing how the outputs behave according to
the changes in the inputs.
While describing in the behavioral modeling, it is not necessary to know the logic diagram of
the system but it is required to know how the output behaves in response to the change in the
input.
In VHDL, process is the main behavioral description statement.
The statements inside the process are sequential.
Sequential statements are those statements, where the order or sequence of writing the statements is
important and defines the step by step execution, followed one after the other.
In concurrent style of modeling the digital circuit, the order of statements is not important. Data flow
and structural style modeling follow concurrent statements.
Every entity is represented using an entity declaration and at least one architecture body.
Entity Declaration:
An entity declaration describes the external interface of the entity, that is, it gives the black-box view. It
specifies the name of the entity, the names of interface ports, their mode (i.e., direction), and the type of
ports. The syntax for an entity declaration is
entity entity-name is
[ generic ( list-of-generics-and-their-types ) ; ]
[ port ( list-of-interface-port-names-and-their-types) ; ]
[ entity-item-declarations ]
[ begin
entity-statements]
end [ entity-name ];
The entity-name is the name of the entity and the interface ports are the signals through which the entity
passes information to and from its external environment. Each interface port can have one of the
following modes:
1. in: Unidirectional port, indicating that the signal is an input and data can be written to.
2. out: Unidirectional port, indicating that the signal is an output of an entity whose value can be read.
The value of an output port can only be updated within the entity model; it cannot be read.
3. inout: the value of a bidirectional port can be read and updated within the entity model.
2
4. buffer: the value of a buffer port can be read and updated within the entity model.
Example:
Consider an And-Or-Invert (AOI) circuit is shown in Fig. and its corresponding entity declaration is
A
B
Z
C
entity AOI is
port (A, B, C, D: in BIT; Z: out BIT);
end AOI;
The entity declaration specifies that the name of the entity is AOI and that it has four input signals of
type BIT and one output signal of type BIT.
Architecture Body
An architecture body describes the internal view of an entity. It describes the structure of the entity.
Architecture consists of two portions:
Architecture declaration and
Architecture body.
The syntax of an architecture body is
architecture architecture-name of entity-name is
[ architecture-item-declarations ]
begin
Concurrent-statements; these are —>
Process-statement
Block-statement
Concurrent-procedure-call
Concurrent-assertion-statement
Concurrent-signal-assignment-statement
Component-instantiation-statement
generate-statement
end [ architecture-name ] ;
The architecture name is a user defined name of the architecture body. It can be same as entity name or
different.
Process Statement
3
A process statement contains sequential statements that describe the functionality of a portion of an
entity in sequential terms. The syntax of a process statement is
[ process-label: ] process [ ( sensitivity-list ) ]
[process-item-declarations]
begin
sequential-statements; these are ->
variable-assignment-statement
signal-assignment-statement
wait-statement
if-statement
case-statement
loop-statement
null-statement
exit-statement
next-statement
assertion-statement
procedure-call-statement
return-statement.
end process [ process-label];
Sensitivity list:
Sensitivity list is the set of signals to which the process is sensitive to (responsive). i.e., whenever an
event occurs on any one of the signals in the sensitivity list, process comes into execution. The process
is suspended only after executing all the statements inside the process in sequence.
For eg: Consider the behavior model of AND gate. The signals A,B are included in the
sensitivity list. So whenever the value of ‘A’ or ‘B’ or both changes from ‘0’ to ‘1’ or ‘1’
to ‘0’ , the process will start execution and the output of the gate is updated
according to the expression C <= A and B;
Any change in the state of any element of the sensitivity list s treated as an event. The process is
activated (initiated) on if an event occurs; otherwise process remains inactive. If the process has no
sensitivity list, the process is executed continuously.
Variables are the class of VHDL objects allowed only with the sequential style of modeling. Variables
are objects that are used for the local storage within a process and subprogram alone. Inside a process
local variables can be declared in the declarative part before the keyword begin to represent its local
temporary values.
4
The first statement of the process statement is the variable assignment statement that assigns a value to
variable temp. Variables can be declared and used inside a process statement. A variable is assigned a
value using the variable assignment statement that typically has the form
Variable-object : = expression;
Signals Variables
1. 1.These are VHDL objects used to These are temporary storage in VHDL
represent wires and interconnections
2. .Values of signals are updated only Values of variables are updated immediately
after default delta delay or specified on the execution of variable assignment
user delay statement.
3. Require event scheduling and No event scheduling and synchronizing is
synchronizing of signal drivers. required.
4. Consume more memory space Consume less memory space
5. Use of signals is allowed in styles of Variables are used only in behavioral modeling
modeling
6. Assignment operator is <= Assignment operator is :=
[Write the VHDL code for the AOI circuit using Behavioral modeling].
entity AOI is
port (A, B, C, D: in BIT; Z: out BIT);
end AOI;
C
5
Write the VHDL code for two input nand gate using Behavioral modeling
Entity nand2 is
Port ( A : in bit;
B: in std-logic ;
C : out std-logic);
End nand2;
Begin
if A='1' and B='1' then
C<= '0';
else
C <= '1';
End if;
End process;
End behavioral;
The syntax is
Signal-object <= expression [after delay-value ];
Example:
COUNTER <= COUNTER+ "0010"; - Assign after a delta delay.
PAR <= PAR xor DIN after 12 ns;
Z <= (A0 and A1) or (B0and B1) or (C0 and C1) after 6 ns;
Delta Delay
A delta delay is a very small delay. This delay models hardware where a minimal amount of time is
needed for a change to occur. Delta delay allows for ordering of events that occur at the same simulation
time during a simulation. Each unit of simulation time can be considered to be composed of an infinite
number of delta delays. Therefore, an event always occurs at a real simulation time plus an integral
multiple of delta delays.
For example, events can occur at 15 ns, 15 ns+IA, 15 ns+2A, 15 ns+3A,
22 ns, 22 ns+A, 27 ns, 27 ns+A, and so on.
Let us assume that an event occurs on input signal D (i.e., there is a change of value on signal D) at
simulation time T. Statement I is executed first and TEMPI is assigned a value immediately since it is a
variable. Statement 2 is executed next and TEMP2 is assigned a value immediately. Statement 3 is
executed next which uses the values of TEMPI and TEMP2 computed in statements I and 2,
respectively, to determine the new value for TEMPI. And finally, statement 4 is executed that causes
signal Z to get the value of its right-hand-side expression after a delta delay, that is, signal Z gets its
value only at time T+A; this is shown in Fig.
Sequential statements:
The sequential statements exist inside the boundaries of a process statement as well as sub-programs.
These are-
8
Wait Statement:
4. WAIT FOR 0:
Syntax : Wait for 0ns
It means to wait for one delta cycle. This is a useful statement when the process is to be delayed.
For e.g.:
Wait 0: process
Begin
Wait on data
Sig_A <= data;
Wait for 0 ns;
Sig_B <= Sig_A;
End process;
The Wait for 0ns causes the process to suspend for 1Δ. SIG_A gets updated with its new value. Process
resumes at 10 + 1Δ. SIG_B gets the new value of SIG_A at 10 + 2Δ. This is as shown below.
Data
SIG_A
SIG_B
If Statement:
9
The if statement is a statement that depending on the value of one or more corresponding conditions,
selects for execution one or none of the enclosed sequences of statements, IF statement exists in three
forms.
1. if boolean-expression then
sequential-statements
end if;
Example1:
entity NOR2 is
port (A, B: in BIT; Z: out BIT);
end NOR2;
architecture behaviour of NOR2 is Y=
A B
begin A+B
process (A, B) 0 0 1
0 1 0
constant RISE_TIME: TIME := 10 ns;
1 0 0
constant FALL_TIME: TIME := 5 ns:
1 1 0
variable TEMP: BIT;
begin
TEMP := A nor B;
If (TEMP = '1 ') then
Z <= TEMP after RISE_TIME;
else
Z <= TEMP after FALL_TIME;
end if;
end process;
end Behaviour;
2. if boolean-expression then
sequential-statements
elsif
boolean-expression then
sequential-statements
else
sequential-statements
end if;
Entity dff is
PORT (d, clk, rst : in-std-logic;
Q, qbar: out-std-logic );
End dff;
Architecture behavior of dff is
Begin
Process(rst, clk)
Begin
If rst = ‘0’ then
Q = ‘0’;
elsif clk ‘event and clk =’1’ then
Q = ‘d’;
End if;
End Process;
End behavior;
3 if boolean-expression then
sequential-statements
else
sequential-statement
end if;
Entity counter is
Port(E,clk,rst : in_std_logic;
Count: inout std_logic_vector (3 down to 0);
End counter;
The if statement is executed by checking each condition sequentially until the first true condition is
found; then, the set of sequential statements associated with this condition is executed. The if statement
11
can have zero or more elsif clauses and an optional else clause. An if statement is also a sequential
statement, and therefore, the previous syntax allows for arbitrary nesting of if statements.
(Refer more programs in ‘Godse’)
Case Statement:
The syntax is
case expression is
when choices => sequential-statements
when choices => sequential-statements
[ when others => sequential-statements ]
.
.
..
end case;
The CASE statement executes the proper statement depending on the value of the input instruction. If
the value of the instruction is one of the choices listed in the WHEN clauses then the statement
following the when clause is executed.
If the value of the expression is outside the range of the choices given, then the expression following the
OTHERS clause is executed.
Examples:
I 2 x 4 decoder Y
0 0
12
INPUTS OUTPUTS
3 1 A(3) A(2) A(1) A(0) B(1) B(0)
Encoder 4 X 2 0 0 0 1 0 0
A B 0 0 1 0 0 1
0 1 0 0 1 0
0 0 1 0 0 0 1 1
entity encoder is
Port (A: in STD_LOGIC_ VECTOR (3 Down to 0);
B: out STD_LOGIC_VECTOR (1 Down to 0));
end encoder;
Null Statement
The statement NULL is a sequential statement that does not cause any action to take place and
execution continues with the next statement.
13
It can be used to indicate that when some conditions are met, no action is to be performed. Such an
application is useful in particular in conjunction with case statements to exclude some conditions.
Example:
Loop Statement:
Loop is a sequential statement. The LOOP statement is used whenever an operation needs to be
repeated. Loop statements are used for iteration is needed in a model.
The syntax of a loop statement is
[ loop-label : ] iteration-scheme loop
sequential-statements
end loop [ loop-label ] ;
There are three types of iteration schemes.
for iteration scheme.
FOR identifier In range LOOP
Statements;
END LOOP;
END LOOP;
For Loop:
The FOR-LOOP statement is used whenever an operation needs to be repeated.
The for loop defines a loop parameter which takes on the type of the range specified.
Write the VHDL code for factorial of a number using FOR LOOP:
Entity fact is
PORT (clk: in-std-logic;
Factorial : out-integer );
End fact;
While Loop:
WHILE loop differs from FOR loop as it repeats the sequential statements until a particular condition
is met with. The syntax is
while boolean-expression
Example:
J:=0;SUM:=10;
while J < 20 loop
SUM := SUM * 2;
15
J:=J+3;
end loop;
The statements within the body of the loop are executed sequentially and repeatedly as long as the loop
condition, J < 20, is true. At this point, execution continues with the statement following the loop
statement.
The third and final form of the iteration scheme is one where no iteration scheme is specified . In this
form of loop statement, all statements in the loop body are repeatedly executed until some other action
causes it to exit the loop. These actions can be caused by an exit statement, a next statement, or a return
statement
Example:
SUM:=1;J:=0;
L2: a label loop
J:=J+21;
SUM := SUM* 10;
exit when SUM > 100;
end loop L2;
In this example, the exit statement causes the execution to jump out of loop L2 when SUM becomes
greater than 100. If the exit statement were not present, the loop would execute indefinitely.
Exit Statement
The EXIT statement is a sequential statement that can be used only inside a loop. It is used to jump out
of the loop conditionally or unconditionally and terminate the loop. The LOOP label in the EXIT
statement identifies the particular loop to be exited
exit [ loop-label] [ when condition ]:
If no loop label is specified, the innermost loop is exited
Example:
SUM := 1; J := 0;
L3: loop
J:=J+21;
SUM := SUM* 10;
if (SUM > 100) then
exit L3;
end if;
end loop L3;
Next Statement
The next statement is used to complete execution of one of the iterations of an enclosing loop statement.
The completion is conditional if the statement includes a condition.
16
Its syntax is
next [ loop-label] [ when condition ];
Example:
for J in 10 downto 5 loop
if (SUM < TOTAL_SUM) then
SUM := SUM +2;
elsif (SUM = TOTAL_SUM) then
next;
else
null;
end if;
The difference between the Next statement and exit statement is that- the exit statement "exits" the loop
entirely, while the next statement skips to the "next" loop iteration
Assertion Statement
Assertion statement checks whether a specified condition is true and reports an error if it is not.
The syntax is
assert boolean-expression
[ report string-expression ]
[ severity expression ]:
The assertion statement has three optional fields and usually all three are used.
The condition specified in an assertion statement must evaluate to a Boolean value
(true or false). If it is false, it is said that an assertion violation occurred.
The expression specified in the report clause must be of predefined type STRING and
is a message to be reported when assertion violation occurred.
If the severity clause is present, it must specify an expression of predefined type
SEVERITY_LEVEL, which determines the severity level of the assertion violation.
Example:
Functional errors, timing errors can be reported via assert:
entity RSFF is
port( R,S, rst, CLK: in std_logic;
Q,Qbar: out std_logic);
End RSFF;
Architecture behavioral of RSFF is
begin
process (CLK , R,S)
begin
if (CLK‘ event and clock = ‘1’) then
17
Report statement:
A report statement can be used to display a message. It is similar to an assertion statement but without
the assertion check. The syntax is
report string expression
[severity expression];
When report statement is executed, it causes the specified string to be printed and the severity level to be
reported to the simulator for appropriate action.
Examples:
1. if CLR = ‘Z’ then
report “signal CLR has a high impedance value”;
end if;
If no pulse rejection limit is specified, the default pulse rejection limit is the inertial delay value itself.
Example:
Consider a non-inverting buffer with an inertial delay of 10 ns.
Ie., Z = reject 4 ns inertial A after 10 ns
A 5 8 10 25 28 30 45 48
Z
20 40
Events on signal A that occur at 5 ns and 8 ns are not stable for the inertial delay duration and hence do
not propagate to the output. Event on A at 10ns remains stable for more than the inertial delay, and
therefore, the value is propagated to the target signal Z after the inertial delay; Z gets the value 1' at 20
ns. Events on signal A at 25ns and 28 ns do not affect the output since they are not stable for the inertial
delay duration. Transition 1' to '0' at time 30 ns on signal A remains stable for at least the inertial delay
duration, and therefore, a '0' is propagated to signal Z with a delay of 10 ns; Z gets the new value at 40
ns. Other events on A do not affect the target signal Z.
Since inertial delay is most commonly found in digital circuits, it is the default delay model. This delay
model is often used to filter out unwanted spikes and transients on signals.
Example:
Consider a non-inverting buffer with a transport delay of 10 ns.
A
5 8 10 25 28 30 45 48
A Z Z
15 18 20 35 38 40 55 58
In this case, spikes would be propagated through instead of being ignored as in the inertial delay case.
19
Each waveform element has a value part, specified by an expression (called the waveform expression in
this text), and a delay part, specified by an after clause that specifies the delay. The delays in the
waveform elements must appear in increasing order. A waveform element is of the form
expression after time-expression
Signal Drivers:
The effective value of a signal, if there is more than one assignment to the same signal
within a process, can be obtained by creating the drivers.
Every signal assignment in a process creates a driver for that signal. The driver of a signal holds its
current value and all its future values as a sequence of one or more transactions, where each transaction
identifies the value to appear on the signal along with the time at which the value is to appear.
Example:
process
begin
...
RESET <= 3 after 5 ns, 21 after 10 ns, 14 after 17 ns;
end process;
When the third signal assignment statement is executed, the new transaction, 35@T+18 ns, causes the
20@T+22 ns transaction to be deleted and the new transaction is appended to the driver. Because the
delay for the new transaction (=18 ns) is less than the delay of the last transaction sitting on the driver
(=22 ns). This effect is caused because transport delay is used. In general, a new transaction will delete
all transactions sitting on a driver that are to occur at or later than the delay of the new transaction.
Therefore, the driver for RX_DATA is changed to
When inertial delays are used, both the signal value being assigned and the delay value
affect the deletion and addition of transactions. If the delay of the new transaction is earlier than
an existing transaction, the latter is deleted and the new one is added at the end of the driver,
regardless of the signal values of the two transactions
On the other hand, if the delay of the new transaction is greater than an already existing
one, the signal values of the two transactions are compared. If they are the same, the new
transaction is simply added at the end of the driver, if not, the existing one is deleted before
adding the new transaction. Deletion occurs for every existing transaction with a signal value
that is different from the new transaction.
Example:
Consider the following process statement.
process
begin
TX_DATA <= 11 after 10 ns;
TX_DATA <= 22 after 20 ns;
TX_DATA <= 33 after 15 ns;
wait; -- Suspends indefinitely.
end process;
The transaction, 11@10 ns, first gets added to the driver. The second transaction, 22@20 ns, causes the
11@10 ns transaction on the driver to be deleted because the signal value, that is, 22, of the new
transaction is different from the value of the transaction on the driver, that is, 11. The state of the driver
at this point is
The execution of the third signal assignment causes the transaction 22@20 ns to be deleted from the
driver, since the delay of the new transaction (=15 ns) is less than the delay of the transaction on the
driver (similar to the transport delay case). The final status of the driver is
Dataflow modeling describes the architecture of the entity under design without describing its components in
terms of flow of data from input towards output. This style is nearest to RTL description of the circuit.
Dataflow modeling is concurrent style of modeling in VHDL, that is, unlike behavioral modeling the order of
statements is not important
In this example, the architecture body contains a single concurrent signal assignment statement. The
interpretation of this statement is that, whenever an event (change of value) occurs on either A or B, the
expression on the right is evaluated and the value is scheduled to appear on signal Z after a delay of 9 ns.
Two signal assignment statements are used to represent the dataflow of the FULL_ADDER entity. Whenever
an event occurs on signals A, B, or CIN, expressions of both the statements are evaluated and the value to
SUM is scheduled to appear after 15 ns while the value to COUT is scheduled to appear after 10 ns. The after
clause models the delay of the logic represented by the expression.
A B C Z
entity FAST_INVERTER is
port (A: in BIT; Z: out BIT);
end FAST_INVERTER;
architecture DELTA_DELAY of FAST_INVERTER is
signal B, C: BIT;
begin
Z <= not C; - signal assignment #1
C <= not B; - signal assignment #2
B <= not A; - signal assignment #3
end DELTA_DELAY;
When an event occurs on signal A, say at 20 ns, the third signal assignment is triggered which causes
signal B to get the inverted value of A at 20ns+1Δ. When time advances to 20ns+1Δ, signal B changes. This
triggers the second signal assignment, causing signal C to get the inverted value of B at 20ns+2Δ. When
simulation time advances to 20ns+2Δ, the first signal assignment is triggered causing Z to get a new value at
time 20 ns+3Δ. Even though the real simulation time stayed at 20 ns, Z was updated with the correct value
through a sequence of delta-delayed events. This sequence of waveforms is shown below
A
Z
20ns 20ns+1 ΔΔ Δ
2
Example 2: RS latch
entity RS_LATCH is
port (R, S; in BIT := '1'; Q: buffer BIT := '1';
QBAR: buffer BIT: = '0');
end RS_LATCH;
architecture DELTA of RS_LATCH is
begin
QBAR <= R nand Q;
Q <= S nand QBAR;
end DELTA;
At start of simulation, both R and S have value'1' and Q and QBAR are at '1' and '0', respectively. When the
signal R changes from '1' to '0' at 5 ns. The following diagrams illustrate the event that occurs as a result of
change in the value of R. This shows that the output gets stabilized after two delta delays. The circuit
stabilizes with the final values of Q & Qbar being ‘0’ and ‘1’ respectively.
S =1
R =1
QBAR
5ns
5ns +1 5ns +2
Multiple Drivers
Each concurrent signal assignment statement creates a driver for the signal being assigned. If the signal has
more than one driver then that signal is said to have multiple drivers.
For e.g.:
entity md is
port (A, B, C: in BIT; Z: out BIT);
A end md;
B architecture df of md is
begin
Z
Z <= A and B after 10 ns;
C
Z <= not C after 5 ns;
End df;
The effective value of Z is determined by using the user defined “Resolution Function”. This considers the
value of both the drivers for Z and determines the effective value. A signal with more than one driver must
have a resolution function associated with it, otherwise, it is an error. Such a signal is called a resolved signal
A resolution function consists of a function that is called whenever one of the drivers for the signals has an
event occurring on it. When the resolution function is executed it returns a single value from all the values of
the drivers. This is the new value of the signal.
3
Example: wired-OR, wired-AND, average value of a signal and so
Example: entity md is
port (A, B, C,D,E: in BIT;
Consider the following circuit.
Z: out BIT);
end md;
architecture df of md is
begin
A Z <= A and B after 10 ns;
B
Z <= not C after 5 ns;
Z <= A or B after 15 ns;
C Z End df;
D Z <= '1' after 2 ns, '0' after 5 ns, '1' after 10 ns;
E Z <= '0' after 4 ns, '1' after 5 ns, '0' after 20 ns;
Z <= '1' after 10 ns, '0' after 20 ns;
In this case, there are three drivers for signal Z. Each driver has a sequence of transactions where each
transaction defines the value to appear on the signal and the time at which it is to appear. The resolution
function resolves the value for the signal Z from the current value of each of its drivers. This is shown
pictorially.
The value of each driver is an input to the resolution function and based on the computation performed
within the resolution function, the value returned by this function becomes the resolved value for the signal.
Driver 2
The resolution function is associated with the signal by specifying the name in the signal declaration. (signal
declaration could wired-or, wired and, average value etc.,) considering the wired-
OR operation for the above example, the correct way if representing it is
entity md is
port (A, B, C,D,E: in BIT;
Z: out wired-OR BIT);
end md;
architecture df of md is
begin
Z <= A and B after 10 ns;
Z <= not C after 5 ns;
Z <= A or B after 15 ns;
Z <= '1' after 2 ns, '0' after 5 ns, '1' after 10 ns;
Z <= '0' after 4 ns, '1' after 5 ns, '0' after 20 ns;
Z <= '1' after 10 ns, '0' after 20 ns;
4
End df;
In the example of architecture md, the resolution function is invoked at time 2 ns with driver values
'1', '0', and '0' (drivers 2 and 3 have '0' because that is assumed to be the initial value of Z). The function,
WIRED_OR, is performed and the resulting resolved value of '1' is assigned to Z at 2 ns. Signal Z is
scheduled to have another event at 4 ns, at which time the driver values, '1', '0', and '0', are passed to the
resolution function which returns the value of '1' for signal Z. At time 5 ns, the driver values, '0', '1', and '0'
are passed to the resolution function which returns the value '1'. At 10ns, the driver values, '1', '1', and '1' are
passed to the resolution function. Finally at time 20 ns, the driver values, '1', '0', and '0' are passed to the
resolution function to determine the effective value for signal Z, which is 1'.
There are two forms of the concurrent signal assignment statement: the conditional signal assignment
statement and the selected signal assignment statement.
That is, whenever an event occurs on a signal used either in any of the waveform expressions or in any of
the conditions, the conditional signal assignment statement is executed by evaluating the conditions one at a
time.
Example: Consider 4 x 1 mux.
Ctrl lines Inputs
S0 S1 I3 I2 I1 I0
0 0 0 0 0 1
0 1 0 0 1 0
1 0 0 1 0 0
1 1 1 0 0 0
5
DATAFLOW MODELING BEHAVIORAL MODELING
entity MUX is
entity MUX is port (I: in BIT_vector (3 down to 0);
port (I0,I1,I2,I3,S0,S1: in BIT; S: in BIT_vector (1 down to 0)
Y: out BIT); Y: out BIT);
end md; end MUX;
architecture behavioral of MUX is
architecture df of MUX is begin
begin process
begin
Y <= I0 after 10ns when S0 = '0' and S1 = '0' else if S0 = '0' and S1 = '0' then
I1 after 10ns when S0 = '1' and S1 = '0' else Y<= I0 after 10 ns;
Elsif S0='1'and S1='0' then
I2 after 10ns when S0 = '0' and S1 = '1' else
Y<= I1 after 10ns;
I3 after 10 ns;
Elsif S0='0' and S1 = '1' then
Y<= I2 after 10 ns;
else Y<= I3 after 10 ns;
NOTE: Refer manual for selected signal assignment for
end if;
MUX
wait on I0, I1, I2, I3, S0, S1;
end process;
end behavioral;
In the example of data flow modeling, the statement is executed any time an event occurs on signals I0, I1,
I2, I3, S0, or S1. The first condition (S0='0' and S1='0') is checked; if false, the second condition (S0='1' and
S1='0') is checked; if false, the third condition is checked; and so on. Assuming S0='0' and S1='1', then the
value of IN2 is scheduled to be assigned to signal Y after 10 ns.
Whenever an event occurs on a signal in the select expression or on any signal used in any of the waveform
expressions, the statement is executed. The choices are not evaluated in sequence. All possible values of the
select expression must be covered by the choices that are specified not more than once. Values not covered
explicitly may be covered by an "others" choice.
Example:
Consider a 4 x 2 Encoder:
Inputs Outputs
I3 I2 I1 I0 Y1 Y0
0 0 0 1 0 0
Encoder 0 0 1 0 0 1
0 1 0 0 1 0
1 0 0 0 1 1 6
entity encoder is
port (I: in std_logic_vector(3 down to 0);
Conditional signal assignment
Z: out std_logic_vector(1down to 0);
End encoder; Y <= “00” when I “0001” else ,
Architecture df of encoder is
Begin “01” when I “0010” else,
With I select
Y<= “00” when “0001”, “10” when I “0100” else,
“01” when “0010”,
“10” when “0100”, “11” when I “1000” else,
“11” when “1000”,
“00” when others;
“00” when others;
End df;
Block Statement:
A block statement is a concurrent statement. There are two types of block statement –
1. Simple block
2. Guarded block
Simple BLOCK
The BLOCK statement, in its simple form, represents only a way of locally partitioning the code. It
allows a set of concurrent statements to be clustered into a BLOCK, with the purpose of turning the overall
code more readable and more Manageable.
Its syntax is shown below.
label: BLOCK
[Declarative part]
BEGIN
(concurrent statements)
END BLOCK label;
Guarded BLOCK
A guarded BLOCK is a special kind of BLOCK, which includes an additional expression, called
guard expression. A guarded statement in a guarded BLOCK is executed only when the guard expression is
TRUE.
Guarded BLOCK:
label: BLOCK (guard expression)
[declarative part]
BEGIN
(concurrent guarded and unguarded statements)
END BLOCK label;
Example: D- flip-flop. with a Guarded BLOCK
entity D_FLIP_FLOP is
port (D, CLK: in BIT; Q, QBAR: out BIT);
end D_FLIP_PLOP;
architecture DFF of D_FLIP_FLOP is
begin
7
b1: BLOCK (clk='1')
begin
q <= GUARDED D;
end block b1;
end DFF;
entity encoder is
port (I: in std_logic_vector(3 down to 0);
Z: out std_logic_vector(1down to 0);
End encoder;
Value of a signal
A signal gets its value from its drivers. Every concurrent signal assignment statements create a driver for the
target signal. All signal assignments in a process that assign to a particular signal create one driver for the
signals.
8
In a given VHDL description, if a signal has more than one driver, the resolution function is necessary. This
function is associated with the current value of all drivers for a signal and the return value of the function
becomes the effective value of the signal.
9
Structural Modeling
Structural modeling is the simplest style of modeling. It describes the circuit design in terms of
components. In this style of modeling, the top-level entity is partitioned into smaller lower level entities,
each of which is known as the component.
Every component in VHDL is specified with its component declaration and mapped to top-level entity
using component instantiation.
Component Declaration
Any entity before using the components is required to declare the components in the architecture –
declarative section. The syntax of a simple form of component declaration is
component component-name
port ( list-of-interface-ports ) ;
end component;
Example 1:
component NAND2
port (A, B: in MVL; Z: out MVL);
end component;
Example 2:
component MP
port (CK, RESET, RD, WR: in BIT;
DATA_BUS: inout INTEGER range 0 to 255;
ADDR_BUS: in BIT_VECTOR(15 downto 0));
end component;
Example 3:
component AND2
port (X, Y: in BIT: Z: out BIT):
end component;
Example 4:
component DFF
port (D, CLOCK: in BIT; Q, QBAR: out BIT);
end component;
Example 5
component NOR2
port (A, B: in BIT; Z: out BIT);
end component;
Component Instantiation:
Component instantiation is creating an instance of the specific component by associating its local ports
to signals of the top-level entity. It puts the components used in the executable form for the top-level
1
entity. PORT MAP statement is used for component instantiation. A format of a component
instantiation statement is
Example1:
-- Component declaration:
U
component nandg
port (U, V in BIT; W: out BIT);
end component;
-- Component instantiation:
G1 : nandg port map (A, B, S1);
G2 : nandg port map (C, D, S2);
G1 : nandg port map (S1,S2, S3);
G1, G2 & G3 are the component label for the current instantiation of the nandg component. The
ordering of the actual is not important. Here S1 is actual and Y is the formal.
If a port in a component instantiation is not connected to the any signal, the keyword OPEN can be used
to specify that the port is not connected.
Example 2:
2
G1 : JKFF port map (1,1,CLK,QA,OPEN);
G2 : JKFF port map (1,1,QA,QB,OPEN);
formal => actual1, formal2 => actual2, ..., formaaln => actualn
Example: MR
RDY
Q S1
D
Clk S22
QBar
DIN CTRL A
Component norg
Port (DA,DB: IN BIT;
DZ : OUTBIT);
End component;
Component andg
Port (x,y : IN BIT;
z : OUTBIT);
End component;
Component DFF
Port (D,clk : IN BIT;
Q, Qbar : OUTBIT);
End component;
G1 : DFF portmap (D =>A, clk=>clk, Q=> S1, QBAR => S2);
G2 : norg port map (DA => MR, DB => S1, DZ => RDY);
G3 : Andg port map (x => S2, y => Din , Z => CTRLA);
In this case considering G2, MR is an actual which is declared in the entity port list is associated with the
first port (port DA, a formal) of the norg gate, signal ready is associated with the third port (DZ) and S1 is
associated with the second port (DB of norg gate. )
If an actual is a port of mode in, it may not be associated with mode of out or inout.
If an actual is a port of mode out , it may not be associated with mode of in or inout
If an actual is a port of mode inout, it may be associated with mode of in, out or inout
In named association, the ordering of the associations is not important since the mapping between the
actuals and formals are explicitly specified.
RDY
Q S1
A D
DIN CTRL A
entity GATING is
port (A, CK, MR, DIN: in BIT; RDY, CTRLA: out BIT);
end GATING;
architecture STRUCTURE_VIEW of GATING is
component AND2
port (X, Y: in BIT; Z: out BIT);
end component;
component DFF
port (D, CLOCK: in BIT; Q, QBAR: out BIT);
end component;
component NOR2
port (A, B: in BIT; Z: out BIT);
end component;
signal SI, S2: BIT;
begin
D1: DFF port map (A, CK, SI, S2);
A1: AND2 port map (S2, DIN, CTRLA);
N1: NOR2 port map (SI, MR, RDY);
end STRUCTURE_VIEW;
Three components, AND2, DFF, and NOR2, are declared. These components are instantiated in the
architecture body via three component instantiation statements, and the instantiated components are
connected to each other via signals SI and S2. The component instantiation statements are concurrent
statements, and therefore, their order of appearance in the architecture body is not important. A
component can, in general, be instantiated any number of times. However, each instantiation must have a
unique component label; as an example, A1 is the component label for the AND2 component
instantiation.
Other Examples
Ex 1: The structural model for a 9-bit parity generator circuit is as shown below.
4
entity PARITY_9_BIT is
port (D: in BIT_VECTOR(8 downto 0); EVEN: out BIT;
ODD: buffer BIT);
end PARITY_9_BIT;
architecture structural of PARITY_9_BIT is
component XOR2
port (A, B: in BIT; Z: out BIT);
end component;
component INV2
port (A: in BIT; Z: out BIT);
end component;
signal E0, E1, E2, E3, F0, F1, H0: BIT;
begin
XE0: XOR2 port map (D(0), D(1), E0);
XE1: XOR2 port map (D(2), D(3), E1);
XE2: XOR2 port map (D(4), D(5), E2);
XE3: XOR2 port map (D(6), D(7), E3);
XF0: XOR2 port map (E0, E1, F0);
XF1: XOR2 port map (E2, E3, F1);
XH0: XOR2 port map (F0, F1, H0);
XODD: XOR2 port map (H0, D(8), ODD);
XEVEN: INV2 port map (ODD, EVEN);
end structural;
In this example, port ODD is of mode buffer since the value of this port is being read as well as written to
inside the architecture.
Ex 2: The structural model for decade counter using J-K flip-flops is as shown
below.
Cout
S1
S2
J Q J Q J Q J Q
CK CK CK CK
K NQ K NQ K NQ K NQ
5
Z (0) Z (2) Z (3)
entity decade is
port (COUNT: in BIT; Z: buffer BIT_VECTOR(0 to 3));
end decade;
architecture structural of decade is
component JK_FF
port (J, K, CK: in BIT; Q, NQ: buffer BIT);
end component;
component andg
port (A, B: in BIT; C: out BIT);
end component;
signal S1, S2: BIT;
signal S_HIGH: BIT := '1';
begin
A1: AND_GATE port map (Z(2), Z(1), S1);
G1: JK_FF port map (1, 1, COUNT, Z(0), open);
G2: JK_FF port map (S2, 1, Z(0), Z(1), open);
G3: JK_FF port map (1, 1, Z(1), Z(2), open);
G4: JK_FF port map (S1, 1, Z(0), Z(3), S2);
end structural;
This example illustrates the point that only signals can be used as actuals inside a port map. If a
constant, say 'V, is to be set for one of the ports, as in instance JKI, it is necessary to define a signal, say
S_HIGH, that contains this value and then use this signal as an actual for this port. It would be an error to
use the constant value directly as an actual in a port map.
Ex 3: Consider the 3-bit up-down counter circuit shown below and its structural model
J Q J Q J Q
CK CK CK
K NQ K NQ K NQ
entity UP_DOWN is
port (CLK, CNT_UP, CNT_DOWN: in BIT;
A, B, C: buffer BIT);
end UP_DOWN;
architecture structural of UP_DOWN is
component JK_FF
port (J, K, CK: in BIT; 0, ON: buffer BIT);
end component;
component AND2
6
port (A, B: in BIT; C: out BIT);
end component;
component OR2
port (A, B: in BIT; C: out BIT);
end component;
signal SI, S2, S3, S4, S5, S6, S7, S8: BIT;
signal ONE: BIT := '1';
begin
JK1: JK_FF port map (1, 1, CLK, A, S1);
A1: AND2 port map (CNT_UP, A, S2);
A2: AND2 port map (S1, CNT_DOWN, S3);
O1: OR2 port map (S2, S3, S4);
JK2: JK_FF port map (1, 1, S4, B, S5);
A3; AND2 port map (B, CNT_UP, S7);
A4: AND2 port map (S5, CNT_DOWN, S6);
O2: OR2 port map (S7, S6, S8);
JK3: JK_FF port map (1, 1, S8, C, open):
end structural;
entity DRIVING_SIGNAL is
port (A, B, C, D: in BIT; Z: out BIT);
end DRIVING_SIGNAL;
{-- PULL_UP is the name of a function defined in package RF_PACK that
-- has been compiled into the working library}
use WORK.RF_PACK.PULL_UP;
component XORgate
port (x,y : in STD_LOGIC; z : out STD_LOGIC);
end component;
component ANDgate
port (x,y : in STD_LOGIC; z : out STD_LOGIC);
end component;
begin
G1 : XORgate port map (a,b,s);
G2 : ANDgate port map (a,b,c);
end Structural;
component NOTgate
port (x : in STD_LOGIC; y : out STD_LOGIC);
end component;
component ANDgate
port (x,y : in STD_LOGIC; z : out STD_LOGIC);
end component;
signal x1 : STD_LOGIC;
begin
G1 : XORgate port map (a,b,d);
G2 : NOTgate port map (a,x1);
G3 : ANDgate port map (x1,b,ba);
end Structural;
entity FS_S is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
c : in STD_LOGIC;
d : out STD_LOGIC;
ba : out STD_LOGIC);
end FS_S;
component ORgate
port (x,y :in STD_LOGIC; z : out STD_LOGIC);
end component;
begin
end Structural;
10