Vous êtes sur la page 1sur 8

Lab Experiment |5

LAB # 5:
Design the sequential circuit using advanced VHDL programming
techniques

Objective

• To explain the basics of Function and Procedure constructs in VHDL


• To design an electronic wheel of the fortune, utilizing the package and procedure
constructs
Pre-Lab
Part 1 -Basics of Function and Procedures constructs:
FUUNCTION:
A function is a section of sequential code. Its purpose is to create new functions to deal with
commonly encountered problems, like data type conversions, logical operations, arithmetic
computations, and new operators and attributes. By writing such code as a FUNCTION, it can be
shared and reused, also propitiating the main code to be shorter and easier to understand.
A function is very similar to a PROCESS. The same statements that can be used in a process (IF,
WAIT, CASE, and LOOP) can also be used in a function, two parts are necessary: the function
itself (functions body) and a call to the function. Their syntaxes are shown below,
Function Body

In the syntax above, <parameter list> specifies the function’s input parameters, that is:
<parameter list> = [CONSTANT] constant_name: constant_type; or
<parameter list> = SIGNAL signal_name: signal_type;

Example:
The function below, named f1, receives three parameters (a, b, and c). a and b are CONSTANTS
(notice that the word CONSTANT can be omitted, for it is the default object), while c is a SIGNAL.
a and b are of type INTEGER, while c is of type STD_LOGIC_VECTOR. Notice that neither
RANGE nor DOWNTO was specified. The output parameter (there can be only one) is of type
BOOLEAN.
Lab Experiment |5

PROCEDURE:
A procedure is very similar to a function and has the same basic purposes. However, a procedure
can return more than one value.
Like a Function, two parts are necessary to construct and use a Procedure: the procedure itself
(procedure body) and a procedure call.

Procedure call:
Contrary to a function, which is called as part of an expression, a procedure call is a statement on
its own. It can appear by itself or associated to a statement.

Syntax procedure call:


Lab Experiment |5

Pre- Lab Task:


To use procedure for min – max circuit below.

Figure 5.1 Min-Max Circuit

Code for Min-Max circuit using Procedure:


Lab Experiment |5

FUNCTION versus PROCEDURE Summary

• A FUNCTION has zero or more input parameters and a single return value. The
input parameters can only be CONSTANTS (default) or SIGNALS
(VARIABLES are not allowed)
• A PROCEDURE can have any number of IN, OUT, and INOUT parameters,
which can be SIGNALS, VARIABLES, or CONSTANTS. For input parameters
(mode IN) the default is CONSTANT, whereas for output parameters (mode OUT
or INOUT) the default is VARIABLE.
• A FUNCTION is called as part of an expression, while a PROCEDURE is a
statement on its own.
• In both, WAIT and COMPONENTS are not synthesizable.
• The possible location of FUNCTIONS and PROCEDURES are the same. Though
they are usually placed in PACKAGES (for code partitioning, code sharing, and
code reuse purposes), they can also be located in the main code (either inside the
ARCITECTURE or inside the ENTITY). When placed in a PACKAGE, then a
PACKAGE BODY is necessary, which should contain the body of each
FUNCTION and/or PROCEDURE declared in the PACKAGE.

Lab Tasks
Implementation of an LED wheel-of-fortune using a package/procedure

The LED wheel of fortune you are designing works as follows.

At the startup, the LED lights continuously rotate around using a bit pattern “00000001”, and
at the same time the seven-segment display (SSD) digits continuously increments the four-
digit hex number (16 bit) at a fast speed. The digit starts from 0000 and increments to FFFF
and repeats.
When a user presses a button, the LED rotation stops and the SSD displays the number caught at
the positive transition of the button press. When the user presses the button again, it starts the
whole process again, i.e., the LED lights rotates around, and SSD increments the four-digit hex
number at a fast speed. The LED movements should be slow enough to be visible. However, the
numbers on the SSD should be fast enough so that it is hard to recognize except when it is
stopped.
In order to accomplish this, several things must happen.
1. Add more SSD patterns, so that it can display 0-9 plus A-F.
2. Modify the procedure, so that it can decode a 16-bit number instead of just a four-bit
number as given.
3. You need to generate another clock that multiplexes the anodes of SSD. This clock
should run around 1/60th seconds in order to display different numbers in each position
Lab Experiment |5

of the SSD digit because cathodes are shared. Please refer to Fig 1.
4. Rotate bits and display the bits on LED. Synchronize the LED pattern to a slow clock,
so that the rotation would be visible. Rotating LED can be done using concatenation.
5. Write a push button code to detect positive transition and to take a proper action.
Please remember that buttons cause bouncing of signals and thus require
debouncing using the routine like the one given in the previous lab.
6. Please note that this design can be easily turned into a stop watch or a timer.
Lab Experiment |5

Write your VHDL Code for LED wheel-of-fortune:

:
Lab Experiment |5
Lab Experiment |5

Rubric for Lab Evaluation


Exceeds Meets
Developing Unsatisfactory
Expectations Expectation
[4] [3] [2] [1]
Setup of experiment and implementation
(hardware/simulation)
Follow the procedure/design process
Hardware Experimental results
Safety
Viva
Hardware Score (Average)
Exceeds Meets
Developing Unsatisfactory
Expectations Expectation
[4] [3] [2] [1]
Ability to use software
Software Ability to follow procedure and/or design a
procedure for experiment
Ability to troubleshoot software
Q&A
Software Score (Average)
Exceeds Meets
Developing Unsatisfactory
Expectations Expectation
[4] [3] [2] [1]
Written Lab Data Presentation
Report Data Analysis
Writing Style
Written Lab Report Score (Average)
Total Score

Signature & Date:

Vous aimerez peut-être aussi