Forum Discussion
Altera_Forum
Honored Contributor
11 years agoHi Scott,
Here's a Modelsim testbench of a hex display component. Follow through the readme.txt file ...
Hexadecimal Display Example
---------------------------
8/9/2014 D. W. Hawkins (dwh@ovro.caltech.edu)
This example shows how to use Modelsim to test a hexadecimal
display component. The source code shows two methods for
using VHDL to drive a hexadecimal display
1. A VHDL component; see src/hex_display.vhd
2. A VHDL function; see src/hex_display_pkg.vhd
The testbench test/hex_display_tb.vhd creates an instance
of both components and drives 4-bit hex values onto their
input puts. The hex display package defines another function
that decodes the 7-bit hex display output and converts it
back to a 4-bit value. The testbench uses that function
to check that the display values are correct.
The simulation can be run as follows;
1. Unzip the example, eg., into
c:\temp\hex_display
2. Start Modelsim
3. Change directory to the example, i.e.,
type the following
ModelSim> cd {c:\temp\hex_display}
where "ModelSim>" is the prompt, so does not need to
be typed in. The paranthasis {} around the path make
sure that a Windows path back-slashed are correctly
interpreted by Tcl. You can also use Tcl paths, i.e.,
ModelSim> cd c:/temp/hex_display
4. Run the simulation script
ModelSim> source scripts/sim.tcl
This script contains Modelsim commands. Read it to
understand the compilation sequence. The output from
this script run using Modelsim-ASE 10.1b (from Quartus 12.1sp1)
is as follows;
#
# Hex display testbench simulation script
# ---------------------------------------
#
# * Setup paths
# * Setup Modelsim work
# * Build the code
# Model Technology ModelSim ALTERA vcom 10.1b Compiler 2012.04 Apr 27 2012
# -- Loading package STANDARD
# -- Loading package TEXTIO
# -- Loading package std_logic_1164
# -- Loading package NUMERIC_STD
# -- Compiling package hex_display_pkg
# -- Compiling package body hex_display_pkg
# -- Loading package hex_display_pkg
# Model Technology ModelSim ALTERA vcom 10.1b Compiler 2012.04 Apr 27 2012
# -- Loading package STANDARD
# -- Loading package TEXTIO
# -- Loading package std_logic_1164
# -- Compiling entity hex_display
# -- Compiling architecture behave of hex_display
# * Build the testbench
# Model Technology ModelSim ALTERA vcom 10.1b Compiler 2012.04 Apr 27 2012
# -- Loading package STANDARD
# -- Loading package TEXTIO
# -- Loading package std_logic_1164
# -- Loading package NUMERIC_STD
# -- Compiling package log_pkg
# -- Compiling package body log_pkg
# -- Loading package log_pkg
# Model Technology ModelSim ALTERA vcom 10.1b Compiler 2012.04 Apr 27 2012
# -- Loading package STANDARD
# -- Loading package TEXTIO
# -- Loading package std_logic_1164
# -- Loading package NUMERIC_STD
# -- Loading package hex_display_pkg
# -- Loading package log_pkg
# -- Compiling entity hex_display_tb
# -- Compiling architecture test of hex_display_tb
#
# Testbench procedure
# --------------------
#
# hex_display_tb - Run the testbench
#
The script defines a Tcl procedure called hex_display_tb that loads
the hex_display_tb testbench, populates the wave window, and then
runs the simulation. Read sim.tcl to see the procedure.
5. Run the simulation testbench
ModelSim> hex_display_tb
The output after running this command is
# vsim -novopt hex_display_tb
# Loading std.standard
# Loading std.textio(body)
# Loading ieee.std_logic_1164(body)
# Loading ieee.numeric_std(body)
# Loading std.env(body)
# Loading work.hex_display_pkg(body)
# Loading work.log_pkg(body)
# Loading work.hex_display_tb(test)
# Loading work.hex_display(behave)
#
# ==============================================================================
# Hex display testbench
# ==============================================================================
#
# ==============================================================================
# 1: Check the hex display component
# ==============================================================================
# 0 ns: checking values 0h to Fh
# 160 ns: checks pass
#
# ==============================================================================
# 2: Check the hex displayfunction
# ==============================================================================
# 160 ns: checking values 0h to Fh
# 320 ns: checks pass
#
# ==============================================================================
# Simulation complete
# ==============================================================================
# ** Note: stop
# Time: 370 ns Iteration: 0 Instance: /hex_display_tb
# Break in Process line__78 at C:/temp/hex_display/test/hex_display_tb.vhd line 162
Viola! You have two working hex display drivers.
Now create a Quartus design and confirm that they synthesize to
exactly the same logic.
Enjoy! Cheers, Dave