SlideShare a Scribd company logo
1 of 32
Functions
A function accepts a number of arguments and returns a result.
Each of the arguments and the result in a function definition or
function call have a predetermined type.
When a function is called, the actual parameters in the function call
are substituted for the formal parameters
When a function is called from within an architecture, a value of
the type return-type is returned in place of the function call
A function may define its own local types, constants, variables and
nested functions and procedures
The keywords begin and end enclose a series of “sequential
statements” that are executed when the function is called

                                                                1
A simple example

entity Inhibit is   -- a.k.a. “but-not” as in “X but not Y”
    port (X,Y:   in BIT;
           Z: out BIT);
end Inhibit;        -- end of entity declaration


architecture Inhibit_arch of Inhibit is
begin
    Z <= ‘1’ when X=‘1’ and Y=‘0’ else ‘0’;
end Inhibit_arch    -- end of architecture declaration


                                                         2
But-not gate using a function
  architecture Inhibit_archf of Inhibit is
  function ButNot (A,B: bit) return bit is
  begin
     if B = ‘0’ then return A;
     else return ‘0’;
     end if;
  end ButNot;
  begin
     Z <= ButNot(X,Y);
  end Inhibit_archf
                                             3
Libraries
A VHDL library is a place where the compiler stores information about a
particular design project, including intermediate files that are used in the
analysis, simulation and synthesis of the design.
Library location is implementation-dependent
For a given VHDL design, the compiler automatically creates and uses a
library named “work”.
When compiler analyzes each file in the design, it puts the results there.
A complete VHDL design usually has multiple files, each containing
different design units including entities and architectures.
Not all the information needed in a design may be in the “work” library.




                                                                         4
Libraries
A designer may rely on common definitions or functional modules
across a family of different projects.
Even small projects may use a standard library such as the one
containing IEEE standard definitions
The designer can specify the name of such a library using a
library clause at the beginning of the design file.
For example one can specify the IEEE library as
library IEEE;
Specifying a library name in a design gives it access to any
previously analyzed entities and architectures stored in the library,
but does not give access to type definitions and the like. This is
the function of “packages” and “use clauses”
                                                                 5
Library statement in VHDL
library ieee;
-- needed if you want to use the ieee library

library unisim;
-- will see this in Xilinx-generated files

library work;
-- implicitly included in every VHDL file



                                            6
What’s in a package?
 A package is a file containing definitions of
 “objects” that can be used in other programs
   Is an ADA concept
   Like the entity-architecture pair, the package is another
   precursor to the OOP idea!
   “object” here means signals, types, constants,
   functions, procedures, components declarations, etc.
   NOT objects as in OOP.
 The kind of objects are signal, type,
 constant, function, procedure, and
 component declarations

                                                               7
Packages
Signals that are defined in a package are “global” signals,
available to any VHDL entity that uses the package
Types and constants defined in a package are known in any
file that uses the package
Likewise functions and procedures defined in a package can
be called in files that use the package and components can be
“instantiated” in architectures that use the package.
To use a package you say “use” … for example:
use ieee.std_logic_1164.all; -- use all
definitions in pkg
use ieee.std_logic_1164.std_ulogic -- use
just def std_ulogic type

                                                        8
Packages
A design can use a package by including a use clause at the
beginning of the design file
To use all the definitions in the IEEE standard 1164 package one
would write
use ieee.std_logic_1164.all;
Here “ieee” is the name of the library which has previously been
given in the library clause
Within the library , the file named “std_logic_1164” contains
the desired definitions and the suffix “all” tells the compiler to use
all of the definitions in this file
Package is not limited to standard bodies, anyone can write a
package using the proper syntax
                                                                9
VHDL Design Styles
              VHDL Design
                 Styles



   dataflow      structural        behavioral

 Concurrent   Components and     Sequential statements
 statements   interconnects    • Registers
                               • State machines
                               • Test benches


              Subset most suitable for synthesis 10
VHDL Example

 Entity declaration for the 2 to 1 MUX
ENTITY mux2_1 IS
  PORT (in0, in1, sel: IN STD_LOGIC;
                 yout: OUT STD_LOGIC);
END mux2_1;




                                         11
VHDL Example
      Logic circuit for a 2-1 MUX device
      Helpful for understanding architecture
in1
sel

                                               yout
in0




                                                 12
Behavioral architecture for the 2 to 1 MUX
ARCHITECTURE    a1 OF mux2_1 IS
 P1: PROCESS    (sel, in0, in1)
 BEGIN
   IF (sel =    ‘0’) THEN
     yout <=    in0;
   ELSE
     yout <=    in1;
   END IF;
  END P1;
END a1;
               in1
               sel

                                   yout
               in0

                                             13
Structural architecture for the 2 to 1 MUX
ARCHITECTURE a2 OF mux2_1 IS
 SIGNAL sel_not, in0_and, in1_and: STD_LOGIC;
 COMPONENT OR_GATE PORT(x,y: IN STD_LOGIC; z: OUT STD_LOGIC);
 COMPONENT AND_GATE PORT (x,y: IN STD_LOGIC; z: OUT STD_LOGIC);
 COMPONENT INV_GATE PORT (x: IN STD_LOGIC; z: OUT STD_LOGIC);
