SlideShare a Scribd company logo
FPGA Training Session
Himalaya College of Engineering
FPGA-ARM Training Session HCOE
In Association with
VHDL: Generic , Package and
Functions
Generic
ENTITY and2 IS
GENERIC(rise, fall : TIME; load : INTEGER);
PORT( a, b : IN BIT;
PORT( c : OUT BIT);
END AND2;
ARCHITECTURE load_dependent OF and2 IS
SIGNAL internal : BIT;
BEGIN
internal <= a AND b;
c <= internal AFTER (rise + (load * 2 ns)) WHEN internal = ‘1’
ELSE internal AFTER (fall + (load * 3 ns));
END load_dependent;
• Generics are a general mechanism used
to pass information to an instance of an
entity.
• The information passed to the entity can
be of most types allowed in VHDL.
• Generics cannot be assigned information
as part of a simulation run.
• The information contained in generics
passed into a component instance or a
block can be used to alter the simulation
results, but results cannot modify the
generics.
Generic: Structural Modeling
ENTITY and2 IS
GENERIC(rise, fall : TIME; load : INTEGER);
PORT( a, b : IN BIT;
PORT( c : OUT BIT);
END AND2;
ARCHITECTURE load_dependent OF and2 IS
SIGNAL internal : BIT;
BEGIN
internal <= a AND b;
c <= internal AFTER (rise + (load * 2 ns)) WHEN internal = ‘1’
ELSE internal AFTER (fall + (load * 3 ns));
END load_dependent;
LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;
ENTITY test IS
GENERIC(rise, fall : TIME; load : INTEGER);
PORT ( ina, inb, inc, ind : IN std_logic;
PORT ( out1, out2 : OUT std_logic);
END test;
ARCHITECTURE test_arch OF test IS
COMPONENT AND2
GENERIC(rise, fall : TIME; load : INTEGER);
PORT ( a, b : IN std_logic;
PORT ( c : OUT std_logic);
END COMPONENT;
BEGIN
U1: AND2 GENERIC MAP(10 ns, 12 ns, 3 )
PORT MAP (ina, inb, out1 );
U2: AND2 GENERIC MAP(9 ns, 11 ns, 5 )
PORT MAP (inc, ind, out2 );
END test_arch;
Package
• The primary purpose of a package is to encapsulate elements that can be
shared (globally) among two or more design units.
• A package is a common storage area used to hold data to be shared among
a number of entities.
• Declaring data inside of a package allows the data to be referenced by
other entities; thus, the data can be shared.
• A package consists of two parts: a package declaration section and a
package body.
• The package declaration defines the interface for the package, much the
same way that the entity defines the interface for a model.
• The package body specifies the actual behavior of the package in the same
method that the architecture statement does for a model.
Package USE LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;
PACKAGE math IS
TYPE st16 IS ARRAY(0 TO 15) OF std_logic;
FUNCTION add(a, b: IN st16) RETURN st16;
FUNCTION sub(a, b: IN st16) RETURN st16;
END math;
PACKAGE BODY math IS
FUNCTION vect_to_int(S : st16) RETURN INTEGER IS
VARIABLE result : INTEGER := 0;
BEGIN
FOR i IN 0 TO 7 LOOP
result := result * 2;
IF S(i) = ‘1’ THEN
result := result + 1;
END IF;
END LOOP;
RETURN result;
END vect_to_int;
FUNCTION int_to_st16(s : INTEGER) RETURN st16 IS
VARIABLE result : st16;
VARIABLE digit : INTEGER := 2**15;
VARIABLE local : INTEGER;
BEGIN
local : = s;
FOR i IN 15 DOWNTO 0 LOOP
IF local/digit >>= 1 THEN
result(i) := ‘1’;
local := local - digit;
ELSE
result(i) := ‘0’;
END IF;
digit := digit/2;
END LOOP;
RETURN result;
END int_to_st16;
FUNCTION add(a, b: IN st16) RETURN st16 IS
VARIABLE result : INTEGER;
BEGIN
result := vect_to_int(a) + vect_to_int(b);
RETURN int_to_st16(result);
END add;
FUNCTION sub(a, b: IN st16) RETURN st16 IS
VARIABLE result : INTEGER;
BEGIN
result := vect_to_int(a) - vect_to_int(b);
RETURN int_to_st16(result);
END sub;
END math;
• Following is an
example of a
complete
package
making use of
this feature
Package: Block Statements
LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;
PACKAGE bit32 IS
TYPE tw32 IS ARRAY(31 DOWNTO 0) OF std_logic;
END bit32;
LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;
USE WORK.bit32.ALL;
ENTITY cpu IS
PORT( clk, interrupt : IN std_logic;
PORT( addr : OUT tw32; data : INOUT tw32 );
END cpu;
ARCHITECTURE cpu_blk OF cpu IS
SIGNAL ibus, dbus : tw32;
BEGIN
ALU : BLOCK
SIGNAL qbus : tw32;
BEGIN
-- alu behavior statements
END BLOCK ALU;
REG8 : BLOCK
SIGNAL zbus : tw32;
BEGIN
REG1: BLOCK
SIGNAL qbus : tw32;
BEGIN
-- reg1 behavioral statements
END BLOCK REG1;
-- more REG8 statements
END BLOCK REG8;
END cpu_blk;
• Blocks are a partitioning mechanism
within VHDL that allow the designer
to logically group areas of the model.
• The statement area in an architecture
can be broken into a number of
separate logical areas.
• For instance, if you are designing a
CPU, one block might be an ALU,
another a register bank, and another
a shifter.
• Each block represents a self-
contained area of the model.
• Each block can declare local signals,
types, constants, and so on.
• Any object that can be declared in the
architecture declaration section can
be declared in the block declaration
section.
Subprograms: Procedures and Functions
• A procedure can return more than one argument; a function always
returns just one.
• In a function, all parameters are input parameters; a procedure can
have input parameters, output parameters, and inout parameters.
• There are two versions of procedures and functions: a concurrent
procedure and concurrent function, and a sequential procedure and
sequential function.
• All statements inside of a subprogram are sequential.
Procedures
USE LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;
PROCEDURE vector_to_int (z : IN std_logic_vector;
x_flag : OUT BOOLEAN; q : INOUT INTEGER) IS
BEGIN
q := 0;
x_flag := false;
FOR i IN z’RANGE LOOP
q := q * 2;
IF z(i) = ‘1’ THEN
q := q + 1;
ELSIF z(i) /= F0 THEN
x_flag := TRUE;
END IF;
END LOOP;
END vector_to_int;
• Conversion from
an array of a
multivalued
type to an
integer
Function: Package
USE LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;
PACKAGE num_types IS
TYPE log8 IS ARRAY(0 TO 7) OF std_logic; --line 1
END num_types;
USE LIBRARY IEEE; USE IEEE.std_logic_1164.ALL;
USE WORK.num_types.ALL;
ENTITY convert IS
PORT(I1 : IN log8; --line 2
O1 : OUT INTEGER); --line 3
END convert;
ARCHITECTURE behave OF convert IS
FUNCTION vector_to_int(S : log8) --line 4
RETURN INTEGER is --line 5
VARIABLE result : INTEGER := 0; --line 6
BEGIN
FOR i IN 0 TO 7 LOOP --line 7
result := result * 2; --line 8
IF S(i) = ‘1’ THEN --line 9
result := result + 1; --line 10
END IF;
END LOOP;
RETURN result; --line 11
END vector_to_int;
BEGIN
O1 <= vector_to_int(I1); --line 12
END behave;
• The following
example is a
function that
takes in an array
of the std_logic
type- “Standard
Logic Package”
and returns an
integer value
Function: Package USE LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;
ENTITY dff IS
PORT(d, clk : IN std_logic;
PORT(q : OUT std_logic);
FUNCTION rising_edge(SIGNAL S : std_logic) --line 1
RETURN BOOLEAN IS --line 2
BEGIN
--this function makes use of attributes
--‘event and ‘last_value discussed
--in Chapter 6
IF (S’EVENT) AND (S = ‘1’) AND --line 3
(S’LAST_VALUE = ‘0’) THEN --line 4
RETURN TRUE; --line 5
ELSE
RETURN FALSE; --line 6
END IF;
END rising_edge;
END dff;
ARCHITECTURE behave OF dff IS
BEGIN
PROCESS( clk)
BEGIN
IF rising_edge(clk) THEN --line 7
q <= d; --line 8
END IF;
END PROCESS;
END behave;
• Following is an
example
showing a
function that
contains signal
parameters.
• provides a rising
edge detection
facility for the D
flip-flop being
modeled
Reference
• DL Perry “VHDL programming”
• Pong P Chu “FPGA design with VHDL”
FPGA-ARM Training Session HCOE
Thank You !
Ad

More Related Content

What's hot (20)

Verilog Tasks and functions
Verilog Tasks and functionsVerilog Tasks and functions
Verilog Tasks and functions
Vinchipsytm Vlsitraining
 
Verilog overview
Verilog overviewVerilog overview
Verilog overview
posdege
 
Verilog Lecture5 hust 2014
Verilog Lecture5 hust 2014Verilog Lecture5 hust 2014
Verilog Lecture5 hust 2014
Béo Tú
 
Basic structures in vhdl
Basic structures in vhdlBasic structures in vhdl
Basic structures in vhdl
Raj Mohan
 
Programs of VHDL
Programs of VHDLPrograms of VHDL
Programs of VHDL
Rkrishna Mishra
 
VHDL- gate level modelling
VHDL- gate level modellingVHDL- gate level modelling
VHDL- gate level modelling
VandanaPagar1
 
Notes: Verilog Part 1 - Overview - Hierarchical Modeling Concepts - Basics
Notes: Verilog Part 1 - Overview - Hierarchical Modeling Concepts - BasicsNotes: Verilog Part 1 - Overview - Hierarchical Modeling Concepts - Basics
Notes: Verilog Part 1 - Overview - Hierarchical Modeling Concepts - Basics
Jay Baxi
 
VHDL CODES
VHDL CODES VHDL CODES
VHDL CODES
OmkarDarekar6
 
Notes: Verilog Part 2 - Modules and Ports - Structural Modeling (Gate-Level M...
Notes: Verilog Part 2 - Modules and Ports - Structural Modeling (Gate-Level M...Notes: Verilog Part 2 - Modules and Ports - Structural Modeling (Gate-Level M...
Notes: Verilog Part 2 - Modules and Ports - Structural Modeling (Gate-Level M...
Jay Baxi
 
Vhdl programming
Vhdl programmingVhdl programming
Vhdl programming
Yogesh Mashalkar
 
VHDL Packages, Coding Styles for Arithmetic Operations and VHDL-200x Additions
VHDL Packages, Coding Styles for Arithmetic Operations and VHDL-200x AdditionsVHDL Packages, Coding Styles for Arithmetic Operations and VHDL-200x Additions
VHDL Packages, Coding Styles for Arithmetic Operations and VHDL-200x Additions
Amal Khailtash
 
Hd2
Hd2Hd2
Hd2
Prakash Rao
 
Usp notes unit6-8
Usp notes unit6-8Usp notes unit6-8
Usp notes unit6-8
Syed Mustafa
 
Vhdl basic unit-2
Vhdl basic unit-2Vhdl basic unit-2
Vhdl basic unit-2
Uvaraj Shanmugam
 
Behavioral modelling in VHDL
Behavioral modelling in VHDLBehavioral modelling in VHDL
Behavioral modelling in VHDL
Bhupendra Pratap Singh
 
Vhdl
VhdlVhdl
Vhdl
Neeraj Gupta
 
Introduction to VHDL
Introduction to VHDLIntroduction to VHDL
Introduction to VHDL
Yaser Kalifa
 
Verilog tutorial
Verilog tutorialVerilog tutorial
Verilog tutorial
Abhiraj Bohra
 
Coding verilog
Coding verilogCoding verilog
Coding verilog
umarjamil10000
 
Modern Java Workshop
Modern Java WorkshopModern Java Workshop
Modern Java Workshop
Simon Ritter
 
Verilog overview
Verilog overviewVerilog overview
Verilog overview
posdege
 
Verilog Lecture5 hust 2014
Verilog Lecture5 hust 2014Verilog Lecture5 hust 2014
Verilog Lecture5 hust 2014
Béo Tú
 
Basic structures in vhdl
Basic structures in vhdlBasic structures in vhdl
Basic structures in vhdl
Raj Mohan
 
VHDL- gate level modelling
VHDL- gate level modellingVHDL- gate level modelling
VHDL- gate level modelling
VandanaPagar1
 
Notes: Verilog Part 1 - Overview - Hierarchical Modeling Concepts - Basics
Notes: Verilog Part 1 - Overview - Hierarchical Modeling Concepts - BasicsNotes: Verilog Part 1 - Overview - Hierarchical Modeling Concepts - Basics
Notes: Verilog Part 1 - Overview - Hierarchical Modeling Concepts - Basics
Jay Baxi
 
Notes: Verilog Part 2 - Modules and Ports - Structural Modeling (Gate-Level M...
Notes: Verilog Part 2 - Modules and Ports - Structural Modeling (Gate-Level M...Notes: Verilog Part 2 - Modules and Ports - Structural Modeling (Gate-Level M...
Notes: Verilog Part 2 - Modules and Ports - Structural Modeling (Gate-Level M...
Jay Baxi
 
VHDL Packages, Coding Styles for Arithmetic Operations and VHDL-200x Additions
VHDL Packages, Coding Styles for Arithmetic Operations and VHDL-200x AdditionsVHDL Packages, Coding Styles for Arithmetic Operations and VHDL-200x Additions
VHDL Packages, Coding Styles for Arithmetic Operations and VHDL-200x Additions
Amal Khailtash
 
Introduction to VHDL
Introduction to VHDLIntroduction to VHDL
Introduction to VHDL
Yaser Kalifa
 
Modern Java Workshop
Modern Java WorkshopModern Java Workshop
Modern Java Workshop
Simon Ritter
 

Viewers also liked (17)

Building Hierarchy
Building HierarchyBuilding Hierarchy
Building Hierarchy
Mohamed Samy
 
RadioVerse
RadioVerseRadioVerse
RadioVerse
Analog Devices, Inc.
 
Brief Introduction to Parallella
Brief Introduction to ParallellaBrief Introduction to Parallella
Brief Introduction to Parallella
Somnath Mazumdar
 
Hardware Accelerated Software Defined Radio
Hardware Accelerated Software Defined Radio Hardware Accelerated Software Defined Radio
Hardware Accelerated Software Defined Radio
Tarik Kazaz
 
DME for ZYNQ FPGA - A new way to design your SOC
DME for ZYNQ FPGA - A new way to design your SOCDME for ZYNQ FPGA - A new way to design your SOC
DME for ZYNQ FPGA - A new way to design your SOC
Bengt Edlund
 
Axi protocol
Axi protocolAxi protocol
Axi protocol
Azad Mishra
 
RF Power Management Attach Training Module
RF Power Management Attach Training ModuleRF Power Management Attach Training Module
RF Power Management Attach Training Module
Analog Devices, Inc.
 
Integrating a custom AXI IP Core in Vivado for Xilinx Zynq FPGA based embedde...
Integrating a custom AXI IP Core in Vivado for Xilinx Zynq FPGA based embedde...Integrating a custom AXI IP Core in Vivado for Xilinx Zynq FPGA based embedde...
Integrating a custom AXI IP Core in Vivado for Xilinx Zynq FPGA based embedde...
Vincent Claes
 
Running FreeRTOS on Digilent Zybo board
Running FreeRTOS on Digilent Zybo boardRunning FreeRTOS on Digilent Zybo board
Running FreeRTOS on Digilent Zybo board
Vincent Claes
 
AntiPinchWithZynq
AntiPinchWithZynqAntiPinchWithZynq
AntiPinchWithZynq
Gopalakrishnan Krishnan
 
Zynq MPSoC勉強会 Codec編
Zynq MPSoC勉強会 Codec編Zynq MPSoC勉強会 Codec編
Zynq MPSoC勉強会 Codec編
Tetsuya Morizumi
 
axi protocol
axi protocolaxi protocol
axi protocol
Azad Mishra
 
Axi
AxiAxi
Axi
Vinchipsytm Vlsitraining
 
Zynq mp勉強会資料
Zynq mp勉強会資料Zynq mp勉強会資料
Zynq mp勉強会資料
一路 川染
 
FPGAアクセラレータの作り方
FPGAアクセラレータの作り方FPGAアクセラレータの作り方
FPGAアクセラレータの作り方
Mr. Vengineer
 
Software defined radio technology : ITB research activities
Software defined radio technology : ITB research activitiesSoftware defined radio technology : ITB research activities
Software defined radio technology : ITB research activities
Dr.Joko Suryana
 
ZynqMPのQEMU
ZynqMPのQEMUZynqMPのQEMU
ZynqMPのQEMU
Mr. Vengineer
 
Building Hierarchy
Building HierarchyBuilding Hierarchy
Building Hierarchy
Mohamed Samy
 
Brief Introduction to Parallella
Brief Introduction to ParallellaBrief Introduction to Parallella
Brief Introduction to Parallella
Somnath Mazumdar
 
Hardware Accelerated Software Defined Radio
Hardware Accelerated Software Defined Radio Hardware Accelerated Software Defined Radio
Hardware Accelerated Software Defined Radio
Tarik Kazaz
 
DME for ZYNQ FPGA - A new way to design your SOC
DME for ZYNQ FPGA - A new way to design your SOCDME for ZYNQ FPGA - A new way to design your SOC
DME for ZYNQ FPGA - A new way to design your SOC
Bengt Edlund
 
RF Power Management Attach Training Module
RF Power Management Attach Training ModuleRF Power Management Attach Training Module
RF Power Management Attach Training Module
Analog Devices, Inc.
 
Integrating a custom AXI IP Core in Vivado for Xilinx Zynq FPGA based embedde...
Integrating a custom AXI IP Core in Vivado for Xilinx Zynq FPGA based embedde...Integrating a custom AXI IP Core in Vivado for Xilinx Zynq FPGA based embedde...
Integrating a custom AXI IP Core in Vivado for Xilinx Zynq FPGA based embedde...
Vincent Claes
 
Running FreeRTOS on Digilent Zybo board
Running FreeRTOS on Digilent Zybo boardRunning FreeRTOS on Digilent Zybo board
Running FreeRTOS on Digilent Zybo board
Vincent Claes
 
Zynq MPSoC勉強会 Codec編
Zynq MPSoC勉強会 Codec編Zynq MPSoC勉強会 Codec編
Zynq MPSoC勉強会 Codec編
Tetsuya Morizumi
 
Zynq mp勉強会資料
Zynq mp勉強会資料Zynq mp勉強会資料
Zynq mp勉強会資料
一路 川染
 
FPGAアクセラレータの作り方
FPGAアクセラレータの作り方FPGAアクセラレータの作り方
FPGAアクセラレータの作り方
Mr. Vengineer
 
Software defined radio technology : ITB research activities
Software defined radio technology : ITB research activitiesSoftware defined radio technology : ITB research activities
Software defined radio technology : ITB research activities
Dr.Joko Suryana
 
Ad

Similar to FPGA training session generic package and funtions of VHDL by Digitronix Nepal (20)

Ddhdl 17
Ddhdl 17Ddhdl 17
Ddhdl 17
Akhil Maddineni
 
VHDL Part 4
VHDL Part 4VHDL Part 4
VHDL Part 4
Abhilash Nair
 
Practical file
Practical filePractical file
Practical file
rajeevkr35
 
Vhdl introduction
Vhdl introductionVhdl introduction
Vhdl introduction
Dhaval Shukla
 
Basic Coding In VHDL COding
Basic Coding In VHDL COdingBasic Coding In VHDL COding
Basic Coding In VHDL COding
anna university
 
Digital Electronics .
Digital Electronics                                              .Digital Electronics                                              .
Digital Electronics .
inian2
 
VHDL-Behavioral-Programs-Structure of VHDL
VHDL-Behavioral-Programs-Structure of VHDLVHDL-Behavioral-Programs-Structure of VHDL
VHDL-Behavioral-Programs-Structure of VHDL
Revathi Subramaniam
 
Digital system design practical file
Digital system design practical fileDigital system design practical file
Digital system design practical file
Archita Misra
 
Spdas2 vlsibput
Spdas2 vlsibputSpdas2 vlsibput
Spdas2 vlsibput
GIET,Bhubaneswar
 
Session1
Session1Session1
Session1
omarAbdelrhman2
 
VHDL Programs
VHDL ProgramsVHDL Programs
VHDL Programs
Dr. A. B. Shinde
 
Create your first model for a simple logic circuit
Create your first model for a simple logic circuitCreate your first model for a simple logic circuit
Create your first model for a simple logic circuit
Mohamed Samy
 
Basics of Vhdl
Basics of VhdlBasics of Vhdl
Basics of Vhdl
Atchyuth Sonti
 
Verilogspk1
Verilogspk1Verilogspk1
Verilogspk1
supriya kurlekar
 
Vhd lhigh2003
Vhd lhigh2003Vhd lhigh2003
Vhd lhigh2003
gkumawat
 
Digital System Design Lab Report - VHDL ECE
Digital System Design Lab Report - VHDL ECEDigital System Design Lab Report - VHDL ECE
Digital System Design Lab Report - VHDL ECE
Ramesh Naik Bhukya
 
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
Mahmoud Abdellatif
 
An Overview of SystemVerilog for Design and Verification
An Overview of SystemVerilog  for Design and VerificationAn Overview of SystemVerilog  for Design and Verification
An Overview of SystemVerilog for Design and Verification
KapilRaghunandanTrip
 
VAC Course VHDL.ppt value added course b. Tech
VAC Course VHDL.ppt value added course b. TechVAC Course VHDL.ppt value added course b. Tech
VAC Course VHDL.ppt value added course b. Tech
mukulgrd1
 
Verilog Final Probe'22.pptx
Verilog Final Probe'22.pptxVerilog Final Probe'22.pptx
Verilog Final Probe'22.pptx
SyedAzim6
 
Practical file
Practical filePractical file
Practical file
rajeevkr35
 
Basic Coding In VHDL COding
Basic Coding In VHDL COdingBasic Coding In VHDL COding
Basic Coding In VHDL COding
anna university
 
Digital Electronics .
Digital Electronics                                              .Digital Electronics                                              .
Digital Electronics .
inian2
 
VHDL-Behavioral-Programs-Structure of VHDL
VHDL-Behavioral-Programs-Structure of VHDLVHDL-Behavioral-Programs-Structure of VHDL
VHDL-Behavioral-Programs-Structure of VHDL
Revathi Subramaniam
 
Digital system design practical file
Digital system design practical fileDigital system design practical file
Digital system design practical file
Archita Misra
 
Create your first model for a simple logic circuit
Create your first model for a simple logic circuitCreate your first model for a simple logic circuit
Create your first model for a simple logic circuit
Mohamed Samy
 
Vhd lhigh2003
Vhd lhigh2003Vhd lhigh2003
Vhd lhigh2003
gkumawat
 
Digital System Design Lab Report - VHDL ECE
Digital System Design Lab Report - VHDL ECEDigital System Design Lab Report - VHDL ECE
Digital System Design Lab Report - VHDL ECE
Ramesh Naik Bhukya
 
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
Mahmoud Abdellatif
 
An Overview of SystemVerilog for Design and Verification
An Overview of SystemVerilog  for Design and VerificationAn Overview of SystemVerilog  for Design and Verification
An Overview of SystemVerilog for Design and Verification
KapilRaghunandanTrip
 
VAC Course VHDL.ppt value added course b. Tech
VAC Course VHDL.ppt value added course b. TechVAC Course VHDL.ppt value added course b. Tech
VAC Course VHDL.ppt value added course b. Tech
mukulgrd1
 
Verilog Final Probe'22.pptx
Verilog Final Probe'22.pptxVerilog Final Probe'22.pptx
Verilog Final Probe'22.pptx
SyedAzim6
 
Ad

More from Krishna Gaihre (9)

Electronic Hardware Design with FPGA
Electronic Hardware Design with FPGAElectronic Hardware Design with FPGA
Electronic Hardware Design with FPGA
Krishna Gaihre
 
Freelancing on FPGA Design [How & Where to get Freelancing on FPGA]
Freelancing on FPGA Design [How & Where to get Freelancing on FPGA]Freelancing on FPGA Design [How & Where to get Freelancing on FPGA]
Freelancing on FPGA Design [How & Where to get Freelancing on FPGA]
Krishna Gaihre
 
How to Create and Program Flash PROM XCf04s on Spartan 3E
How to Create and Program Flash PROM XCf04s on Spartan 3EHow to Create and Program Flash PROM XCf04s on Spartan 3E
How to Create and Program Flash PROM XCf04s on Spartan 3E
Krishna Gaihre
 
FPGA Design Challenges
FPGA Design ChallengesFPGA Design Challenges
FPGA Design Challenges
Krishna Gaihre
 
FPGA Selection Methodology for Real time projects
FPGA Selection Methodology for Real time projectsFPGA Selection Methodology for Real time projects
FPGA Selection Methodology for Real time projects
Krishna Gaihre
 
FPGA Board Selection for Beginners
FPGA Board Selection for BeginnersFPGA Board Selection for Beginners
FPGA Board Selection for Beginners
Krishna Gaihre
 
Innovation & entrepreneurship scenario and strategies
Innovation & entrepreneurship scenario and strategiesInnovation & entrepreneurship scenario and strategies
Innovation & entrepreneurship scenario and strategies
Krishna Gaihre
 
E learning with raspberry pi based minicomputer krishna gaihre
E learning with raspberry pi based minicomputer krishna gaihreE learning with raspberry pi based minicomputer krishna gaihre
E learning with raspberry pi based minicomputer krishna gaihre
Krishna Gaihre
 
Remote sensing in space krishna
Remote sensing in space krishnaRemote sensing in space krishna
Remote sensing in space krishna
Krishna Gaihre
 
Electronic Hardware Design with FPGA
Electronic Hardware Design with FPGAElectronic Hardware Design with FPGA
Electronic Hardware Design with FPGA
Krishna Gaihre
 
Freelancing on FPGA Design [How & Where to get Freelancing on FPGA]
Freelancing on FPGA Design [How & Where to get Freelancing on FPGA]Freelancing on FPGA Design [How & Where to get Freelancing on FPGA]
Freelancing on FPGA Design [How & Where to get Freelancing on FPGA]
Krishna Gaihre
 
How to Create and Program Flash PROM XCf04s on Spartan 3E
How to Create and Program Flash PROM XCf04s on Spartan 3EHow to Create and Program Flash PROM XCf04s on Spartan 3E
How to Create and Program Flash PROM XCf04s on Spartan 3E
Krishna Gaihre
 
FPGA Design Challenges
FPGA Design ChallengesFPGA Design Challenges
FPGA Design Challenges
Krishna Gaihre
 
FPGA Selection Methodology for Real time projects
FPGA Selection Methodology for Real time projectsFPGA Selection Methodology for Real time projects
FPGA Selection Methodology for Real time projects
Krishna Gaihre
 
FPGA Board Selection for Beginners
FPGA Board Selection for BeginnersFPGA Board Selection for Beginners
FPGA Board Selection for Beginners
Krishna Gaihre
 
Innovation & entrepreneurship scenario and strategies
Innovation & entrepreneurship scenario and strategiesInnovation & entrepreneurship scenario and strategies
Innovation & entrepreneurship scenario and strategies
Krishna Gaihre
 
E learning with raspberry pi based minicomputer krishna gaihre
E learning with raspberry pi based minicomputer krishna gaihreE learning with raspberry pi based minicomputer krishna gaihre
E learning with raspberry pi based minicomputer krishna gaihre
Krishna Gaihre
 
Remote sensing in space krishna
Remote sensing in space krishnaRemote sensing in space krishna
Remote sensing in space krishna
Krishna Gaihre
 

Recently uploaded (20)

🚀 TDX Bengaluru 2025 Unwrapped: Key Highlights, Innovations & Trailblazer Tak...
🚀 TDX Bengaluru 2025 Unwrapped: Key Highlights, Innovations & Trailblazer Tak...🚀 TDX Bengaluru 2025 Unwrapped: Key Highlights, Innovations & Trailblazer Tak...
🚀 TDX Bengaluru 2025 Unwrapped: Key Highlights, Innovations & Trailblazer Tak...
SanjeetMishra29
 
[PyCon US 2025] Scaling the Mountain_ A Framework for Tackling Large-Scale Te...
[PyCon US 2025] Scaling the Mountain_ A Framework for Tackling Large-Scale Te...[PyCon US 2025] Scaling the Mountain_ A Framework for Tackling Large-Scale Te...
[PyCon US 2025] Scaling the Mountain_ A Framework for Tackling Large-Scale Te...
Jimmy Lai
 
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic AlgorithmDesign Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Journal of Soft Computing in Civil Engineering
 
Slide share PPT of NOx control technologies.pptx
Slide share PPT of  NOx control technologies.pptxSlide share PPT of  NOx control technologies.pptx
Slide share PPT of NOx control technologies.pptx
vvsasane
 
Construction Materials (Paints) in Civil Engineering
Construction Materials (Paints) in Civil EngineeringConstruction Materials (Paints) in Civil Engineering
Construction Materials (Paints) in Civil Engineering
Lavish Kashyap
 
Machine foundation notes for civil engineering students
Machine foundation notes for civil engineering studentsMachine foundation notes for civil engineering students
Machine foundation notes for civil engineering students
DYPCET
 
Optimizing Reinforced Concrete Cantilever Retaining Walls Using Gases Brownia...
Optimizing Reinforced Concrete Cantilever Retaining Walls Using Gases Brownia...Optimizing Reinforced Concrete Cantilever Retaining Walls Using Gases Brownia...
Optimizing Reinforced Concrete Cantilever Retaining Walls Using Gases Brownia...
Journal of Soft Computing in Civil Engineering
 
01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf
01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf
01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf
PawachMetharattanara
 
22PCOAM16 Unit 3 Session 23 Different ways to Combine Classifiers.pptx
22PCOAM16 Unit 3 Session 23  Different ways to Combine Classifiers.pptx22PCOAM16 Unit 3 Session 23  Different ways to Combine Classifiers.pptx
22PCOAM16 Unit 3 Session 23 Different ways to Combine Classifiers.pptx
Guru Nanak Technical Institutions
 
860556374-10280271.pptx PETROLEUM COKE CALCINATION PLANT
860556374-10280271.pptx PETROLEUM COKE CALCINATION PLANT860556374-10280271.pptx PETROLEUM COKE CALCINATION PLANT
860556374-10280271.pptx PETROLEUM COKE CALCINATION PLANT
Pierre Celestin Eyock
 
Modeling the Influence of Environmental Factors on Concrete Evaporation Rate
Modeling the Influence of Environmental Factors on Concrete Evaporation RateModeling the Influence of Environmental Factors on Concrete Evaporation Rate
Modeling the Influence of Environmental Factors on Concrete Evaporation Rate
Journal of Soft Computing in Civil Engineering
 
Control Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptxControl Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptx
vvsasane
 
Zeiss-Ultra-Optimeter metrology subject.pdf
Zeiss-Ultra-Optimeter metrology subject.pdfZeiss-Ultra-Optimeter metrology subject.pdf
Zeiss-Ultra-Optimeter metrology subject.pdf
Saikumar174642
 
Water Industry Process Automation & Control Monthly May 2025
Water Industry Process Automation & Control Monthly May 2025Water Industry Process Automation & Control Monthly May 2025
Water Industry Process Automation & Control Monthly May 2025
Water Industry Process Automation & Control
 
698642933-DdocfordownloadEEP-FAKE-PPT.pptx
698642933-DdocfordownloadEEP-FAKE-PPT.pptx698642933-DdocfordownloadEEP-FAKE-PPT.pptx
698642933-DdocfordownloadEEP-FAKE-PPT.pptx
speedcomcyber25
 
OPTIMIZING DATA INTEROPERABILITY IN AGILE ORGANIZATIONS: INTEGRATING NONAKA’S...
OPTIMIZING DATA INTEROPERABILITY IN AGILE ORGANIZATIONS: INTEGRATING NONAKA’S...OPTIMIZING DATA INTEROPERABILITY IN AGILE ORGANIZATIONS: INTEGRATING NONAKA’S...
OPTIMIZING DATA INTEROPERABILITY IN AGILE ORGANIZATIONS: INTEGRATING NONAKA’S...
ijdmsjournal
 
Mode-Wise Corridor Level Travel-Time Estimation Using Machine Learning Models
Mode-Wise Corridor Level Travel-Time Estimation Using Machine Learning ModelsMode-Wise Corridor Level Travel-Time Estimation Using Machine Learning Models
Mode-Wise Corridor Level Travel-Time Estimation Using Machine Learning Models
Journal of Soft Computing in Civil Engineering
 
UNIT 3 Software Engineering (BCS601) EIOV.pdf
UNIT 3 Software Engineering (BCS601) EIOV.pdfUNIT 3 Software Engineering (BCS601) EIOV.pdf
UNIT 3 Software Engineering (BCS601) EIOV.pdf
sikarwaramit089
 
22PCOAM16 ML Unit 3 Full notes PDF & QB.pdf
22PCOAM16 ML Unit 3 Full notes PDF & QB.pdf22PCOAM16 ML Unit 3 Full notes PDF & QB.pdf
22PCOAM16 ML Unit 3 Full notes PDF & QB.pdf
Guru Nanak Technical Institutions
 
hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .
NABLAS株式会社
 
🚀 TDX Bengaluru 2025 Unwrapped: Key Highlights, Innovations & Trailblazer Tak...
🚀 TDX Bengaluru 2025 Unwrapped: Key Highlights, Innovations & Trailblazer Tak...🚀 TDX Bengaluru 2025 Unwrapped: Key Highlights, Innovations & Trailblazer Tak...
🚀 TDX Bengaluru 2025 Unwrapped: Key Highlights, Innovations & Trailblazer Tak...
SanjeetMishra29
 
[PyCon US 2025] Scaling the Mountain_ A Framework for Tackling Large-Scale Te...
[PyCon US 2025] Scaling the Mountain_ A Framework for Tackling Large-Scale Te...[PyCon US 2025] Scaling the Mountain_ A Framework for Tackling Large-Scale Te...
[PyCon US 2025] Scaling the Mountain_ A Framework for Tackling Large-Scale Te...
Jimmy Lai
 
Slide share PPT of NOx control technologies.pptx
Slide share PPT of  NOx control technologies.pptxSlide share PPT of  NOx control technologies.pptx
Slide share PPT of NOx control technologies.pptx
vvsasane
 
Construction Materials (Paints) in Civil Engineering
Construction Materials (Paints) in Civil EngineeringConstruction Materials (Paints) in Civil Engineering
Construction Materials (Paints) in Civil Engineering
Lavish Kashyap
 
Machine foundation notes for civil engineering students
Machine foundation notes for civil engineering studentsMachine foundation notes for civil engineering students
Machine foundation notes for civil engineering students
DYPCET
 
01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf
01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf
01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf
PawachMetharattanara
 
22PCOAM16 Unit 3 Session 23 Different ways to Combine Classifiers.pptx
22PCOAM16 Unit 3 Session 23  Different ways to Combine Classifiers.pptx22PCOAM16 Unit 3 Session 23  Different ways to Combine Classifiers.pptx
22PCOAM16 Unit 3 Session 23 Different ways to Combine Classifiers.pptx
Guru Nanak Technical Institutions
 
860556374-10280271.pptx PETROLEUM COKE CALCINATION PLANT
860556374-10280271.pptx PETROLEUM COKE CALCINATION PLANT860556374-10280271.pptx PETROLEUM COKE CALCINATION PLANT
860556374-10280271.pptx PETROLEUM COKE CALCINATION PLANT
Pierre Celestin Eyock
 
Control Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptxControl Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptx
vvsasane
 
Zeiss-Ultra-Optimeter metrology subject.pdf
Zeiss-Ultra-Optimeter metrology subject.pdfZeiss-Ultra-Optimeter metrology subject.pdf
Zeiss-Ultra-Optimeter metrology subject.pdf
Saikumar174642
 
698642933-DdocfordownloadEEP-FAKE-PPT.pptx
698642933-DdocfordownloadEEP-FAKE-PPT.pptx698642933-DdocfordownloadEEP-FAKE-PPT.pptx
698642933-DdocfordownloadEEP-FAKE-PPT.pptx
speedcomcyber25
 
OPTIMIZING DATA INTEROPERABILITY IN AGILE ORGANIZATIONS: INTEGRATING NONAKA’S...
OPTIMIZING DATA INTEROPERABILITY IN AGILE ORGANIZATIONS: INTEGRATING NONAKA’S...OPTIMIZING DATA INTEROPERABILITY IN AGILE ORGANIZATIONS: INTEGRATING NONAKA’S...
OPTIMIZING DATA INTEROPERABILITY IN AGILE ORGANIZATIONS: INTEGRATING NONAKA’S...
ijdmsjournal
 
UNIT 3 Software Engineering (BCS601) EIOV.pdf
UNIT 3 Software Engineering (BCS601) EIOV.pdfUNIT 3 Software Engineering (BCS601) EIOV.pdf
UNIT 3 Software Engineering (BCS601) EIOV.pdf
sikarwaramit089
 
hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .
NABLAS株式会社
 

FPGA training session generic package and funtions of VHDL by Digitronix Nepal

  • 1. FPGA Training Session Himalaya College of Engineering FPGA-ARM Training Session HCOE In Association with
  • 2. VHDL: Generic , Package and Functions
  • 3. Generic ENTITY and2 IS GENERIC(rise, fall : TIME; load : INTEGER); PORT( a, b : IN BIT; PORT( c : OUT BIT); END AND2; ARCHITECTURE load_dependent OF and2 IS SIGNAL internal : BIT; BEGIN internal <= a AND b; c <= internal AFTER (rise + (load * 2 ns)) WHEN internal = ‘1’ ELSE internal AFTER (fall + (load * 3 ns)); END load_dependent; • Generics are a general mechanism used to pass information to an instance of an entity. • The information passed to the entity can be of most types allowed in VHDL. • Generics cannot be assigned information as part of a simulation run. • The information contained in generics passed into a component instance or a block can be used to alter the simulation results, but results cannot modify the generics.
  • 4. Generic: Structural Modeling ENTITY and2 IS GENERIC(rise, fall : TIME; load : INTEGER); PORT( a, b : IN BIT; PORT( c : OUT BIT); END AND2; ARCHITECTURE load_dependent OF and2 IS SIGNAL internal : BIT; BEGIN internal <= a AND b; c <= internal AFTER (rise + (load * 2 ns)) WHEN internal = ‘1’ ELSE internal AFTER (fall + (load * 3 ns)); END load_dependent; LIBRARY IEEE; USE IEEE.std_logic_1164.ALL; ENTITY test IS GENERIC(rise, fall : TIME; load : INTEGER); PORT ( ina, inb, inc, ind : IN std_logic; PORT ( out1, out2 : OUT std_logic); END test; ARCHITECTURE test_arch OF test IS COMPONENT AND2 GENERIC(rise, fall : TIME; load : INTEGER); PORT ( a, b : IN std_logic; PORT ( c : OUT std_logic); END COMPONENT; BEGIN U1: AND2 GENERIC MAP(10 ns, 12 ns, 3 ) PORT MAP (ina, inb, out1 ); U2: AND2 GENERIC MAP(9 ns, 11 ns, 5 ) PORT MAP (inc, ind, out2 ); END test_arch;
  • 5. Package • The primary purpose of a package is to encapsulate elements that can be shared (globally) among two or more design units. • A package is a common storage area used to hold data to be shared among a number of entities. • Declaring data inside of a package allows the data to be referenced by other entities; thus, the data can be shared. • A package consists of two parts: a package declaration section and a package body. • The package declaration defines the interface for the package, much the same way that the entity defines the interface for a model. • The package body specifies the actual behavior of the package in the same method that the architecture statement does for a model.
  • 6. Package USE LIBRARY IEEE; USE IEEE.std_logic_1164.ALL; PACKAGE math IS TYPE st16 IS ARRAY(0 TO 15) OF std_logic; FUNCTION add(a, b: IN st16) RETURN st16; FUNCTION sub(a, b: IN st16) RETURN st16; END math; PACKAGE BODY math IS FUNCTION vect_to_int(S : st16) RETURN INTEGER IS VARIABLE result : INTEGER := 0; BEGIN FOR i IN 0 TO 7 LOOP result := result * 2; IF S(i) = ‘1’ THEN result := result + 1; END IF; END LOOP; RETURN result; END vect_to_int; FUNCTION int_to_st16(s : INTEGER) RETURN st16 IS VARIABLE result : st16; VARIABLE digit : INTEGER := 2**15; VARIABLE local : INTEGER; BEGIN local : = s; FOR i IN 15 DOWNTO 0 LOOP IF local/digit >>= 1 THEN result(i) := ‘1’; local := local - digit; ELSE result(i) := ‘0’; END IF; digit := digit/2; END LOOP; RETURN result; END int_to_st16; FUNCTION add(a, b: IN st16) RETURN st16 IS VARIABLE result : INTEGER; BEGIN result := vect_to_int(a) + vect_to_int(b); RETURN int_to_st16(result); END add; FUNCTION sub(a, b: IN st16) RETURN st16 IS VARIABLE result : INTEGER; BEGIN result := vect_to_int(a) - vect_to_int(b); RETURN int_to_st16(result); END sub; END math; • Following is an example of a complete package making use of this feature
  • 7. Package: Block Statements LIBRARY IEEE; USE IEEE.std_logic_1164.ALL; PACKAGE bit32 IS TYPE tw32 IS ARRAY(31 DOWNTO 0) OF std_logic; END bit32; LIBRARY IEEE; USE IEEE.std_logic_1164.ALL; USE WORK.bit32.ALL; ENTITY cpu IS PORT( clk, interrupt : IN std_logic; PORT( addr : OUT tw32; data : INOUT tw32 ); END cpu; ARCHITECTURE cpu_blk OF cpu IS SIGNAL ibus, dbus : tw32; BEGIN ALU : BLOCK SIGNAL qbus : tw32; BEGIN -- alu behavior statements END BLOCK ALU; REG8 : BLOCK SIGNAL zbus : tw32; BEGIN REG1: BLOCK SIGNAL qbus : tw32; BEGIN -- reg1 behavioral statements END BLOCK REG1; -- more REG8 statements END BLOCK REG8; END cpu_blk; • Blocks are a partitioning mechanism within VHDL that allow the designer to logically group areas of the model. • The statement area in an architecture can be broken into a number of separate logical areas. • For instance, if you are designing a CPU, one block might be an ALU, another a register bank, and another a shifter. • Each block represents a self- contained area of the model. • Each block can declare local signals, types, constants, and so on. • Any object that can be declared in the architecture declaration section can be declared in the block declaration section.
  • 8. Subprograms: Procedures and Functions • A procedure can return more than one argument; a function always returns just one. • In a function, all parameters are input parameters; a procedure can have input parameters, output parameters, and inout parameters. • There are two versions of procedures and functions: a concurrent procedure and concurrent function, and a sequential procedure and sequential function. • All statements inside of a subprogram are sequential.
  • 9. Procedures USE LIBRARY IEEE; USE IEEE.std_logic_1164.ALL; PROCEDURE vector_to_int (z : IN std_logic_vector; x_flag : OUT BOOLEAN; q : INOUT INTEGER) IS BEGIN q := 0; x_flag := false; FOR i IN z’RANGE LOOP q := q * 2; IF z(i) = ‘1’ THEN q := q + 1; ELSIF z(i) /= F0 THEN x_flag := TRUE; END IF; END LOOP; END vector_to_int; • Conversion from an array of a multivalued type to an integer
  • 10. Function: Package USE LIBRARY IEEE; USE IEEE.std_logic_1164.ALL; PACKAGE num_types IS TYPE log8 IS ARRAY(0 TO 7) OF std_logic; --line 1 END num_types; USE LIBRARY IEEE; USE IEEE.std_logic_1164.ALL; USE WORK.num_types.ALL; ENTITY convert IS PORT(I1 : IN log8; --line 2 O1 : OUT INTEGER); --line 3 END convert; ARCHITECTURE behave OF convert IS FUNCTION vector_to_int(S : log8) --line 4 RETURN INTEGER is --line 5 VARIABLE result : INTEGER := 0; --line 6 BEGIN FOR i IN 0 TO 7 LOOP --line 7 result := result * 2; --line 8 IF S(i) = ‘1’ THEN --line 9 result := result + 1; --line 10 END IF; END LOOP; RETURN result; --line 11 END vector_to_int; BEGIN O1 <= vector_to_int(I1); --line 12 END behave; • The following example is a function that takes in an array of the std_logic type- “Standard Logic Package” and returns an integer value
  • 11. Function: Package USE LIBRARY IEEE; USE IEEE.std_logic_1164.ALL; ENTITY dff IS PORT(d, clk : IN std_logic; PORT(q : OUT std_logic); FUNCTION rising_edge(SIGNAL S : std_logic) --line 1 RETURN BOOLEAN IS --line 2 BEGIN --this function makes use of attributes --‘event and ‘last_value discussed --in Chapter 6 IF (S’EVENT) AND (S = ‘1’) AND --line 3 (S’LAST_VALUE = ‘0’) THEN --line 4 RETURN TRUE; --line 5 ELSE RETURN FALSE; --line 6 END IF; END rising_edge; END dff; ARCHITECTURE behave OF dff IS BEGIN PROCESS( clk) BEGIN IF rising_edge(clk) THEN --line 7 q <= d; --line 8 END IF; END PROCESS; END behave; • Following is an example showing a function that contains signal parameters. • provides a rising edge detection facility for the D flip-flop being modeled
  • 12. Reference • DL Perry “VHDL programming” • Pong P Chu “FPGA design with VHDL”
  • 13. FPGA-ARM Training Session HCOE Thank You !
  翻译: