05_VHDL (3)
05_VHDL (3)
10636321
Dr. Ashraf Armoush
VHDL
• Design Specification:
– unambiguous definition of components
and interfaces in a large design
• Design Simulation:
– verify system/subsystem/chip performance
prior to design Implementation.
• Design Synthesis:
– automated generation of a hardware
design
Design HW as if it is SW
Software Design Hardware Design
(Microcontroller) (CPLD/FPGA)
Specification Specification
Implementation (e.g.: C or Implementation in HDL
assembly) Structural description
Behavioral description
Compilation to machine code Automatic transformation in
Gate Level Description (Synthesis)
Load code in program memory Load configuration in target
of target
Functionality is realized by Functionality is implemented in
execution of code by CPU (CPU hardware
can use certain peripherals as
timers )
© 2023 Dr. Ashraf Armoush , An-Najah National University 8
HDLs (Examples)
• Verilog
– Invented in 1984
– Syntax similar to C
• VHDL
– Was originally developed for the US Department of Defense (DoD)
– Syntax similar to ADA
– VHDL is more complex than Verilog.
• System C
– C++ library for hardware specific constructs
– Good for Simulation, but synthesis still problematic.
VHDL
Synthesizable Allows automatic
subset synthesis to gate
level description
• Not all constructs in VHDL are suitable for synthesis (e.g. wait for 10 ns).
• This VHDL subset is not standardized. (why?)
VHDL – History
• 1981: The development of VHDL was initiated by US DoD in order to
document the behavior of ASICs that were included in the supplied
equipments.
• 1983: a team of Intermetrics, IBM and Texas Instruments were awarded a
contract to develop VHDL
• 1985: the official release of the final version of the language was released.
• 1987: (VHDL-87) the first IEEE standardized version was adopted (IEEE -
1076)
• 1993: (VHDL 93) is the first IEEE revision. It is still the most widely
supported version of VHDL.
• 2000: (VHDL 2000): added the idea of protected types (similar to the
concept of class in C++)
• 2002: (VHDL-2002) is a minor revision of VHDL 2000 Edition
• 2008: (VHDL-2008) addressed more than 90 issues discovered during the
trial period for the previous version)
• 2019: (VHDL-2019) The VHDL standard IEEE 1076-2019 was approved
© 2023 Dr. Ashraf Armoush , An-Najah National University 12
VHDL Constructs
Entity: specifies inputs and outputs of each module
Architecture: specifies the structure or the behavior of a module
Process: can be used for description of the behavior
Signal: can be understood as physical connections
Variable: can be understood as memory cell
VHDL language constructs are divided into three categories by their level
of abstraction:
Behavioral: (functional aspects)
Dataflow: (the data flow from input to output)
Structural: (a model where the components of a design are
interconnected)
[ port ( port_declarations ) ;]
[] : optional
end [ entity_name ] ;
Data Type
• Determines the values that an object (e.g. constant, signal, variable,
function, and parameter) can have.
• BIT , BIT_VECTOR, and INTEGER are the most common used types.
• BIT: can have two values '1' and '0'
Ex: X : in bit;
• BIT_VECTOR: is a one dimensional array
ex: D : in bit_vector( 3 downto 0)
A
Y
B
entity Majority_Vote is
Entity
Declaration
Entity
name
port( A, B, C :in bit;
Y :out bit);
end Majority_Vote;
Architecture name
Notes
Statements in VHDL are terminated by semicolons.
This operator ( <= ) is called "assignment operator".
Comments in VHDL start with two adjacent hyphens (‘--’)
The Boolean operators (AND, OR, NOT, NAND, NOR, XOR, and
XNOR) have an equal order of precedence.
The VHDL statements are case insensitive.
The VHDL file name must be the same as the top-level entity name.
A valid name in VHDL consists of a letter followed by any number of
letters or numbers, without spaces. An underscore can be used
within a name, but can not begin or end the name.
You can define a literal constant to be used within an entity with the
generic declaration, which is placed before the port declaration
within the entity block
generic (name : type := value);
© 2023 Dr. Ashraf Armoush , An-Najah National University 22
Signals Assignment (<=)
• A : out bit;
A <= '0';
A <= '1';
Ex2:
entity ALU32 is
port( A, B: in bit_vector (31 downto 0);
C : out bit_vector (31 downto 0);
Op: in bit_vector ( 5 downto 0);
N, Z: out bit);
end ALU32;
LIBRARY LIBRARY_NAME;
USE LIBRARY_NAME.PACKAGE_NAME.ALL;
library IEEE;
use IEEE.std_logic_1164.ALL ; -- Defines the standard data types
entity decoder is
Port ( A : in STD_LOGIC_VECTOR (1 downto 0);
Y : out STD_LOGIC_VECTOR (3 downto 0));
end decoder;
Signals
• A signal is like an internal wire connecting two or more points
inside an architecture body.
• It is declared before the BEGIN statement of an architecture
body
signal signal_name: signal_type [:=default_value];
Ex:
signal flag : STD_LOGIC := '0' ;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity mux is
Port ( I : in std_logic_vector (3 downto 0);
S : in std_logic_vector (1 downto 0);
Y : out std_logic);
end mux;
Array Types
• An array is an object that is a collection of elements
of the same type.
• VHDL supports N-dimensional arrays, but Foundation
Express supports only one-dimensional arrays.
Ex:
component HALFADDER
port ( a, b : in std_logic; • Component
A declaredDeclaration
component can
sum, carry : out std_logic);
end component;
come from:
– The same VHDL source file
Begin – A different VHDL source file
-
-
-
end Fulladder_Arch;
© 2023 Dr. Ashraf Armoush , An-Najah National University 51
end Fulladder_Arch;
MODULE1: HALFADDER
port map ( a , b , W_SUM, W_CARRY1 ); The signal position must be
in the same order as the
declared component’s ports
MODULE2: HALFADDER
port map ( W_SUM, c , sum , W_CARRY2 );
end Fulladder_Arch;
FA FA FA FA
HA HA HA HA HA HA HA HA
Ex: (cont.)
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity FOURBITADDER is
port ( a,b : in std_logic_vector (3 downto 0);
Cin : in std_logic;
sum : out std_logic_vector (3 downto 0);
Cout , V : out std_logic);
end FOURBITADDER;
FA2: FULLADDER
port map (a(2), b(2), c(2), sum(2), c(3));
FA3: FULLADDER
port map (a(3), b(3), c(3), sum(3), c(4));
end FourBitAdder_Arch;
Generate Statement
• Generate: is a VHDL construct that is used to create
repetitive portions of hardware .
label:
for identifier in range generate
{ concurrent_statement }
Process (cont.)
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity D_latch is
Port ( data_in : in std_logic ;
enable : in std_logic ;
data_out : out std_logic);
end D_latch;
Sensitivity list
architecture Behav of D_latch is
begin
D_PROCESS: process ( data_in , enable)
begin
if ( enable = '1' ) then
data_out <= data_in;
end if ;
end process D_PROCESS;
end Behav;
Sequential Statements
Executed according to the order in which
they appear
entity DFF is
Port ( D, CLK, CLEAR : in std_logic ;
Q : out std_logic
);
end DFF;
when 1 to 5 =>
Z <= C ;
Wait Statement
A wait statement suspends (halts) the process execution.
Different types of wait statements:
1. wait for a specific time
wait for SPECIFIC_TIME;
2. wait for a signal event
wait on SIGNAL_LIST;
3. wait for a true condition (requires an event)
wait until CONDITION;
4. indefinite (process is never reactivated)
wait ;
• IEEE VHDL specifies that a process containing a wait statement
must not have a sensitivity list.
• The Xilinx Foundation Express has implemented only the third form
of the wait statement (wait until).
entity DFF is
Port ( D, CLK : in std_logic ;
Q, Qbar : out std_logic
);
end DFF;
{ sequential_statement }
{ sequential_statement }
{ sequential_statement }
• The when keyword is optional clause that executes its next statement
when its condition evaluates to TRUE.
• A next statement with no label terminates the current iteration of the
innermost enclosing loop.
• The when keyword is optional and will execute the exit statement when
its condition evaluates to TRUE.
• An exit statement with no label terminates the innermost enclosing loop.
© 2023 Dr. Ashraf Armoush , An-Najah National University 79
null Statements
• The null statement states that no action will occur.
• It is often used in case statements because all choices must be
covered
process (CONTROL, A)
begin
Z <= A;
case CONTROL is
when 0 | 7 => -- If 0 or 7, then invert A
Z <= not A;
when others =>
null; -- If not 0 or 7, then do nothing
end case;
end process;
Ex:
architecture Behav_XYZ of XYZ is
signal A, B, C : integer range 0 to 7;
signal Y, Z : integer range 0 to 7;
Begin
-
-
process (A,B,C)
variable M, N : integer range 0 to 7;
begin
M := A;
N := B;
Z <= M + N;
M := C;
Y <= M + N;
end process;
-
-
end Behav_XYZ;
Use of Variables
• Variables are especially suited for the implementation of
algorithms
1. signal to variable assignment
2. execution of algorithm
3. variable to signal assignment
(Use functions when you do not need to update the parameters, and you want a
single return value.)
• Subprograms are called by name from anywhere within a VHDL
architecture or a package body.
Subprogram Calls
• When the subprogram is called, each formal parameter receives a
value.
• Each actual parameter’s value (of an appropriate type) can come
from an expression, a variable, or a signal.
• Actual parameters that use mode out and mode inout cannot be
constants or expressions.
• Procedure Calls
P (X, Y);
– In the synthesized circuit, the procedure’s actual inputs and outputs
are wired to the procedure’s internal logic.
• Function Calls
---------------
---------------
end process
© 2023 Dr. Ashraf Armoush , An-Najah National University 93
ASM
T0
0
S
1
T1
entity ASM is
port(S, X, CLOCK : in BIT;
1 0 y : out BIT);
X
end ASM;
y <= 1 y <= 0
T2 T3
ASM (cont.)
You can divide the previous process into two processes:
process(CURRENT_STATE , X, S)
begin
case CURRENT_STATE is
when S0 =>
NEXT_STATE <= - - - First Process
when S1 => (combinational process)
---
when S2|S3 =>
---
end case;
end process;
end;
© 2023 Dr. Ashraf Armoush , An-Najah National University 105
Operators
• Logical Operators
• Relational Operators
• Adding Operators
• Unary (Signed) Operators
• Multiplying Operators
• Miscellaneous
Logical Operators
• Priority
– not (top priority)
– and, or, nand, nor, xor, xnor (equal
priority ) entity LOGIC_OP is
port (A, B, C, D : in bit;
Z1: out bit;
• Predefined for EQUAL : out boolean);
– bit, bit_vector end LOGIC_OP;
– boolean
– STD_LOGIC, STD_LOGIC_VECTOR architecture EXAMPLE of LOGIC_OP is
begin
end EXAMPLE;
• Logical operations with arrays require
operands of the same type and the same
length
begin
process (A, B)
begin
if (A = B) then
A_EQ_B1 <= '1';
else
A_EQ_B1 <= '0';
end if;
end process;
A_EQ_B2 <= A = B; -- wrong
end EXAMPLE
Shift Operators
• Defined for BIT_VECTOR , BOOLEAN_VECTOR and STD_LOGIC_VECTOR
signal A_BUS, B_BUS, Z_BUS : std_logic_vector (3 downto 0);
signal A, B, C : integer;
signal RESULT : integer;
RESULT <= - A + B * C;