BEGIN
  U1: AND_GATE PORT MAP (in0, sel_not, in0_and);
  U2: AND_GATE PORT MAP (in1, sel, in1_and);
  U3: INV_GATE PORT MAP (sel, sel_not);
  U4: OR_GATE PORT MAP (in0_and, in1_and, yout);
END a2;
                 in1                   In1_and
                 sel

                                                 yout
                  in0                 In0_and
                            sel_not
                                                          14
Dataflow architecture for the 2 to 1 MUX
ARCHITECTURE a3 OF mux2_1 IS
BEGIN
  yout <= ((in0 AND NOT(sel)) OR (in1 AND sel));
END a3;

  In1
  sel

                                             yout
  In0


                                               15
Half Adder Circuit
 Looking at the truth table for a half adder, it is easy
 to visualize the circuit



   AB     CS          A
                                                     S
                      B

                                                     C



                                                      16
Full Adder Circuit
  The circuit at right shows a                  half adder
  full adder constructed from
  two half adders.
  XOR generates the sum
  output
  AND generates the carry
  output                                                         half adder

     [                        ]
C = ( A ⋅ B + A ⋅ B ) ⋅ C ′ + ( A ⋅ B ) = ( A ⋅ B ⋅ C ′) + ( A ⋅ B ⋅ C ′) + ( A ⋅ B )
   = ( A ⋅ C ′) + ( B ⋅ C ′) + ( A ⋅ B )
S = A ⊕ B ⊕ C′
                                                                                  17
-- Dataflow model for a full adder circuit
-- Library Statement declares the ieee synthesis library
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;

-- Entity declaration
ENTITY fulladder IS
 PORT(Ain, Bin, Cin: IN STD_LOGIC;
         Cout, Sout: OUT STD_LOGIC);
END fulladder;

-- Architecture defines the function
-- In this case the function is defined using Boolean
equations
ARCHITECTURE dataflow OF fulladder IS
BEGIN
 -- Concurrent Signal Assignment Statements
 Sout <= Ain XOR Bin XOR Cin;
 Cout <= (Ain AND Bin) OR (Ain AND Cin) OR (Bin AND Cin);
END dataflow;
-- Structural architecture is defined by a circuit
ARCHITECTURE structural OF fulladder IS
COMPONENT AND2
 PORT( A, B: IN STD_LOGIC; F: OUT STD_LOGIC);
END COMPONENT;
COMPONENT OR3
 PORT( A, B, C: IN STD_LOGIC; F: OUT STD_LOGIC);
END COMPONENT;
COMPONENT XOR2
 PORT( A, B: IN STD_LOGIC; F: OUT STD_LOGIC);
END COMPONENT;
SIGNAL AXB, AB, BC, AC: STD_LOGIC;
BEGIN
 F1: XOR2 port map (Ain, Bin, AXB); --Port Map Statements
 F2: XOR2 port map (AXB, Cin, Sout);
 F3: AND2 port map (Ain, Bin, AB);
 F4: AND2 port map (Bin, Cin, BC);
 F5: AND2 port map (Ain, Cin, AC);
 F6: OR3 port map (AB, BC, AC, Cout);
END structural;
Binary Addition: 4-Bit Numbers
The following example illustrates the addition of two
4-bit numbers A(A3A2A1A0) and B(B3B2B1B0):




                                                  20
Binary Addition: 4-Bit Numbers

The addition can be split-up in bit
slices
Each slice performs the addition of
the bits Ai, Bi and the Carry-in bit Ci
   Ci <= carry-out bit of the previous slice
Each slice is simply a full adder



                                               21
4-Bit Binary Adder
Circuit for a 4-bit parallel binary adder constructed
from full adder building blocks




                                                    22
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
-- VHDL model of a 4-bit adder using four full adders
ENTITY four_bit_adder_st IS
PORT (A, B : IN STD_LOGIC_VECTOR(3 downto 0);
       SUM : OUT STD_LOGIC_VECTOR(3 downto 0);
       CIN : IN STD_LOGIC;
      COUT : OUT STD_LOGIC);
END four_bit_adder_st;




                                                        Cin


 Cout

                      Internal Signals
-- The architecture is a structural one.
ARCHITECTURE structural OF four_bit_adder_st IS
-- First all the components are declared. The full adder
-- is declared only once, even though it will be used 4
times.
COMPONENT fulladder
  PORT(Ain, Bin, Cin: IN STD_LOGIC;
          Cout, Sout: OUT STD_LOGIC);
END COMPONENT;
-- The full adders are connected by carry signals. These
-- must be declared also.
SIGNAL C : STD_LOGIC_VECTOR(1 to 3);
-- Port map statements are used to define full adder
-- instances and how they are connected.
BEGIN
  F1: fulladder port map (A(0),B(0),CIN,C(1),SUM(0));
  F2: fulladder port map (A(1),B(1),C(1),C(2),SUM(1));
  F3: fulladder port map (A(2),B(2),C(2),C(3),SUM(2));
  F4: fulladder port map (A(3),B(3),C(3),COUT,SUM(3));
