Lecture VHDL
Lecture VHDL
1
VHDL – High Level View
• VHDL provides extensive range of modeling capabilities. However
subset of language is usually sufficient to design most applications
• The design units can be entity declaration, architecture body,
configuration declaration, package declaration or package body
LIBRARIES:
• These are repository in the file system of host environment that contain
compiled design units
• Libraries STD & WORK are predefined and default in VHDL (no need
to declare) while others need to be declared with ‘library’ clause.
• Other useful library is IEEE
Library IEEE;
Use IEEE.std_logic_1164.all - - use all items of package called
’std_lgoic_1164’
Use IEEE.numeric_std.all - - use complete ‘numeric_std’ package
2
Libraries and Packages
Package:
• It has two parts : (1) package declaration (2) package body (optional)
• Often contain declaration that are common across many design units
• Frequently used hardware units and subprograms
• Predefined Package named STANDARD is available in VHDL that contain
many commonly used predefined types like BIT, BIT_VECTOR,
INTEGER, CHARACTER, TIME etc.
• The most widely used package is STD_LOGIC_1164 from library IEEE
3
Entity and Architecture
ENTITY
• Any definable hardware block is entity. Entity is
only a black box with interface ports
• Ports of entity can be of in, out, inout or buffer
type
Architecture:
• Describes working of an entity
• Inherits all ports and generics of an entity
• Entity may have multiple architectures (alternate
designs)
• Description in architecture can be structural,
behavioral, dataflow or mix style
4
Objects and their usage
• VHDL has four class of objects:
(1) Signal : Used to represent wire or storage in digital hardware.
Unlike variables, signals acquires value after some delay (at least
delta delay). Objects of signal class can hold set of future values that
are to appear on signal (e.g. by specifying waveform)
(2)Variables: They are similar to conventional programming
language. They acquire value immediately .
(3) Constant: Objects of constant class can hold single value that
can not be changed during the simulation
(4) File: Objects belonging to file class contain sequence of values.
Values can be read or written to file using read and write procedures
• Types of values that an object can acquire are called data types.
5
Objects and their usage
6
Data Types
• Enumeration: defines a type that has a set of values
consisting of either characters or names.
– Predefined
(1) In STANDARD package of STD library:
• bit, boolean, character, severity_level, file_open_status,
file_open_kind etc.
• Bit => (‘0’,’1’)
• Boolean => (false, true)
• character => (. . ASCII characters. . )
(2) In package std_logic_1164 of IEEE library
• std_ulogic => (‘U’,’X’,’0’,’1’,’Z’,’W’,’L’,’H’,’-’)
• Subtype STD_LOGIC is resolved STD_ULOGIC
Note: User can define a new data type / array type using type statement
7
Data Types in VHDL
• Integer:
– Predefined type is integer whose range is decided by declaration
e.g. variable v1 : integer range 0 to 15; type index is range 0 to 9;
• Floating Point:
– Predefined type is real whose range is decided by declaration
variable v2 : real range -0.5 to 1.5;
type TTL_VOL is range 0.2 to 5.0;
8
Data Types
• Array type: includes constrained array and unconstrained array. Array
is an indexed collection of objects of same type and size
– Unconstrained array types:
• Predefined in STANDARD package: string, bit_vector,
• Predefined In IEEE.std_logic_1164 package: std_logic_vector,
std_ulogic_vector
e.g.
• Signal add_bus : bit_vector (15 downto 0) ;
• Signal data_bus : std_logic_vector (7 downto 0) ;
9
OPERATORS
• Logical : and, or, nand, nor, xor, xnor, not
– Defined for BIT and BOOLEAN and their one dimensional array
– A nand B nand C => invalid, (A nand B) nand C => valid
10
OPERATORS
• The values can be combined using & operator. For example,
Signal s1 : bit_vector(3 downto 0);
s1<= “10” & “01”;
11
Assigning Values
12
Dataflow Modeling
• Three types of signal assignment statements: (1)concurrent (2)conditional
Entity mux4 is
port ( inp : in bit_vector ( 0 to 3);
s1,s0 : in bit; z : out bit);
End mux4;
Architecture concurrent of mux4 is
signal w0,w1,w2,w3 : bit;
begin
13
Dataflow Modeling
Architecture conditional of mux4 is -- alternate architecture
begin
z <= inp(0) when s0=‘0’ and s1=‘0’ else - - conditional
inp(1) when s0=‘0’ and s1=‘1’ else
inp(2) when s0=‘1’ and s1=‘0’ else
inp(3) when s0=‘1’ and s1=‘1’;
unaffected when others;
End conditional;
14
BEHVIOURAL Description
Process:
• It is sequentially executed block of hardware description
• Architecture can have multiple processes and they are concurrent among
themselves (i.e. simultaneous execution of multiple processes).
• Process is only sensitive to signals placed in the sensitivity list.
• If sensitivity list is not present, there must be wait statement in process.
15
BEHVIOURAL Description
• Process is triggered when an event occurs to any signal in sensitivity
list and then sequential statements are executed in order. It suspends
after executing last sequential statements and waits for event to occur
in sensitivity list.
• Process is never exited; it is either running (executing) or suspended
• If process uses wait statements, its sensitivity list must be empty.
16
BEHVIOURAL Description
• IF statement : syntax
If boolean-expression then
sequential statements
[Elsif boolean-expression then
sequential statements
[Else - - else clause is optional
sequential statements
End if ;
• CASE statement:
Case expression is - - expression must have only discrete values
When choices => sequential statements
When choices => sequential statements
[when others =>sequential statements]
End case;
17
BEHVIOURAL Description
In case statement, choices can be combined and bind to same action,
for example
Case sig1 is
When ‘W’ | ‘X’ | ‘Z’ |’U’ => sequential statements
When others => sequential statements;
End case;
• Looping Construct:
The are various form of loop statements
1) While loop:
[loop-label]: While (boolean-expression) loop
Sequential statements
End loop [loop-label];
18
BEHVIOURAL Description
(2) For loop:
[loop-label ]: For identifier in discrete-range loop
Sequential statements
End loop [loop-label];
19
STRUCTURAL DESCRIPTION
• Structural description defines hardware as collection of components
• Components are precompiled design units (that exist in WORK
library) that describes its working.
• At the top of hierarchy is Top level design entity. The top level entity
may contain many components
20
STRUCTURAL DESCRIPTION
• Let us say we have top level entity (having inputs A & B and
outputs W & Z) that contains two sub units called comp1 and
comp2. Then, these sub-units are instantiated and connections
are defined using “port map” statements
21
STRUCTURAL DESCRIPTION
Component instantiations:
The ports of each instance must be associated to signals/ports of top
level entity. The port map associates ports of component called formals
with the signals/ports of top entity called actuals.
– Named association :- both formals and actuals are specified, order is
not important.
– Positional association :- only actuals are specified with proper order
syntax : Instance name: component name port map
(formal1=>actual1,formal2=>actual2, . . . )
22
Example – Structural Description
• Example 1: Full Adder:
– 1-bit basic adder can be compiled and then stored in work library
23
Example – Structural Description
24
Example – Structural Description
Entity add4 is -- 4-bit parallel adder
Port ( A, B : in std_logic_vector (3 downto 0);
Cin : in std_logic ;
S : out std_logic_vector (3 downto 0); Co : out std_logic );
End entity add4;
• Notes: (i) This is direct instantiations where name of components and port
name must match with entity that describe this
25
Test bench
• Testbench is verification program used to verify the correctness of
designed hardware
• Following is a test bench code for testing is 4-bit parallel adder “add4”
described earlier.
Entity test_bench is
End test_bench;
26
signal inp_A : std_logic_vector(3 downto 0) := "0000";
signal inp_B : std_logic_vector(3 downto 0) := "0000";
signal inp_cin : std_logic := '0';
signal outp_S : std_logic_vector(3 downto 0);
signal outp_Co : std_logic;
begin
-- create instance of component full_adder
DUT1 : add4 port map (A=>inp_A, B=>inp_B, cin=>inp_cin,
S=>outp_S, Co=> outp_Co);
process is
begin
inp_A <= "0000"; inp_B <= "0000";
inp_cin <= '0'; wait for 10 ns;
inp_A <= "0001"; inp_B <= "0001"; wait for 10 ns;
inp_A <= "1001"; inp_B <= "1001"; wait for 10 ns;
inp_A <= "1101"; inp_B <= "1101"; wait for 10 ns;
assert false report "end of simulation";
wait;
end process;
end behave;
27