VHDL Discussion Subprograms

Slides:



Advertisements
Similar presentations
COE 405 VHDL Basics Dr. Aiman H. El-Maleh Computer Engineering Department King Fahd University of Petroleum & Minerals Dr. Aiman H. El-Maleh Computer Engineering.
Advertisements

1 Introduction to VHDL (Continued) EE19D. 2 Basic elements of a VHDL Model Package Declaration ENTITY (interface description) ARCHITECTURE (functionality)
1 Lecture 13 VHDL 3/16/09. 2 VHDL VHDL is a hardware description language. The behavior of a digital system can be described (specified) by writing a.
Introduction to VHDL VHDL Tutorial R. E. Haskell and D. M. Hanna T1: Combinational Logic Circuits.
Why Behavioral Wait statement Signal Timing Examples of Behavioral Descriptions –ROM.
ELEN 468 Lecture 191 ELEN 468 Advanced Logic Design Lecture 19 VHDL.
Topics of Lecture Structural Model Procedures Functions Overloading.
VHDL Intro What does VHDL stand for? VHSIC Hardware Description Language VHSIC = Very High Speed Integrated Circuit Developed in 1982 by Govt. to standardize.
Kazi Fall 2006 EEGN 4941 EEGN-494 HDL Design Principles for VLSI/FPGAs Khurram Kazi Some of the slides were taken from K Gaj’s lecture slides from GMU’s.
ECE C03 Lecture 141 Lecture 14 VHDL Modeling of Sequential Machines Hai Zhou ECE 303 Advanced Digital Design Spring 2002.
VHDL. What is VHDL? VHDL: VHSIC Hardware Description Language  VHSIC: Very High Speed Integrated Circuit 7/2/ R.H.Khade.
Introduction to VHDL (part 2)
1 Data Object Object Types A VHDL object consists of one of the following: –Signal, Which represents interconnection wires that connect component instantiation.
1 H ardware D escription L anguages Basic Language Concepts.
ECE 332 Digital Electronics and Logic Design Lab Lab 5 VHDL Design Styles Testbenches.
IAY 0600 Digital Systems Design
IAY 0600 Digitaalsüsteemide disain Event-Driven Simulation Alexander Sudnitson Tallinn University of Technology.
VHDL TUTORIAL Preetha Thulasiraman ECE 223 Winter 2007.
VHDL IE- CSE. What do you understand by VHDL??  VHDL stands for VHSIC (Very High Speed Integrated Circuits) Hardware Description Language.
Language Concepts Ver 1.1, Copyright 1997 TS, Inc. VHDL L a n g u a g e C o n c e p t s Page 1.
IAY 0600 Digital Systems Design VHDL discussion Dataflow&Behavioral Styles Combinational Design Alexander Sudnitson Tallinn University of Technology.
Introduction to VHDL Spring EENG 2920 Digital Systems Design Introduction VHDL – VHSIC (Very high speed integrated circuit) Hardware Description.
Copyright(c) 1996 W. B. Ligon III1 Getting Started with VHDL VHDL code is composed of a number of entities Entities describe the interface of the component.
Fall 2004EE 3563 Digital Systems Design EE 3563 VHSIC Hardware Description Language  Required Reading: –These Slides –VHDL Tutorial  Very High Speed.
IAY 0600 Digital Systems Design VHDL discussion Verification: Testbenches Alexander Sudnitson Tallinn University of Technology.
Electrical and Computer Engineering University of Cyprus LAB 1: VHDL.
Topics AliasesSubprograms Generics & Configurations.
(1) Basic Language Concepts © Sudhakar Yalamanchili, Georgia Institute of Technology, 2006.
Introduction to VHDL Simulation … Synthesis …. The digital design process… Initial specification Block diagram Final product Circuit equations Logic design.
1 Introduction to VHDL Part 2 Fall We will use Std_logic And, Or have same precedence See slide 8 of part 1.
16/11/2006DSD,USIT,GGSIPU1 Packages The primary purpose of a package is to encapsulate elements that can be shared (globally) among two or more design.
VHDL Discussion Sequential Sytems. Memory Elements. Registers. Counters IAY 0600 Digital Systems Design Alexander Sudnitson Tallinn University of Technology.
04/26/20031 ECE 551: Digital System Design & Synthesis Lecture Set : Introduction to VHDL 12.2: VHDL versus Verilog (Separate File)
5-1 Logic System Design I VHDL Design Principles ECGR2181 Reading: Chapter 5.0, 5.1, 5.3 port ( I: in STD_LOGIC_VECTOR (1 to 9); EVEN, ODD: out STD_LOGIC.
VHDL Discussion Subprograms IAY 0600 Digital Systems Design Alexander Sudnitson Tallinn University of Technology 1.
IAY 0600 Digital Systems Design Event-Driven Simulation VHDL Discussion Alexander Sudnitson Tallinn University of Technology.
Slide 1 3.VHDL/Verilog Description Elements. Slide 2 To create a digital component, we start with…? The component’s interface signals Defined in MODULE.
George Mason University Behavioral Modeling of Sequential-Circuit Building Blocks ECE 545 Lecture 8.
EGRE 6311 LHO 04 - Subprograms, Packages, and Libraries EGRE 631 1/26/09.
IAY 0600 Digital Systems Design VHDL discussion Structural style Modular design and hierarchy Part 1 Alexander Sudnitson Tallinn University of Technology.
1 Introduction to Engineering Spring 2007 Lecture 18: Digital Tools 2.
Fundamentals of Digital Signal Processing יהודה אפק, נתן אינטרטור אוניברסיטת תל אביב.
IAY 0600 Digital Systems Design
Combinational logic circuit
Structural style Modular design and hierarchy Part 1
Basic Language Concepts
IAY 0600 Digitaalsüsteemide disain
Behavioral Style Combinational Design with VHDL
IAY 0600 Digital Systems Design
Dataflow Style Combinational Design with VHDL
Structural style Modular design and hierarchy Part 1
Behavioral Style Combinational Design with VHDL
IAY 0600 Digital Systems Design
IAS 0600 Digital Systems Design
UNIT 2: Data Flow description
IAS 0600 Digital Systems Design
Structural style Modular design and hierarchy Part 1
IAY 0600 Digital Systems Design
VHDL Discussion Subprograms
CPE 528: Lecture #3 Department of Electrical and Computer Engineering University of Alabama in Huntsville.
IAS 0600 Digital Systems Design
UNIT 6: Mixed-Type Description
IAS 0600 Digital Systems Design
ECE 545 Lecture 5 Simple Testbenches.
Design units Lecture 2.
Sequntial-Circuit Building Blocks
4-Input Gates VHDL for Loops
Digital Systems Design 2
EEL4712 Digital Design (VHDL Tutorial).
(Simple Testbenches & Arithmetic Operations)
Presentation transcript:

VHDL Discussion Subprograms IAS 0600 Digital Systems Design Alexander Sudnitson Tallinn University of Technology

Subprograms A subprogram is an encapsulated sequence of sequential statements that define an algorithm. The algorithm uses the values of input parameters, passed to the subprogram when it is called, to compute results or cause some desired effect. The actual code for a subprogram appears only once in the text of a program. However, the subprogram can be executed by calling it from anywhere in the program. Unlike subprograms in conventional programming languages, VHDL subprograms can also be executed as concurrent statements. Subprograms are not the primary mechanism for producing hierarchy in synthesizable VHDL descriptions. Instead, design entities serve that purpose. Subprograms are not design units and, therefore, they cannot be separately compiled.

Kinds of subprograms VHDL provides two kinds of subprograms: functions and procedures. A function computes and returns a single value. This value is computed using the values of parameters passed to the function when it is called. A function is called from an expression. The value returned by a function is used in the expression that contains the call. An expression containing a function call can be part of either a sequential or concurrent statement. However, all statements within a function are sequential. A procedure can return one or more values, or it may return no values and be used only for its effect. A procedure call is a statement. It can appear in a process or another subprogram as a sequential statement. Or, it can appear alone in an architecture body as a concurrent statement. However, all statements within a procedure are sequential.

Concurrent subprogram calls example We look at an example that includes a function and a procedure that are called using concurrent statements. In this example, these subprograms are used like components in a mixed architecture. As example, the logic diagram for a positive-level D latch comprised of NAND gates is taken. While this is certainly not an efficient way to describe a D latch, it illustrates how a number of different kinds of concurrent statements can each implement an identical operation. It also illustrates how functions and procedures use signals to communicate with other concurrent statements.

Concurrent subprogram calls example For instructional purposes, the D latch description has each NAND component implemented in a different way: u1: concurrent signal assignment statement (nand_2csa) u2: component instantiation statement (nand_2c) u3: process statement (nand_2) u4: function in a concurrent signal assignment statement (nand_2f) u5: concurrent procedure call statement (nand_2p)

2-input NAND component We start description with the entity declaration and architecture body for the design entity nand_2c, which is later instantiated in the top-level design entity. library ieee; use ieee.std_logic_1164.all; entity nand_2c is port (in1, in2 : in std_logic; out1 : out std_logic); end nand_2c; architecture dataflow of nand_2c is begin out1 <= in1 nand in2; end dataflow;

The entity declaration for the top-level design entity dlatch. library ieee; use ieee.std_logic_1164.all; entity dlatch is port (d, clk : in std_logic; q, q_bar : out std_logic); end dlatch; architecture mixed of dlatch is -- Function body for NAND gate function function nand_2f (signal in1, in2 : in std_logic) return std_logic is begin return (in1 nand in2); end nand_2f;

NAND gate function and procedure -- Function body for NAND gate function function nand_2f (signal in1, in2 : in std_logic) return std_logic is begin return (in1 nand in2); end nand_2f; -- Procedure body for NAND gate procedure procedure nand_2p (signal in1, in2 : in std_logic; signal out1 : out std_logic) is out1 <= (in1 nand in2); end nand_2p;

The statement part of the top-level architecture signal s1, s2, s3, s4, s5 : std_logic; -- Signals to connect gates begin u1: s1 <= d nand d; -- concurrent signal assignment NAND u2: entity nand_2c port map (in1 => d, in2 => clk, out1 => s2); -- component u3: process (clk, s1) -- process NAND s3 <= clk nand s1; end process u3; u4: s4 <= nand_2f(s2, s5); -- function NAND u5: nand_2p(s4, s3, s5); -- procedure NAND q <= s4; -- assignment of signals to q_bar <= s5; -- output pins end mixed;

Functions A function can be considered a generalized form of an operator and used to define a new operator. A function is called in an expression. When called, a function calculates and returns a result. In our example, in the declarative part of the architecture body for dlatch is the body of the function nand_2f. This function corresponds to component u4 in the logic diagram. This function’s body also serves as its declaration. function nand_2f (signal in1, in2 : in std_logic) return std_logic is begin return (in1 nand in2); end nand_2f;

Functions In our example, in the declarative part of the architecture body for dlatch is the body of the function nand_2f. This function corresponds to component u4 in the logic diagram. This function’s body also serves as its declaration. function nand_2f (signal in1, in2 : in std_logic) return std_logic is begin return (in1 nand in2); end nand_2f; Function nand_2f is like a component in the sense that it can be instantiated multiple times and its internal operations are not visible to the instantiating architecture (information hiding). Functions always return a value. Function nand_2f returns a value that is type std_logic. The body of this function consists of a single return statement that returns the NAND of parameters in1 and in2.

Function Call The caller passes parameters to a function as part of a function call. A function call consists of the function name followed by a list of actual parameters. The function call can appear alone on the right-hand side of an assignment statement, or as part of a more complex expression. A function declared in the declarative part of an architecture body can be called in the statement part of the architecture body using a concurrent statement, or can be called by a sequential statement in a process in the architecture body. A function declared in the declarative part of a process can only be called from within that process. When a function call appears in a concurrent signal assignment statement, it is executed whenever there is an event on a signal in its parameter list. In contrast, a function in a process is executed only when the statement containing the function call is reached during the sequential execution of the process’s statements.

Example: parity generator using a function An example of a function declared in an architecture body and called by a concurrent signal assignment statement is given in the next slide. The entity has an eight-element std_logic_vector input and a std_logic output that indicates whether the parity of the input vector is even or not. Parity is even if the vector has an even number of bits that are 1s, or if none of its bits are 1s. The body of the function parity_even appears in the declarative part of the architecture. A variable named result is declared in the declarative part of the function and is initialized to '1'. A loop is used to sequence through each element of the vector passed to the function. If the element being examined is a '1', the value of result is complemented. Once the loop is completed, a return statement returns the value of result. The architecture body contains a single concurrent call to the function parity_ even. The value returned by the function is assigned to output even.

Example: parity generator using a function entity parity_even_entity is port ( in_vector : in std_logic_vector(7 downto 0); even : out std_logic); end parity_even_entity; architecture behavioral of parity_even_entity is function parity_even (s: std_logic_vector(7 downto 0)) return std_logic is variable result : std_logic := '1'; begin for i in 7 downto 0 loop if s(i) = '1' then result := not result; end if; end loop; return result; end parity_even; even <= parity_even(in_vector); end behavioral;

Procedures procedure nand_2p (signal in1, in2 : in std_logic; signal out1 : out std_logic) is begin out1 <= (in1 nand in2); end nand_2p; Look slides Nr 8-9. The formal parameter list specifies three parameters. Parameters in1 and in2 are inputs and parameter out1 is an output. Procedure nand_2p contains a single sequential signal assignment statement that assigns out1 the NAND of parameters in1 and in2. Concurrent procedure call statement u5 calls procedure nand_2p. Actual parameter signals s4, s3, and s5 replace formal parameters in1, in2, and out1, respectively, of the procedure body. The procedure is called whenever there is an event on input parameters s4 or s3. When called, nand_2p updates the value of s5.

Procedures Procedures are encapsulated sequences of sequential statements. Like a function, the definition of a procedure can be given in two parts: a procedure declaration and a procedure body. A procedure declaration defines a procedure’s calling convention and is optional. It provides no information on the procedure’s implementation. When a procedure is defined in the declarative part of an architecture or a process, usually only the procedure body is provided. In such cases, the procedure body also serves as the procedure’s declaration. Unlike a function, a procedure’s declaration and body do not specify a return type. Use of parameters is the only way values can be returned from a procedure. Parameters of mode out or inout are used like a return value in a function, except there can be any number of them. If a class is not specified, a formal parameter of mode in defaults to constant class and a formal parameter of mode out or inout defaults to the variable class.

Sequential Procedure Call A procedure call is a statement. A procedure can be called from within a process or another subprogram. Such a call is a sequential procedure call. In a process, a procedure is called when the call statement is reached in the sequential execution of statements in the process. A sequential procedure call is equivalent to inserting inline, at the call statement, the code in the procedure’s body. When the last statement in a procedure is completed, the procedure returns. If the procedure call was sequential, the flow of control returns to the statement following the call. A return statement is not required.

Concurrent Procedure Call A procedure call can also exist alone in an architecture body as a concurrent procedure call. As a shorthand for component instantiation, procedures can represent components with multiple outputs. The procedure in a concurrent procedure call is called whenever there is an event on a signal that is an input parameter (mode in or inout) to the procedure. The parameter list of a concurrent procedure cannot contain a variable, since a variable cannot exist outside of a process. Synthesizeable procedures cannot have wait statements. In contrast, nonsynthesizeable procedures can. However, since a process cannot have both a sensitivity list and a wait statement, a process that calls a procedure that has a wait statement cannot have a sensitivity list.