END structural;
-- The architecture in this case is a dataflow one
ARCHITECTURE dataflow OF four_bit_add_df IS
-- Again there will be internal carry signals that are not
-- inputs or outputs. These must be declared as signals.
SIGNAL C : STD_LOGIC_VECTOR(1 to 3);
-- Concurrent signal assignments can be used to describe
-- each of the 4 outputs and the carry signals.
BEGIN
  SUM(0) <= A(0) XOR B(0) XOR Cin;
  C(1) <= (A(0) AND B(0)) OR (A(0) AND Cin) OR (B(0) AND Cin);

  SUM(1) <= A(1) XOR B(1) XOR C(1);
  C(2) <= (A(1) AND B(1)) OR (A(1) AND C(1)) OR (B(1) AND C(1));

  SUM(2) <= A(2) XOR B(2) XOR C(2);
  C(3) <= (A(2) AND B(2)) OR (A(2) AND C(2)) OR (B(2) AND C(2));

  SUM(3) <= A(3) XOR B(3) XOR C(3);
  COUT <= (A(3) AND B(3)) OR (A(3) AND C(3)) OR (B(3) AND C(3));
END dataflow;
D latch with an async clear and level sensitivity
library IEEE;
use IEEE.Std_logic_1164.all;
entity latch_wc is
  port (CLK, D, CLR: in Std_logic;
                   Q: out Std_logic);
end latch_wc;                                      CLR
Architecture design of latch_wc is
begin
   process (CLK, D, CLR)
      begin
      if CLR = '1' then      -- CLR active High
         Q <= '0';
      elsif CLK = '1' then -- CLK active High
         Q <= D;             -- note that Q is not assigned
                                a value for CLK = '0'
      end if;
   end process;
end design;
                                                     26
D latch with asynch clear and rising-edge triggered
library IEEE;
use IEEE.Std_logic_1164.all;
entity dff_wac is
  port (CLK, D, CLR: in Std_logic;
                   Q: out Std_logic);
                                                    CLR
