Iv Unit Data Flow, Behavioral Modeling: EC258 Digital System Design Using VHDL
Iv Unit Data Flow, Behavioral Modeling: EC258 Digital System Design Using VHDL
Having Finished Basic Foundations in VHDL, we will go a step further and learn the
main design styles in VHDL. VHDL Supports two main design styles. Both the styles have their
capabilities and will help a designer to describe his own application. The VHDL Code can be
Concurrent (Parallel) or Sequential.
By Definition Combinational Logic is that in which, the output of the circuit solely
depends on the current inputs (Inputs given at the input side). It is clear from the principle that the
system needs no memory and it can be implemented by using conventional Logic gates. In
contrast Sequential Logic is defined as the logic in which the outputs will not only depend on the
present inputs but also past inputs stored in the memory. From this principle we understand that
sequential logic system needs a memory to be used along with conventional logic gates.
Therefore storage elements are required.
VHDL Code is inherently Concurrent (Parallel). Only statements place inside Process,
Functions or Procedures are sequential, though within these blocks execution is sequential, the
block as a whole is concurrent, with any other external statements. A concurrent code is also
called Dataflow Code. A Sequential code is also called Behavioral Code.
A dataflow model specifies the functionality of the entity without explicitly specifying its
structure. This functionality shows the flow of information through the entity, which is expressed
primarily using concurrent signal assignment statements and block statements.
These statements are used in Dataflow Modeling. There are two types of Concurrent
signal Assignment Statements. They are:
Syntax:
For Example: Let us consider an Multiplexer in Fig4 .3 and analyze how to write in conditional
signal Assignment Statement
In the above Solution, Sel was given as std_logic, but it can also be configured as Integer. The
following Example will give clear picture of this change
Syntax:
For Example: Let us consider a half adder to illustrate Selected Signal Assignment Statements
Library IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
Entity halfadder is
1. Operators.
2. The When (When/Else or With/Select/When)
3. The Generate Statement *
4. The Block Statement.*
This is the most basic way of creating concurrent code. Operators (AND, OR, +, -, *, sll, sra,
etc…) can be used to implement any type of Combinational circuit.
For Example: Let us consider Multiplexer in Fig 4.3and understand this Concept
4.4.1 Process
Process is a sequential section of VHDL Code. It is characterized by the presence of if, if else,
Wait, Case, or Loop and by a sensitivity List. A Process must be installed in main code and is
executed every time a signal in sensitivity list changes. Its syntax is given below
For Example: Let us consider half adder to illustrate Behavioral code for Combinational Ckts
Library IEEE;
USE IEEE.STD_LOGIC_1164.ALL:
Entitiy halfadd is
End halfadd;
Begin
Process (a,b)
{Variable declarations} {Optional}
For Example: Let us take D Flip-flop to Behavioral code for Sequential Circuits
Library IEEE;
USE IEEE.STD_LOGIC_1164.ALL:
Entity dff is
End dff;
Begin
Process (clk)
{Variable declarations} {Optional}
Begin
<Sequential Code>
End Process;
End;
4.4.2 If Statement
If <Condition> then
<Sequence of Statements>;
End if;
Entity nand1 is
End nand1;
If <Condition> then
<Sequence of statements>;
Elsif
<Sequence of statements>;
Else
<Sequence of statements>;
End if;
Entity counter1 is
End counter1;
If Rst=’0’ then
Count<=”000”;
Case is another fragment of sequential code along with If, Wait, Loop etc…
Case <Expression/Identifier> is
When <Choice/Value> => Sequence of statements;
When <Choice/Value> => Sequence of statements;
When <Choice/Value> => Sequence of statements;
…………..
………….
When others => <Sequence of Statements>;
End case
Entity multiplexer is
End multiplexer;
Case Sel is
When “00” => Z <= in1(0);
When “01” => Z <= in1(1);
When “10” => Z <= in1(2);
When “11” => Z <= in1(3);
End case;
End Process;
End;
The operation of Wait is sometimes is similar to If. However more that one form of wait
is available
Begin
If a > b then
Q<=’1’;
Else
Q<=’0’;
End if;
Wait on a,b;
End if;
End process;
As the name says, Loop is useful when a piece of code must be instantiated several times.
Like If, Wait and case. Loop is intended exclusively for Sequential Code. So it too can only be
used inside a process, Function or procedure. There are several ways of using Loop as shown
below.
4.4.6.1 For/Loop:
For Example
4.4.6.3 Exit
For Example
4.4.6.4 Next
For Example
4.5 SUBPROGRAM
4.5.1 Function
Functions are used to describe frequently used sequential algorithms that return a single
value. This value is returned to the calling program using a return statement. Some of their
common uses are as resolution functions, and as type conversion functions.
A Package using Function will have three constructs in the the code. They are described in
following Syntax:
1. Package Declaration:
Library IEEE;
USE IEEE.STD_LOGIC_1164.ALL:
Library Work;
Package <Package_Name> is
End <Package_Name>;
2. Package Body
End <Package_Name>;
3. Entity / Architecture
Library IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE Work.<Package_Name>.all;
Entity <Entity_Name> is
Port(Sensitivity List); {Names of this Sensitivity List should differ the Package sensitivity Names
and should specify all the functions sensitivity List Names without fail}
End <Entity_Name>;
Begin
Process (Sensitivity List / Clock)
Begin
<Sequence of Statements>;
Function_Name (Call Package Sensitivity List);
End process;
End;
Library IEEE;
Use IEEE.STD_LOGIC_1164.ALL;
Use IEEE.STD_LOGIC_ARITH.ALL;
Use IEEE.STD_LOGIC_UNSIGNED.ALL;
Library Work;
------------------------------------------------------------------------------------------------------------
---------
Package Declaration
Package mux_f is
End mux_f;
------------------------------------------------------------------------------------------------------------
---------
Package Body
Package body mux_f is
Return std_logic is
Begin
if sel="00" then
Return a;
Elsif sel="01" then
Return b;
Elsif sel="10" then
Return c;
Elsif sel="11" then
Return d;
End if;
End con;
End mux_f;
------------------------------------------------------------------------------------------------------------
---------
Entity / Architecture
Library IEEE;
Use IEEE.STD_LOGIC_1164.ALL;
Entity mux2 is
Port (p, q, r, s: in std_logic;
t: in std_logic_vector;
z: out std_logic);
End mux2;
4.5.2 Procedure
1. Package Declaration
Library IEEE;
USE IEEE.STD_LOGIC_1164.ALL:
Library Work;
Package <Package_Name> is
End <Package_Name>;
2. Package Body
3. Entity / Architecture
Library IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE Work.<Package_Name>.all;
Entity <Entity_Name> is
Port (Sensitivity List); {Names of this Sensitivity List should differ the Package sensitivity
Names and should specify all the functions sensitivity List Names without fail}
End <Entity_Name>;
Begin
Process (Sensitivity List / Clock)
Begin
<Sequence of Statements>;
Procedure_Name (Call Package Sensitivity List);
End process;
End;
For Example: Let us Consider an ALU and illustrate this Procedure Call
Library IEEE;
Use IEEE.STD_LOGIC_1164.ALL;
Use IEEE.STD_LOGIC_ARITH.ALL;
Use IEEE.STD_LOGIC_UNSIGNED.ALL;
Library Work;
------------------------------------------------------------------------------------------------------------
Package Declaration
Package Alu_p is
End mux_f;
------------------------------------------------------------------------------------------------------------
Package Body
Package body mux_f is
Return std_logic is
Begin
if sel="00" then
Return a;
Elsif sel="01" then
Return b;
Elsif sel="10" then
Return c;
Elsif sel="11" then
Return d;
End if;
End con;
End mux_f;
------------------------------------------------------------------------------------------------------------
Entity / Architecture
Library IEEE;
Use IEEE.STD_LOGIC_1164.ALL;
Use IEEE.STD_LOGIC_ARITH.ALL;
Use IEEE.STD_LOGIC_UNSIGNED.ALL;
Use WORK.mux_f.ALL;
Entity mux2 is
Port (p, q, r, s: in std_logic;
t: in std_logic_vector;
z: out std_logic);
End mux2;