0% found this document useful (0 votes)
46 views20 pages

Allan Diaz Ricardo Beltrán Electronic Engineering Digital Systems I

The document discusses the differences between functions and procedures in VHDL. It states that functions can have zero or more input parameters and one output parameter, while procedures can have any number of input, output, or input-output parameters. Both functions and procedures can contain sequential code to perform common operations like calculations or logical operations. Key differences are that functions are called as part of an expression, while procedures are called as statements. Both can be placed within packages for code reuse or within the main code. When placed in packages, the package body must define the bodies of the functions and procedures.

Uploaded by

nb7_
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views20 pages

Allan Diaz Ricardo Beltrán Electronic Engineering Digital Systems I

The document discusses the differences between functions and procedures in VHDL. It states that functions can have zero or more input parameters and one output parameter, while procedures can have any number of input, output, or input-output parameters. Both functions and procedures can contain sequential code to perform common operations like calculations or logical operations. Key differences are that functions are called as part of an expression, while procedures are called as statements. Both can be placed within packages for code reuse or within the main code. When placed in packages, the package body must define the bodies of the functions and procedures.

Uploaded by

nb7_
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Allan Diaz

Ricardo Beltrán
Electronic Engineering
Digital Systems I
 Functions and procedures are known as subprograms.
 From a construction point of view , they are very
similar to those processes .
 However, from a viewpoint of application, there is a
fundamental difference between processes, functions
or procedures: while the former is aimed at immediate
use within the main code , the others are intended to
use in libraries , that is, its purpose is to store common
pieces of code, so they can be reused or shared with
other projects .
 However , if desired, a function or procedure can also
be placed within the main code.
 A function is a sequential code section .
 Its purpose is to create code to deal with common design
problems, such as:
 Data type conversion
 Logical operations
 Arithmetic Calculations
 New operators and attributes
 A function is a sequential code section .
 When you write code like function , it can be reused and
shared
 The functions are similar to processes, since they can be
used in both statements (IF, WAIT , CASE , LOOP ) except
WAIT
 Two other prohibitions are a function declaration and use of
signal components.
 To make and use a function, two parts are necessary : the same function
( function body ) and the call to the function. Its syntax is as follows:

 In this syntax, <parameter list> contains the input parameters , that is:
 <parameter list>= [CONSTANT] constant_name: constant_type;
 <parameter list>= SIGNAL signal_name: signal_type

 There may be any number of parameters ( including zero) , which can be


constant or signal ( the variables are not supported )

 Types can be any of the synthesizable (boolean , bit , std_logic , integer, etc )
. However, it is not necessary to specify the range . On the other hand , there
is only one return value, whose type is specified with data_type
 This feature, called f1, takes three parameters : a, b and
c.
 a and b are constants ( note that the constant word can
be omitted because it is the default object ) , while c is a
sign
 a and b are integers , while c is the type
std_logic_vector .
 Note that no range for integer values (a and b ) or to
the logic ( c ) is specified .

The output parameter (which is only one) is a boolean .
 A function is called as part of an expression.
 The expression obviously can appear by itself or associated
with a statement ( either simultaneously or sequentially ) .
 Examples of function calls:

 Example : positive_edge function( )


 This function converts a parameter of type
std_logic_vector to an integer value . Note that
the code is generic, because it works for any rank
or order ( to / downto ) std_logic_vector
parameter input
 The common location of a function (or method ) are
shown in the following figure .

 Although a function is usually placed in a package (


to segment code , code reuse or sharing ) it can also be
placed in main code (either in architecture or inside
the entity) .

When placed in a package , you need the package
body , which must contain the body of each function
(or method ) placed in the declarative part of the
package .
 When a function in the main code is placed ,
the function can be placed either in the state
as in the declarative part of architecture.
 By placing a function within a package , the function
can be re-used and shared to other projects.
 Note that when the function within a package is
placed , the function is declared in the package, but
described in the package body .
 A procedure is very similar to a function and has
the same purpose . However , a method may
return more than one output value

 As a function, two parts are needed to build and


use a procedure: the same procedure ( procedure
body ) and the procedure call
 Procedure body

 In this syntax, < parameter_list > specifies the inputs


and outputs of the process , that is:
 A procedure can have any number of input parameters,
output or input - output , which in turn can be signs ,
variable or constant .
 For input signals (IN mode), the default is the constant
rate , and considering Come out signals (OUT or
INOUT mode), the default is the variable rate.
 As seen above, WAIT and SIGNAL and statements are
not synthesizable COMPONENTS when used within a
function .
 The same is true for procedures, with the exception that
the signals can be declared , but the procedure must be
in a process.
 In addition to WAIT , detections flanks are not
synthesized within a procedure (that is, contrary to a
function, a procedure synthesizable not infer a record )
 This procedure has three inputs : a, b and c ( in IN
mode).
 a it is a constant bit rate , while b and c are signals
also type bit .
 a it is a constant bit rate , while b and c are signals
also type bit .
 There are also two output signals : x (OUT mode ,
typo bit_vector ) and y ( INOUT mode , INTEGER
type) .
 Unlike a function, which is called as part of an
expression, the call to a procedure is a
statement itself. It may appear by itself or
associated with a statement ( either
concurrently or sequentially ) .
 Example call to a procedure:
 The typical placement procedure is the same as
a function .
 Again, although it is usual to place it in a
package ( to segment code reuse and
distribution) , it can also be placed in the main
code ( whether in the body or in the declarative
part of the architecture ) .
 When placed in a package , you must include
the package body , which will have the body of
each procedure in the declarative part of the
package .
 The mix_max code uses a procedure called
SORT. Its inputs are two integers unsigned 8-
bit ( INP1 , INP2 ) , sorts , and output min_out
placed on the minimum value and the
maximum value in max_out.
 A function has zero or more inputs and one output . The
input parameter can be only constants ( default object )
or signals ( variables are not supported) .
 A procedure can have any number of inputs ( IN) ,
output (OUT ) or input -output ( INOUT ) which can be
signals , variables or constants . For input parameters ,
the default object are constant , while for the default
output is a variable .
 In both WAIT and are not synthesizable
COMPONENTS
 The placement of functions and procedures are the same
. Although are placed generally within package ( for
segmenting the code reuse or share ) they can also be
placed in the main code ( either architecture or entity ) .
When placed in a package, it is essential to the body of
the package, which must contain the body of each
function or procedure stated in the package.

You might also like