end dff_wac;
Architecture design of dff_wac is
begin
      process (CLK, D, CLR)
      begin
        if CLR = '1' then -- asynchronous CLR active High
             Q <= '0';
        elsif (CLK'event and CLK='1') then
             Q <= D; -- CLK rising edge, CLK'event and
                         CLK = '1' can be replaced by the
                         "function" rising_edge (CLK)

        end if;
      end process;
end design;                                         27
T f-f with an asynch clear and rising edge triggered
library IEEE;
use IEEE.Std_logic_1164.all;
entity t_ff is
   port (T, CLK, CLR:      in std_logic;
          Q:      buffer std_logic);
end t_ff;                                       CLR
architecture design of t_ff is
begin
  process (CLK, CLR, T)
  begin
    if (CLR = '1') then
             Q <= '0';
    elsif rising_edge (CLK) then
      case T is
          when '0' =>           Q <= Q;
          when '1' =>           Q <= not Q;
          when others =>        Q <= '0';

      end case;
    end if;
                                                  28
  end process;
JK f-f with an asynch reset and rising edge triggered
library IEEE;
use IEEE.Std_logic_1164.all;

entity JK_FF is
port (clock, J, K, reset:    in std_logic;       reset
                 Q, Qbar:   out std_logic);
end JK_FF;

architecture behv of JK_FF is
    signal state: std_logic;    -- define the useful
                                    signals here
    signal input: std_logic_vector(1 downto 0);




                                                       29
JK f-f with an asynch reset and rising edge triggered
begin
    input <= J & K;    -- combine inputs into 2-bit vector
    p: process(clock, reset) is
    begin
      if (reset='1') then
          state <= '0';
      elsif (rising_edge(clock)) then
          case (input) is    -- compare to the truth table
            when "11" =>           state <= not state;
            when "10" =>           state <= '1';
            when "01" =>           state <= '0';
            when others =>         null;
            end case;
      end if;
    end process;
    -- concurrent statements
    Q <= state;
    Qbar <= not state;
end behv;                                          reset
                                                    30
JK f/f with enable using if-then-else structure
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity JK_FF_VHDL is
  port( J,K: in std_logic;
        Reset: in std_logic;
        Clock_enable: in std_logic;
        Clock: in std_logic;
        Output: out std_logic);
end JK_FF_VHDL;




                                                  31
JK f/f with enable using if-then-else structure
architecture Behavioral of JK_FF_VHDL is
signal temp: std_logic;
begin
  process (Clock)
  begin
    if Clock'event and Clock='1' then
      if Reset='1' then temp <= '0';
        elsif Clock_enable ='1' then
          if (J='0' and K='0') then temp          <= temp;
            elsif (J='0' and K='1') then          temp <= '0';
            elsif (J='1' and K='0') then          temp <= '1';
            elsif (J='1' and K='1') then          temp <= not
(temp);
        end if;
      end if;
    end if;
  end process;
  Output <= temp;
end Behavioral;
                                                                 32

More Related Content

What's hot

DPSK(Differential Phase Shift Keying) transmitter and receiver
DPSK(Differential Phase Shift Keying) transmitter and receiverDPSK(Differential Phase Shift Keying) transmitter and receiver
DPSK(Differential Phase Shift Keying) transmitter and receiver
Sumukh Athrey
 

What's hot (20)

Programs of VHDL
Programs of VHDLPrograms of VHDL
Programs of VHDL
 
Introduction to VHDL - Part 1
Introduction to VHDL - Part 1Introduction to VHDL - Part 1
Introduction to VHDL - Part 1
 
verilog
verilogverilog
verilog
 
Logic synthesis,flootplan&placement
Logic synthesis,flootplan&placementLogic synthesis,flootplan&placement
Logic synthesis,flootplan&placement
 
Delays in verilog
Delays in verilogDelays in verilog
Delays in verilog
 
Chapter 5 introduction to VHDL
Chapter 5 introduction to VHDLChapter 5 introduction to VHDL
Chapter 5 introduction to VHDL
 
Data types in verilog
Data types in verilogData types in verilog
Data types in verilog
 
Vhdl introduction
Vhdl introductionVhdl introduction
Vhdl introduction
 
VHDL- data types
VHDL- data typesVHDL- data types
VHDL- data types
 
Unit v. HDL Synthesis Process
Unit v. HDL Synthesis ProcessUnit v. HDL Synthesis Process
Unit v. HDL Synthesis Process
 
System verilog important
System verilog importantSystem verilog important
System verilog important
 
DPSK(Differential Phase Shift Keying) transmitter and receiver
DPSK(Differential Phase Shift Keying) transmitter and receiverDPSK(Differential Phase Shift Keying) transmitter and receiver
DPSK(Differential Phase Shift Keying) transmitter and receiver
 
VHDL - Enumerated Types (Part 3)
VHDL - Enumerated Types (Part 3)VHDL - Enumerated Types (Part 3)
VHDL - Enumerated Types (Part 3)
 
Data flow model -Lecture-4
Data flow model -Lecture-4Data flow model -Lecture-4
Data flow model -Lecture-4
 
Modules and ports in Verilog HDL
Modules and ports in Verilog HDLModules and ports in Verilog HDL
Modules and ports in Verilog HDL
 
Digital system design practical file
Digital system design practical fileDigital system design practical file
Digital system design practical file
 
Introduction to HDLs
Introduction to HDLsIntroduction to HDLs
Introduction to HDLs
 
Verilog Tasks & Functions
Verilog Tasks & FunctionsVerilog Tasks & Functions
Verilog Tasks & Functions
 
Vhdl identifiers,data types
Vhdl identifiers,data typesVhdl identifiers,data types
Vhdl identifiers,data types
 
Verilog hdl
Verilog hdlVerilog hdl
Verilog hdl
 

Viewers also liked

Sequential Circuits - Flip Flops
Sequential Circuits - Flip FlopsSequential Circuits - Flip Flops
Sequential Circuits - Flip Flops
Abhilash Nair
 
Programmable array logic
Programmable array logicProgrammable array logic
Programmable array logic
Gaditek
 
Designing Clocked Synchronous State Machine
Designing Clocked Synchronous State MachineDesigning Clocked Synchronous State Machine
Designing Clocked Synchronous State Machine
Abhilash Nair
 
State Machine Design and Synthesis
State Machine Design and SynthesisState Machine Design and Synthesis
State Machine Design and Synthesis
Abhilash Nair
 
Experiment write-vhdl-code-for-realize-all-logic-gates
Experiment write-vhdl-code-for-realize-all-logic-gatesExperiment write-vhdl-code-for-realize-all-logic-gates
Experiment write-vhdl-code-for-realize-all-logic-gates
Ricardo Castro
 
Analysis of state machines & Conversion of models
Analysis of state machines & Conversion of modelsAnalysis of state machines & Conversion of models
Analysis of state machines & Conversion of models
Abhilash Nair
 

Viewers also liked (20)

Sequential Circuits - Flip Flops
Sequential Circuits - Flip FlopsSequential Circuits - Flip Flops
Sequential Circuits - Flip Flops
 
Synchronous design process
Synchronous design processSynchronous design process
Synchronous design process
 
Programmable array logic
Programmable array logicProgrammable array logic
Programmable array logic
 
MSI Shift Registers
MSI Shift RegistersMSI Shift Registers
MSI Shift Registers
 
Programmable Logic Array ( PLA )
Programmable Logic Array ( PLA )Programmable Logic Array ( PLA )
Programmable Logic Array ( PLA )
 
CPLDs
CPLDsCPLDs
CPLDs
 
Designing Clocked Synchronous State Machine
Designing Clocked Synchronous State MachineDesigning Clocked Synchronous State Machine
Designing Clocked Synchronous State Machine
 
State Machine Design and Synthesis
State Machine Design and SynthesisState Machine Design and Synthesis
State Machine Design and Synthesis
 
VHDL
VHDLVHDL
VHDL
 
Experiment write-vhdl-code-for-realize-all-logic-gates
Experiment write-vhdl-code-for-realize-all-logic-gatesExperiment write-vhdl-code-for-realize-all-logic-gates
Experiment write-vhdl-code-for-realize-all-logic-gates
 
Basics of Vhdl
Basics of VhdlBasics of Vhdl
Basics of Vhdl
 
Analysis of state machines & Conversion of models
Analysis of state machines & Conversion of modelsAnalysis of state machines & Conversion of models
Analysis of state machines & Conversion of models
 
Structural vhdl
Structural vhdlStructural vhdl
Structural vhdl
 
Summer training vhdl
Summer training vhdlSummer training vhdl
Summer training vhdl
 
DSD
DSDDSD
DSD
 
programmable logic array
programmable logic arrayprogrammable logic array
programmable logic array
 
FPLDs
FPLDsFPLDs
FPLDs
 
4 bit binary full subtractor
4 bit binary full subtractor4 bit binary full subtractor
4 bit binary full subtractor
 
4 bit add sub
4 bit add sub4 bit add sub
4 bit add sub
 
Vhdl design flow
Vhdl design flowVhdl design flow
Vhdl design flow
 

Similar to VHDL Part 4

vhdl.ppt Verilog Hardware Description Language
vhdl.ppt Verilog Hardware Description Languagevhdl.ppt Verilog Hardware Description Language
vhdl.ppt Verilog Hardware Description Language
shreenathji26
 

Similar to VHDL Part 4 (20)

Introduction to VHDL
Introduction to VHDLIntroduction to VHDL
Introduction to VHDL
 
FPGA training session generic package and funtions of VHDL by Digitronix Nepal
FPGA training session generic package and funtions of VHDL by Digitronix NepalFPGA training session generic package and funtions of VHDL by Digitronix Nepal
FPGA training session generic package and funtions of VHDL by Digitronix Nepal
 
VLSI Lab manual PDF
VLSI Lab manual PDFVLSI Lab manual PDF
VLSI Lab manual PDF
 
Vhdl 1 ppg
Vhdl 1 ppgVhdl 1 ppg
Vhdl 1 ppg
 
Spdas2 vlsibput
Spdas2 vlsibputSpdas2 vlsibput
Spdas2 vlsibput
 
Session 02 _rtl_design_with_vhdl 101
Session 02 _rtl_design_with_vhdl 101Session 02 _rtl_design_with_vhdl 101
Session 02 _rtl_design_with_vhdl 101
 
How to design Programs using VHDL
How to design Programs using VHDLHow to design Programs using VHDL
How to design Programs using VHDL
 
vhdl
vhdlvhdl
vhdl
 
Hardware Description Language
Hardware Description Language Hardware Description Language
Hardware Description Language
 
Digital Electronics .
Digital Electronics                                              .Digital Electronics                                              .
Digital Electronics .
 
Lecture-07 Modelling techniques.pdf
Lecture-07 Modelling techniques.pdfLecture-07 Modelling techniques.pdf
Lecture-07 Modelling techniques.pdf
 
slide8.ppt
slide8.pptslide8.ppt
slide8.ppt
 
VHDL Entity
VHDL EntityVHDL Entity
VHDL Entity
 
Basic Coding In VHDL COding
Basic Coding In VHDL COdingBasic Coding In VHDL COding
Basic Coding In VHDL COding
 
Session1
Session1Session1
Session1
 
Verilog
VerilogVerilog
Verilog
 
vhdl.ppt Verilog Hardware Description Language
vhdl.ppt Verilog Hardware Description Languagevhdl.ppt Verilog Hardware Description Language
vhdl.ppt Verilog Hardware Description Language
 
Vhdl
VhdlVhdl
Vhdl
 
dokumen.tips_logic-synthesis-report.pdf
dokumen.tips_logic-synthesis-report.pdfdokumen.tips_logic-synthesis-report.pdf
dokumen.tips_logic-synthesis-report.pdf
 
Vhdl new
Vhdl newVhdl new
Vhdl new
 

More from Abhilash Nair (19)

Feedback Sequential Circuits
Feedback Sequential CircuitsFeedback Sequential Circuits
Feedback Sequential Circuits
 
Designing State Machine
Designing State MachineDesigning State Machine
Designing State Machine
 
Analysis of state machines
Analysis of state machinesAnalysis of state machines
Analysis of state machines
 
Sequential Circuits - Flip Flops (Part 2)
Sequential Circuits - Flip Flops (Part 2)Sequential Circuits - Flip Flops (Part 2)
Sequential Circuits - Flip Flops (Part 2)
 
Sequential Circuits - Flip Flops (Part 1)
Sequential Circuits - Flip Flops (Part 1)Sequential Circuits - Flip Flops (Part 1)
Sequential Circuits - Flip Flops (Part 1)
 
FPGA
FPGAFPGA
FPGA
 
CPLDs
CPLDsCPLDs
CPLDs
 
CPLD & FPLD
CPLD & FPLDCPLD & FPLD
CPLD & FPLD
 
CPLDs
CPLDsCPLDs
CPLDs
 
Static and Dynamic Read/Write memories
Static and Dynamic Read/Write memoriesStatic and Dynamic Read/Write memories
Static and Dynamic Read/Write memories
 
Documentation Standards of an IC
Documentation Standards of an ICDocumentation Standards of an IC
Documentation Standards of an IC
 
Shift Registers
Shift RegistersShift Registers
Shift Registers
 
MSI Counters
MSI CountersMSI Counters
MSI Counters
 
EPROM, PROM & ROM
EPROM, PROM & ROMEPROM, PROM & ROM
EPROM, PROM & ROM
 
Counters
CountersCounters
Counters
 
Trends Of Televisions
Trends Of TelevisionsTrends Of Televisions
Trends Of Televisions
 
Core java slides
Core java slidesCore java slides
Core java slides
 
Vectors in Java
Vectors in JavaVectors in Java
Vectors in Java
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 

Recently uploaded

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
MateoGardella
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
SanaAli374401
 

Recently uploaded (20)

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 

VHDL Part 4

  • 1. Functions A function accepts a number of arguments and returns a result. Each of the arguments and the result in a function definition or function call have a predetermined type. When a function is called, the actual parameters in the function call are substituted for the formal parameters When a function is called from within an architecture, a value of the type return-type is returned in place of the function call A function may define its own local types, constants, variables and nested functions and procedures The keywords begin and end enclose a series of “sequential statements” that are executed when the function is called 1
  • 2. A simple example entity Inhibit is -- a.k.a. “but-not” as in “X but not Y” port (X,Y: in BIT; Z: out BIT); end Inhibit; -- end of entity declaration architecture Inhibit_arch of Inhibit is begin Z <= ‘1’ when X=‘1’ and Y=‘0’ else ‘0’; end Inhibit_arch -- end of architecture declaration 2
  • 3. But-not gate using a function architecture Inhibit_archf of Inhibit is function ButNot (A,B: bit) return bit is begin if B = ‘0’ then return A; else return ‘0’; end if; end ButNot; begin Z <= ButNot(X,Y); end Inhibit_archf 3
  • 4. Libraries A VHDL library is a place where the compiler stores information about a particular design project, including intermediate files that are used in the analysis, simulation and synthesis of the design. Library location is implementation-dependent For a given VHDL design, the compiler automatically creates and uses a library named “work”. When compiler analyzes each file in the design, it puts the results there. A complete VHDL design usually has multiple files, each containing different design units including entities and architectures. Not all the information needed in a design may be in the “work” library. 4
  • 5. Libraries A designer may rely on common definitions or functional modules across a family of different projects. Even small projects may use a standard library such as the one containing IEEE standard definitions The designer can specify the name of such a library using a library clause at the beginning of the design file. For example one can specify the IEEE library as library IEEE; Specifying a library name in a design gives it access to any previously analyzed entities and architectures stored in the library, but does not give access to type definitions and the like. This is the function of “packages” and “use clauses” 5
  • 6. Library statement in VHDL library ieee; -- needed if you want to use the ieee library library unisim; -- will see this in Xilinx-generated files library work; -- implicitly included in every VHDL file 6
  • 7. What’s in a package? A package is a file containing definitions of “objects” that can be used in other programs Is an ADA concept Like the entity-architecture pair, the package is another precursor to the OOP idea! “object” here means signals, types, constants, functions, procedures, components declarations, etc. NOT objects as in OOP. The kind of objects are signal, type, constant, function, procedure, and component declarations 7
  • 8. Packages Signals that are defined in a package are “global” signals, available to any VHDL entity that uses the package Types and constants defined in a package are known in any file that uses the package Likewise functions and procedures defined in a package can be called in files that use the package and components can be “instantiated” in architectures that use the package. To use a package you say “use” … for example: use ieee.std_logic_1164.all; -- use all definitions in pkg use ieee.std_logic_1164.std_ulogic -- use just def std_ulogic type 8
  • 9. Packages A design can use a package by including a use clause at the beginning of the design file To use all the definitions in the IEEE standard 1164 package one would write use ieee.std_logic_1164.all; Here “ieee” is the name of the library which has previously been given in the library clause Within the library , the file named “std_logic_1164” contains the desired definitions and the suffix “all” tells the compiler to use all of the definitions in this file Package is not limited to standard bodies, anyone can write a package using the proper syntax 9
  • 10. VHDL Design Styles VHDL Design Styles dataflow structural behavioral Concurrent Components and Sequential statements statements interconnects • Registers • State machines • Test benches Subset most suitable for synthesis 10
  • 11. VHDL Example Entity declaration for the 2 to 1 MUX ENTITY mux2_1 IS PORT (in0, in1, sel: IN STD_LOGIC; yout: OUT STD_LOGIC); END mux2_1; 11
  • 12. VHDL Example Logic circuit for a 2-1 MUX device Helpful for understanding architecture in1 sel yout in0 12
  • 13. Behavioral architecture for the 2 to 1 MUX ARCHITECTURE a1 OF mux2_1 IS P1: PROCESS (sel, in0, in1) BEGIN IF (sel = ‘0’) THEN yout <= in0; ELSE yout <= in1; END IF; END P1; END a1; in1 sel yout in0 13
  • 14. Structural architecture for the 2 to 1 MUX ARCHITECTURE a2 OF mux2_1 IS SIGNAL sel_not, in0_and, in1_and: STD_LOGIC; COMPONENT OR_GATE PORT(x,y: IN STD_LOGIC; z: OUT STD_LOGIC); COMPONENT AND_GATE PORT (x,y: IN STD_LOGIC; z: OUT STD_LOGIC); COMPONENT INV_GATE PORT (x: IN STD_LOGIC; z: OUT STD_LOGIC); BEGIN U1: AND_GATE PORT MAP (in0, sel_not, in0_and); U2: AND_GATE PORT MAP (in1, sel, in1_and); U3: INV_GATE PORT MAP (sel, sel_not); U4: OR_GATE PORT MAP (in0_and, in1_and, yout); END a2; in1 In1_and sel yout in0 In0_and sel_not 14
  • 15. Dataflow architecture for the 2 to 1 MUX ARCHITECTURE a3 OF mux2_1 IS BEGIN yout <= ((in0 AND NOT(sel)) OR (in1 AND sel)); END a3; In1 sel yout In0 15
  • 16. Half Adder Circuit Looking at the truth table for a half adder, it is easy to visualize the circuit AB CS A S B C 16
  • 17. Full Adder Circuit The circuit at right shows a half adder full adder constructed from two half adders. XOR generates the sum output AND generates the carry output half adder [ ] C = ( A ⋅ B + A ⋅ B ) ⋅ C ′ + ( A ⋅ B ) = ( A ⋅ B ⋅ C ′) + ( A ⋅ B ⋅ C ′) + ( A ⋅ B ) = ( A ⋅ C ′) + ( B ⋅ C ′) + ( A ⋅ B ) S = A ⊕ B ⊕ C′ 17
  • 18. -- Dataflow model for a full adder circuit -- Library Statement declares the ieee synthesis library LIBRARY ieee; USE ieee.std_logic_1164.ALL; -- Entity declaration ENTITY fulladder IS PORT(Ain, Bin, Cin: IN STD_LOGIC; Cout, Sout: OUT STD_LOGIC); END fulladder; -- Architecture defines the function -- In this case the function is defined using Boolean equations ARCHITECTURE dataflow OF fulladder IS BEGIN -- Concurrent Signal Assignment Statements Sout <= Ain XOR Bin XOR Cin; Cout <= (Ain AND Bin) OR (Ain AND Cin) OR (Bin AND Cin); END dataflow;
  • 19. -- Structural architecture is defined by a circuit ARCHITECTURE structural OF fulladder IS COMPONENT AND2 PORT( A, B: IN STD_LOGIC; F: OUT STD_LOGIC); END COMPONENT; COMPONENT OR3 PORT( A, B, C: IN STD_LOGIC; F: OUT STD_LOGIC); END COMPONENT; COMPONENT XOR2 PORT( A, B: IN STD_LOGIC; F: OUT STD_LOGIC); END COMPONENT; SIGNAL AXB, AB, BC, AC: STD_LOGIC; BEGIN F1: XOR2 port map (Ain, Bin, AXB); --Port Map Statements F2: XOR2 port map (AXB, Cin, Sout); F3: AND2 port map (Ain, Bin, AB); F4: AND2 port map (Bin, Cin, BC); F5: AND2 port map (Ain, Cin, AC); F6: OR3 port map (AB, BC, AC, Cout); END structural;
  • 20. Binary Addition: 4-Bit Numbers The following example illustrates the addition of two 4-bit numbers A(A3A2A1A0) and B(B3B2B1B0): 20
  • 21. Binary Addition: 4-Bit Numbers The addition can be split-up in bit slices Each slice performs the addition of the bits Ai, Bi and the Carry-in bit Ci Ci <= carry-out bit of the previous slice Each slice is simply a full adder 21
  • 22. 4-Bit Binary Adder Circuit for a 4-bit parallel binary adder constructed from full adder building blocks 22
  • 23. LIBRARY ieee; USE ieee.std_logic_1164.ALL; -- VHDL model of a 4-bit adder using four full adders ENTITY four_bit_adder_st IS PORT (A, B : IN STD_LOGIC_VECTOR(3 downto 0); SUM : OUT STD_LOGIC_VECTOR(3 downto 0); CIN : IN STD_LOGIC; COUT : OUT STD_LOGIC); END four_bit_adder_st; Cin Cout Internal Signals
  • 24. -- The architecture is a structural one. ARCHITECTURE structural OF four_bit_adder_st IS -- First all the components are declared. The full adder -- is declared only once, even though it will be used 4 times. COMPONENT fulladder PORT(Ain, Bin, Cin: IN STD_LOGIC; Cout, Sout: OUT STD_LOGIC); END COMPONENT; -- The full adders are connected by carry signals. These -- must be declared also. SIGNAL C : STD_LOGIC_VECTOR(1 to 3); -- Port map statements are used to define full adder -- instances and how they are connected. BEGIN F1: fulladder port map (A(0),B(0),CIN,C(1),SUM(0)); F2: fulladder port map (A(1),B(1),C(1),C(2),SUM(1)); F3: fulladder port map (A(2),B(2),C(2),C(3),SUM(2)); F4: fulladder port map (A(3),B(3),C(3),COUT,SUM(3)); END structural;
  • 25. -- The architecture in this case is a dataflow one ARCHITECTURE dataflow OF four_bit_add_df IS -- Again there will be internal carry signals that are not -- inputs or outputs. These must be declared as signals. SIGNAL C : STD_LOGIC_VECTOR(1 to 3); -- Concurrent signal assignments can be used to describe -- each of the 4 outputs and the carry signals. BEGIN SUM(0) <= A(0) XOR B(0) XOR Cin; C(1) <= (A(0) AND B(0)) OR (A(0) AND Cin) OR (B(0) AND Cin); SUM(1) <= A(1) XOR B(1) XOR C(1); C(2) <= (A(1) AND B(1)) OR (A(1) AND C(1)) OR (B(1) AND C(1)); SUM(2) <= A(2) XOR B(2) XOR C(2); C(3) <= (A(2) AND B(2)) OR (A(2) AND C(2)) OR (B(2) AND C(2)); SUM(3) <= A(3) XOR B(3) XOR C(3); COUT <= (A(3) AND B(3)) OR (A(3) AND C(3)) OR (B(3) AND C(3)); END dataflow;
  • 26. D latch with an async clear and level sensitivity library IEEE; use IEEE.Std_logic_1164.all; entity latch_wc is port (CLK, D, CLR: in Std_logic; Q: out Std_logic); end latch_wc; CLR Architecture design of latch_wc is begin process (CLK, D, CLR) begin if CLR = '1' then -- CLR active High Q <= '0'; elsif CLK = '1' then -- CLK active High Q <= D; -- note that Q is not assigned a value for CLK = '0' end if; end process; end design; 26
  • 27. D latch with asynch clear and rising-edge triggered library IEEE; use IEEE.Std_logic_1164.all; entity dff_wac is port (CLK, D, CLR: in Std_logic; Q: out Std_logic); CLR end dff_wac; Architecture design of dff_wac is begin process (CLK, D, CLR) begin if CLR = '1' then -- asynchronous CLR active High Q <= '0'; elsif (CLK'event and CLK='1') then Q <= D; -- CLK rising edge, CLK'event and CLK = '1' can be replaced by the "function" rising_edge (CLK) end if; end process; end design; 27
  • 28. T f-f with an asynch clear and rising edge triggered library IEEE; use IEEE.Std_logic_1164.all; entity t_ff is port (T, CLK, CLR: in std_logic; Q: buffer std_logic); end t_ff; CLR architecture design of t_ff is begin process (CLK, CLR, T) begin if (CLR = '1') then Q <= '0'; elsif rising_edge (CLK) then case T is when '0' => Q <= Q; when '1' => Q <= not Q; when others => Q <= '0'; end case; end if; 28 end process;
  • 29. JK f-f with an asynch reset and rising edge triggered library IEEE; use IEEE.Std_logic_1164.all; entity JK_FF is port (clock, J, K, reset: in std_logic; reset Q, Qbar: out std_logic); end JK_FF; architecture behv of JK_FF is signal state: std_logic; -- define the useful signals here signal input: std_logic_vector(1 downto 0); 29
  • 30. JK f-f with an asynch reset and rising edge triggered begin input <= J & K; -- combine inputs into 2-bit vector p: process(clock, reset) is begin if (reset='1') then state <= '0'; elsif (rising_edge(clock)) then case (input) is -- compare to the truth table when "11" => state <= not state; when "10" => state <= '1'; when "01" => state <= '0'; when others => null; end case; end if; end process; -- concurrent statements Q <= state; Qbar <= not state; end behv; reset 30
  • 31. JK f/f with enable using if-then-else structure library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity JK_FF_VHDL is port( J,K: in std_logic; Reset: in std_logic; Clock_enable: in std_logic; Clock: in std_logic; Output: out std_logic); end JK_FF_VHDL; 31
  • 32. JK f/f with enable using if-then-else structure architecture Behavioral of JK_FF_VHDL is signal temp: std_logic; begin process (Clock) begin if Clock'event and Clock='1' then if Reset='1' then temp <= '0'; elsif Clock_enable ='1' then if (J='0' and K='0') then temp <= temp; elsif (J='0' and K='1') then temp <= '0'; elsif (J='1' and K='0') then temp <= '1'; elsif (J='1' and K='1') then temp <= not (temp); end if; end if; end if; end process; Output <= temp; end Behavioral; 32