L7 Slides 2
L7 Slides 2
1
component OR_3
port (A,B,C: in bit; Reserved Words
Reserved Z: out bit);
Words end component ;
Declarations of Components and Entities are similar
Components are virtual design entities
entity OR_3 is
port (A,B,C: in bit;
Z: out bit);
end OR_3;
architecture MODEL of OR_3 is
begin
Z <= A or B or C;
end MODEL; 2
Signal mapping or wiring:
Name of Component Reserved word By Positional Association Connectivity
-- Connection of Components
A1: AND_2 port map (A_IN, B_IN, TEMP1);
A2: AND_2 port map(A_IN, C_IN, TEMP2);
A3: AND_2 port map(B_IN, C_IN, TEMP3);
Label
O1: OR_3 port map(TEMP1, TEMP2,
(identifier)
TEMP3, COUT);
Component Instantiation Statements
3
-- Entity
-- Architecture Signal Assignments
-- Declaration Part Position not
Important
begin
-- Connection of Components with Named Association
A1: AND_2 port map (A =>A_IN, B =>B_IN , Z =>TEMP1);
A2: AND_2 port map (A =>A_IN, Z =>TEMP2 , B =>C_IN);
A3: AND_2 port map (A =>B_IN, B =>C_IN, Z =>TEMP3);
O1: OR_3 port map (A =>TEMP1, B =>TEMP2, C =>TEMP3, Z=> C_out);
end structure;
4
• A hierarchical structure description is a powerful
modeling construct in VHDL as it provides the mechanism
to decompose the description of a large, complex digital
system into smaller pieces.
-- Second Component AB
Z
entity and_2 is and_2
port (A,B: in BIT; Z: out BIT);
end and_2;
architecture Data Flow of and_2 is
begin
Z <= A and B;
end Data Flow;
6
-- Interface
entity H_ADDER is
port (A,B: in BIT; SUM, CRY: out BIT);
end H_ADDER;
-- Body
architecture STRUCTURAL of H_ADDER is
A
component xor_2 xor_2 SUM
port (A,B : in BIT; Z: out BIT);
end component;
component and_2
port (A,B : in BIT; Z: out BIT); and_2 CRY
end component; B
begin
X1: xor_2 port map (A,B,SUM);
A1: and_2 port map (A,B, CRY);
end STRUCTURAL;
7
-- Interface
entity FULL_ADDER is
port (A,B,C: in BIT; SUM, CRY: out BIT);
end FULL_ADDER;
H_ADDER H_ADDER
-- Body
architecture STRUCTURAL of F_ADDER is
A SUM1
SUM
component H_Adder
port (X,Y : in BIT; Z1,Z2: out BIT);
end component; B
begin
HA1: H_ADDER port map (A, B, SUM1, CRY1);
HA2: H_ADDER port map (SUM1, C, SUM, CRY2);
O_2: OR_2 port map (CRY1, CRY2, CRY);
end STRUCTURAL;
8
library ieee;
use ieee.std_logic_1164.all;
entity Adder16 is
port (A, B: in std_logic_vector(15 downto 0);
Cin: in std_logic; Cout: out std_logic;
Sum: out std_logic_vector(15 downto 0));
end Adder16;
architecture Ripple of Adder16 is
component Full_Adder
port (X, Y, Cin: in std_logic; Cout, Sum: out std_logic);
end component;
signal C: std_logic_vector(15 downto 0);
-- Before instantiating the components you must tell the VHDL compiler
--which components to use. We use the for-use construct for this purpose
10
- In real life when building a pc board,usually the same components are often
picked up from a storage area and placed on the board. VHDL structural
description often use the same set of components. Repeating all the
constructs to describe all the components is very tedious. The problem is
solved by introducing the package concept.
11
Packages are the mechanism to share objects among
different design units
- The use statement placed just before the architecture gives access
to all the declarations in the package:
use WORK.ASIM_LIB.all
The statement above gives access to all component declarations in
ASIM_LIB located in library WORK.
- The use statement allows the package ASIM_LIB to export its declarations.
-- Package Description
Reserved package gates is Header
-- Declare all the gates
Word
component and_2 is
port (A,B: in BIT; Z: out BIT);
end component;
Declared Utilities to be exported
component xor_2 is
Components
port (A,B: in BIT; Z: out BIT);
end component;
component or_2 is
port (A,B: in BIT; Z: out BIT);
end component;
Closes Package
end gates;
declaration
Package Declaration
15
-- Interface
entity HALF_ADDER is
port (A,B: in BIT; SUM, CRY: out BIT);
end HALF_ADDER;
-- Body
A
-- Use components in Package gates xor_2 SUM
use WORK.gates.all ;
end structural;
16
package Asim_1 is
A use clause can be placed Can use all declaration
before an entity declaration, Declaration of declaration
giving the design entity and Asim_1
associated architecture access end Asim_1;
to the package contents.
A use clause can also be use WORK.Asim_1.all
package Asim_2 is
placed before a package declaration
declaration giving a package declaration
access to another package.
Thus an hierarchy of packages end Asim_2;
is constructed in which the
declarations of one package Can use all use WORK.Asim_2.all
may be based upon Declaration of --Body
Asim_2 Architecture……….
declarations in other packages. declaration
( No access to
Asim_1)
end Asim_2; 17
- In VHDL everything must be declared before it can be used. A
declaration defines what a name represents.
18
-- You may select only an element Selected of a Package
use WORK.gates.and_2;
begin
A1: and_2 port map (………..);
………….. Gives acces only
…………… to and_2
OR1:
end access;
19
-- Example of Nested Spaces
package signals is
signal Z: bit := ‘0’;
end signals;
20
-- Example
entity CARRY_GENERATE is
port (A_IN, B_IN, C_IN : in BIT; C_OUT : out BIT);
end CARRY_GENERATE;
end structural;
21
Architecture
• Structural
• Behavioral
Data Flow
Algorithmic
• Mixed
We will use a full adder design to show
the different architectural styles
22
Structural Modeling
It IMPLICITLY defines the input/output functions by describing components
and their interconnections. It treats the system to be described as a collection
of gates and other components built on hierarchy that are interconnected to
perform a certain function.
Structural modeling mimic actual hardware design, like a schematic diagram
that has the components and their interconnections. It is by the use of defined
components (cells or micros entities etc. ) over and over again and their
interconnection.
All used component have to be defined earlier, usually in a package.
Structural modeling uses hierarchy to reduces modeling and the design
complexity.
At the lowest hierarchy component are given in a behavioral model, using the
basic logic operators such as AND, OR etc.
Within the architecture body declare:
All components to be used.
All signals that are used to interconnect the components.
**Use labels for each instance of the component used for clear identification.
DATA FLOW Modeling
This kind of modeling describes how data moves through the system.
The data flow model makes use of concurrent statements that are executed in parallel as
soon as data arrives at the input.
With Concurrency , when a change occurs on the right hand side of any statement, all
other statements that get affected are executed in the same time sample. This is the
nature of the event driven simulation of VHDL. This is to say that, the order in which
the statements are written does not matter and has no bearing on the execution of the
statements. Concurrent statements are executed in parallel.
Concurrent design usually has no hierarchy and is a flat design.
Example:
LEVEL1 : block
begin
Temp1 <= A xor not B after 2 ns;
Temp2 <= B xor not A after 2 ns;
Temp3 <= Temp1 or Temp2 after 5ns;
end
end Block LEVEL1;
Behavioral Modeling
It is the highest level of abstraction that describes a system in
terms of what the system does, or how the output is related to
the input signals.
Algorithmic architecture is composed of one or more concurrent
processors. The statements inside each process execute
sequentially .
It could be of many forms such as Boolean expression or Register
Transfer etc.
example:
The house alarm will sound if the Alarm, is activated and one of
the inside doors D1,D2 or D3 is opened.
A_IN TEMP2
C_OUT
C_IN A2
OR1
B_IN TEMP3
C_IN A3
26
Block
The use of block statement is for organizational purpose only and it does
not effect the simulation.
Each block must be assigned a label placed just before the block reserved
word.
Example:
LEVEL1 : block
begin
Temp1 <= A xor not B after 2 ns;
Temp2 <= B xor not A after 2 ns;
Temp3 <= Temp1 or Temp2 after 5 ns;
end
end Block LEVEL1;
architecture GATE_IMPLEMENTATION of FULL_ADDER is
Block
component or_gate port (A,B : in BIT; C: out BIT);
end component;
component and_gate port (A,B : in BIT; C: out BIT);
end component;
component xor_gate port (A,B : in BIT; C: out BIT);
end component;
-- Local Signal Declaration
A S1
signal S1, S2, S3: BIT; SUM
begin B
X1: xor_gate port map (A, B, S1);
S2
X2: xor_gate port map (S1, CIN, SUM);
A1: and_gate port map (CIN, S1, S2); CIN
COUT
A2: and_2 port map (A, B, S3); S3
O1: or_gate port map (S2, S3, COUT);
end Block;
end GATE_IMPLEMENTATION ; 28
architecture DATA_FLOW_IMPLEMENTATION of FULL_ADDER is
block
signal S1, S2, S3: BIT;
begin
S1 <= A xor B;
SUM <= S1 xor CIN;
S2 <= A and B;
S3 <= S1 and CIN;
COUT <= S2 or S3;
end block;
end DATA_FLOW_IMPLEMENTATION;
29
architecture ALGORITHMIC_IMPLEMENTATION of FULL_ADDER is
block
begin
process (A,B,CIN)
variable S: BIT_VECTOR ( 1 to 3 ) := A & B & CIN;
variable COUNT: INTEGER range 0 to 3 :=0;
begin
for i:= 1 to 3 loop
if S(i) = ‘1’ then
COUNT := COUNT +1;
end if ;
end loop;
case COUNT is
when 0 => COUT <= ‘0’; SUM <= ‘0’;
when 1 => COUT <= ‘0’; SUM <= ‘1’;
when 2 => COUT <= ‘1’; SUM <= ‘0’;
when 3 => COUT <= ‘1’; SUM <= ‘1’;
end case; end process;
end block; end ALGORITHIC-IMPLEMENTATION;
30
architecture FUNCTIONAL_IMPLEMENTATION of FULL_ADDER is
use convert_pack.all -- Contains type conversion Functions
block
port ( A,B,C: in INTEGER; S, CO: out INTEGER;
-- Type conversion between BIT and INTEGER is performed in ports
port map ( X=> Bin_to_Int(A), Y=> Bin_to_Int(B), CIN=> Bin_to_Int(C),
INT_to_Bin (S) => SUM, INT_to_Bin (CO) => COUT);
process (A,B,C) -- Sensibility list of the process
variable TOTAL: INTEGER;
begin
TOTAL := A + B + C;
S <= TOTAL mod 2;
CO <= TOITAL / 2;
end Process;
end Block;
end FUNCTIONAL_IMPLEMENTATION;
31
architecture MIXED_IMPLEMENTATION of FULL_ADDER is
Data Flow
end MIXED_IMPLEMENTATION ;
32
THERE ARE VARIOUS SITES THAT YOU MAY TRY TO GET VHDl
http://www.freedownloadscenter.com/Best/vhdl-tool-
free.html
http://www.csee.umbc.edu/help/VHDL/#free
ActiveHDL
http://www.aldec.com/products/active-hdl/
Please visit this site for window based VHDL they have a demo that you can be downloaded The tool is called ActiveHDL.
Xilinx:
www.xilinx.com/ise/logic_design_prod/webpack.htm
VHDL Simili
http://www.symphonyeda.com/products.htm. There's a free version for students, but
you can only simulate 10 waveforms at the same time. There is also a 30 day trial for the standard/professional edition
which does not have this limit. It is very good and
35
Test Bench
To be able to test the circuit that you have designed
then you have to apply some test vectors.
This task is achieved by writing a test bench.
Test_Bench
Stimulus Circuit
36
Circuit : AND GATE
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity and_2 is
Port ( a : in bit;
b : in bit;
c : out bit);
end and_2;
begin
c <= a and b;
end dataflow; 37
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity stim is
Port ( out_1 : out bit; out_2 : out bit);
end stim;
architecture Behavioral of stim is
signal a, b : bit:='0';
begin
process
begin
--00
out_2 <= '0';
out_1 <= '0';
wait for 10 ns;
--01
out_2 <= '1';
out_1 <= '0';
wait for 10 ns;
--10
out_2 <= '0';
out_1 <= '1';
wait for 10 ns;
--11
out_2 <= '1';
out_1 <= '1';
wait for 10 ns; 38
end process; end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity bench is
end bench;
signal x, y, z : bit:='0';
begin
inst_stim: stim port map (x, y);
inst_and2: and_2 port map (x, y, z);
end concurrent ; 39
Simulation results of
TestBench
40