Académique Documents
Professionnel Documents
Culture Documents
LAB # 5:
Design the sequential circuit using advanced VHDL programming
techniques
Objective
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.
• 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
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
:
Lab Experiment |5
Lab Experiment |5