Unit Vi Vhdl Programming 6 Hours
Unit Vi Vhdl Programming 6 Hours
V.H.S.I.C. means
Very High Speed Integrated Circuit
Thus…..
V.H.D.L. = Very High Speed Integrated Circuit Hardware Description Language
VHDL Benefits
1. Public Standard
2. Technology and Process Independent
– Include technology via libraries
3. Supports a variety of design methodologies
1. Behavioral modeling
2. Dataflow or RTL (Register Transfer Language) Modeling
3. Structural or gate level modeling
VHDL Benefits (cont)
4. Supports Design Exchange
– VHDL Code can run on a variety of systems
5. Supports Design Reuse
– Code “objects” can be used in multiple designs
6. Supports Design Hierarchy
– Design can be implemented as interconnected
submodules
VHDL Design Units
• Entity Declaration
– Describes external view of the design (e.g. I/O)
• Architecture Body (AB)
– Describes internal view of the design
• Configuration Declaration
• Package Declaration
– Library Declaration
• Package Body
VHDL Statement Terminator
Each VHDL Statements is terminated using a
semicolon
;
VHDL Comment Operator
To include a comment in VHDL, use the
comment operator
-- This is a comment
-- This is an example of a comment
y <= 0; -- can occur at any point
VHDL Program Format
Library
Declarations
Architecture
Library Declaration
• It is collection of commonly used pieces of
code.
• Allow them to be reused or shared by other
designs. Library
Package
Functions
Procedures
Components
Typical structure of library: Constants
Types
Library Declaration…..
• To declare library two lines of code required:
1) Containing name of library
2) Use clause
LIBRARY Library_name;
USE Library_name_package_name.pacakage_parts;
Library Declaration…..
• At least Three packages , from three different libraries are usually
needed in design that are :
1) ieee.std_logic_1164(from the IEEE library)
2) Standard (from std)
3) Work (from work)
PORT
(
Port_name : [ MODE ] [ DATATYPE ] ;
port_name : [ MODE ] [ DATATYPE ] ; NO Semi-colon
Port_name : [ MODE ] [ DATATYPE ] ; after Last Signal
.
.
port_name : [ MODE ] [ DATATYPE ]
);
END entity_name ;
IN / OUT / INOUT
1) BIT ( 2-Valued Logic )
2) STD_LOGIC ( 9-Valued LOGIC ) --Preferred
Input-Output specification of circuit
Example: my_ckt
Inputs: A, B, C
Outputs: X, Y
A VHDL description:
X
B my_ckt entity my_ckt is
Y port (
S A: in bit;
B: in bit;
S: in bit;
X: out bit;
Y: out bit);
end my_ckt ;
Example of ED For an AND Gate
A
Y
and_gate
B
ENTITY and_gate IS
PORT
(
A : IN STD_LOGIC ;
B : IN STD_LOGIC ;
Y : OUT STD_LOGIC
);
END and_gate ;
Architecture
BEGIN
Y < = A and B ;
END arch_name ;
The Complete VHDL Program For AND Gate
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY and_gate IS
PORT
(
A : IN STD_LOGIC ;
B : IN STD_LOGIC ;
Y : OUT STD_LOGIC
);
END and_gate ;
BEGIN
Y < = A and B ;
END arch_name ;
Architecture Modeling Style
1. Behavioral modeling
2. Dataflow or RTL (Register Transfer
Language) Modeling
3. Structural or gate level modeling
4. Mixed Style of Modeling
Modeling styles:
30
Data Flow Style
• It describe how information is passed between
in the circuit.
• View of data as flowing through a design, from
input to output.
• Used Concurrent signal assignment statement.
• Concurrent signal assignment statements are
concurrent statements,
• therefore, the ordering of these statements is
not important in an architecture body
Example of data flow For AND Gate
ARCHITECTURE dataflow OF and_gate IS
BEGIN
Y < = A and B ;
END dataflow;
entity HALF_ADDER is
port (A, B: in BIT; SUM, CARRY: out BIT);
end HALF_ADDER;
-- This is a comment line.
model for the HALF_ADDER entity
architecture HA_STRUCTURE of HALF_ADDER is
component XOR2
port (X, Y: in BIT; Z: out BIT);
end component;
component AND2
port (L, M: in BIT; N: out BIT);
end component;
begin
X1: XOR2 port map (A, B, SUM);
A1: AND2 port map (A, B, CARRY);
end HA_STRUCTURE;
Mixed Style of Modeling
• It is possible to mix the three modeling styles that we
have seen so far in a single architecture body.
39
VHDL Object Types
• Constants
• Signals
• Variables
• Files
40
Constant
• You can think of it just as a name for a value
reset_c := ‘0’; bus_width_c := 32;
• The value assigned to a constant cannot be changed
(the location of memory that stores the value cannot be
modified)
• Benefits:
– a better documented design.
– it is easier to update the design.
– But do not exaggerate !!!
41
Signals
• It is a physical signal (you can think of it like a piece
of wire)
• A signal is a sequence of time-value pairs
• A signal assignment takes effect only after a certain
delay (the smallest possible delay is called a “delta
time”).
• It is possible to define global signals (signals that can
be shared among entities)
• But more often signals are just locally defined for a
given architecture
42
Signals
• Syntax :
signal_name <= expression;
• Signal assignment
– new values take effect after some delay (delta if
not specified)
signal LOGIC_A : BIT;
LOGIC_A <= ‘0’;
LOGIC_A <= ‘0’ after 1 sec;
LOGIC_A <= ‘0’ after 1 sec, ‘1’ after 3.5 sec;
Variables
• Assignment to variables are scheduled immediately (the
assignment takes effect immediately)
MUX
I0 S1 S0 y
I1 0 0 I0
y
I2 0 1 I1
I3 1 0 I2
S1 S0 1 1 I3
4:1 Mux using Data flow
• library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Mux_41_dataflow is
Port ( i : in STD_LOGIC_VECTOR (3 DOWNTO 0); S1 S0 y
sel : in STD_LOGIC_VECTOR (1 DOWNTO 0);
y : out STD_LOGIC); 0 0 I0
end Mux_41_dataflow;
architecture Dataflow of Mux_41_dataflow is 0 1 I1
begin 1 0 I2
with sel select
y<= i(0) when "00", 1 1 I3
i(1) when "01",
i(2) when "10",
i(3) when others;
end Dataflow;
4:1 mux Structural Model
• library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Mux_41_structual is
• port( D0, D1, D2, D3: in std_logic; -- the data lines
• S0, S1 : in std_logic; -- the selector switches
• F : out std_logic);-- the output
end Mux_41_structual;
architecture Behavioral of Mux_41_structual is
component and_3
Port ( a,b,c : in STD_LOGIC;
y : out STD_LOGIC);
end component;
•
• component or_2
Port ( a,b : in STD_LOGIC;
y : out STD_LOGIC);
end component;
• library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity Counter is
Port ( output : out STD_LOGIC_VECTOR (2
downto 0);
preset,clear,clk,up_dwn,rst : in
STD_LOGIC);
end Counter;
architecture Behavioral of Counter is
begin
process(clk)
variable temp: STD_LOGIC_VECTOR (2 downto 0);
begin
if (clk' event and clk='1') then
if (preset = '1') then
temp := "111";
elsif (clear = '1') then
temp := "000";
elsif (up_dwn = '1' ) then
temp := temp + '1';
else
temp := temp - '1';
end if;
end if;
output<= temp;
end process;
end Behavioral;
steps to Run VHDL codes:-
1. double click on xiling icon
2. go to file
3. new project
4. give project name ->next
5. select product category
6. select family ->spartan 2
7. select device ->xc25200
8. select package ->PQ208
9. select speed -> -5Q
10. verify simulator ->ISE simulator (VHDL / verylog)
11 .Select preffereed languageVHDL
12.Next->next->next->finish
13.double clink on create new source
14.select VHDL module
15.give same file name->next
16.enter required entity i.e. i/p & o/p
17.next->next->finish
18.program window will open.
19.write VHDL code properly & save it using ctr+s.
20.go to synthesis ->check syntax.
21.check view RDL schematics
STEPS FOR STIMULATION