0 VHDL Basic
0 VHDL Basic
Overview
Digital
Component
VHDL structure
Library
Definitions, constants
Entity
Interface
Architecture
Implementation, function
Libraries
Library ieee;
Use ieee.std_logic_1164.all;
Use ieee.std_logic_arith.all;
Use ieee.std_logic_signed.all;
Use ieee.std_logic_unsigned.all;
VHDL - Library
Include library
library IEEE;
Define the library package used
use IEEE.STD_LOGIC_1164.all;
Define the library file used
For example, STD_LOGIC_1164 defines ‘1’ as logic
high and ‘0’ as logic low
output <= ‘1’; --Assign logic high to output
VHDL - Entity
Interface for communication
among different modules / Entity
components name
Input 2 Output 2
…... …...
Input n Output n
Entity test is
A
Port( A,B,C,D: in std_logic;
E: out std_logic);
B E
End test; Digital
C Component
D
Architecture
Define functionality of the
component
A Component
X <= A AND B; B X E
Y <= C AND D;
E <= X OR Y;
C Y
D
Signal
All internal variables
B X E Signal
C Y
D
Final code
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY TEST IS
PORT (A,B,C,D : IN STD_LOGIC;
E : OUT STD_LOGIC);
END TEST;
BEGIN
X <= A AND B;
Y <= C AND D;
E <= X OR Y;
END BEHAVIOR;
VHDL features
Case insensitive
inputa, INPUTA and InputA are refer to the same variable
Comments
‘--’ until end of line
If you want to comment multiple lines, ‘--’ need to be put at the
beginning of every single line
Statements are terminated by ‘;’
Signal assignment:
‘<=’
Variable assignment:
‘:=’
User defined names:
letters, numbers, underscores (‘_’)
start with a letter
Different ways to describe a
digital system in VHDL
WARNING <= (not DOOR and IGNITION) or (not SBELT and IGNITION)
Structural Description
architecture structural of BUZZER is
-- Declarations
component AND2
port (in1, in2: in std_logic;
out1: out std_logic);
end component;
component OR2
port (in1, in2: in std_logic;
out1: out std_logic);
end component;
component NOT1
port (in1: in std_logic;
out1: out std_logic);
end component;
-- declaration of signals used to interconnect gates
signal DOOR_NOT, SBELT_NOT, B1, B2: std_logic;
begin
-- Component instantiations statements
U0: NOT1 port map (DOOR, DOOR_NOT);
U1: NOT1 port map (SBELT, SBELT_NOT);
U2: AND2 port map (IGNITION, DOOR_NOT, B1);
U3: AND2 port map (IGNITION, SBELT_NOT, B2);
U4: OR2 port map (B1, B2, WARNING);
end structural;
Port Map
Chip1 : Chip_A A
Port map (A,B,C,X,Y); X
B Chip_A
Chip2 : Chip_B Y Chip_B
E
Port map (X,Y,D,E); C
D
Final code
LIBRARY IEEE; COMPONENT Chip_B
USE IEEE.STD_LOGIC_1164.ALL; PORT (Q,R,S : IN STD_LOGIC;
T : OUT STD_LOGIC);
END COMPONENT;
ENTITY TEST IS
PORT (A,B,C,D : IN STD_LOGIC;
E : OUT STD_LOGIC); BEGIN
END TEST;
Chip1 : Chip_A
PORT MAP (A,B,C,X,Y);
ARCHITECTURE BEHAVIOR OF TEST IS
Chip2 : Chip_B
SIGNAL X,Y : STD_LOGIC; PORT MAP (X,Y,D,E);
component OR2
port (in1, in2: in std_logic;
out1: out std_logic);
end component;
Component Instantiation and
Interconnections
The component instantiation statement
references a component that can be
Previously defined at the current level of the hierarchy
Defined in a technology library (e.g., vendor’s library)
instance_name : component_name
port map (port1=>signal1, port2=> signal2,… port3=>signaln);
instance_name : component_name
port map (signal1, signal2,… signaln);
component NAND2
port (in1, in2: in std_logic;
out1: out std_logic);
end component;
signal int1, int2, int3: std_logic;
:
U1: NAND2 port map (A,B,int1);
U2: NAND2 port map (in1=>C, in2=>D, out1=>int2);
U3: NAND3 port map (int1, int2, Z);
Data Objects
Constant
A constant can have a single value of a given
type and cannot be changed
Constants declared at the start of an architecture
can be used anywhere within the architecture
Constants declared within a process
can only be used inside that specific process
constant list_of_name_of_constant: type [ := initial value] ;
Signal
Initial value for signals representing wires
Not necessary
Initial value for signals representing storage
elements
Use explicit control signal, e.g., “reset” to initialize all
storage elements to a pre-determined state
Difference between variables
and signals
Example of a process using Variables
architecture VAR of EXAMPLE is
signal TRIGGER, RESULT: integer := 0;
begin
process
variable variable1: integer :=1;
variable variable2: integer :=2;
variable variable3: integer :=3;
begin
wait on TRIGGER;
variable1 := variable2;
variable2 := variable1 + variable3;
variable3 := variable2;
RESULT <= variable1 + variable2 + variable3;
end process;
end VAR
What are the values of “variable1”, “variable2”, “variable3”, and
“RESULT” after the process is executed?
Difference between variables
and signals
Example of a process using Signals
architecture SIGN of EXAMPLE is
signal TRIGGER, RESULT: integer := 0;
signal signal1: integer :=1;
signal signal2: integer :=2;
signal signal3: integer :=3;
begin
process
begin
wait on TRIGGER;
signal1 <= signal2;
signal2 <= signal1 + signal3;
signal3 <= signal2;
RESULT <= signal1 + signal2 + signal3;
end process;
end SIGN;
What are the values of “signal1”, “signal2”, “signal3”, and
“RESULT” after the process is executed?
Data Types
bit values: '0', '1'
boolean values: TRUE, FALSE
integer values: -(231) to +(231 - 1)
begin
-- Statements
-- Processes
:
end architecture_name;
Process (A,B,C)
Begin
statements;
End process;
Process Statement
5. Unary operators + -