





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






Dr. Aleksandar Milenkovic Electrical and Computer Engineering The University of Alabama in Huntsville E-mail: [email protected]
In this tutorial you will learn to edit, compile, and simulate VHDL models. You will use the ModelSim compiler/simulator from Model Technology to simulate an example of the binary to hexadecimal converter.
With the mouse, first double click on the ModelSim icon that is on the desktop.
Close the “Welcome to the ModelSim” popup window and it will open up the following ModelSimSE command window.
Figure 1. ModelSim command window.
You will then want to change to the folder that is associated with your account and to create a new directory for this design.
% cd c:\smith\cpe422 __ # move to your directory here
% mkdir simul2 __ # create directory for this lab
% cd simul2 __ # move to this directory
Each time we start a new design we must create a VHDL library that will hold our compiled designs, just as the IEEE library contains the std_logic_1164 package. The library name work is commonly used. Remember, this only has to be done when you first create a new project directory. From the command line type:
% vlib work __
This creates a library called work in the current directory.
Your next step is to type in the following VHDL code for the converter. You may use any text editor or the ModelSim’s edit utility. To open the ModelSim editor click on File->New->Source-VHDL.
Type in the VHDL code for the binary to hexadecimal converter (see Figure 2).
To save file select the following: File->Save as and give the name of the file (e.g., b2h.vhd).
If you do not have any errors you will see a report similar to the following:
_# Model Technology ModelSim PE vcom 5.7d Compiler 2003.05 May 11 2003
If there are errors this process should be repeated as necessary by editing and altering the VHDL source file.
Once the VHDL model is successfully compiled into the work library, the simulator is invoked to test it.
Start the simulator by selecting Simulate->Simulate.
The Simulate window is displayed showing you all the designs that are currently available. Select the b2h entity in the work directory to display all the architectures that have been associated with the entity. You should have a window like the one below. Click on the b2h entity and click the Load button.
Figure 3. Load design.
Now we need to force the inputs of the design to see if it behaves properly. We will use VHDL testbenches to force inputs on labs and our projects later in the semester. For now we will use the force
commands build into the simulator. ModelSim command files are an easy way to implement a series of commands. The ModelSim command interpreter is actually a Tcl interpreter with ModelSim specific functions added. There are dozens of ModelSim commands but the ones we are interested in are force , run , and add wave. Note that any of the commands in a command file can be interactively entered at the VSIM command prompt in the ModelSim window.
For this tutorial, we will directly type in commands to apply forces to the inputs. Type in the following:
% force I "0000" 0, "0001" 20, "0010" 40 # input I is “0000” at 0 ns, “0001” at 20 ns, “0010” at 40 ns
Although there are many options for viewing simulation state, we will use the signals and the wave view here. From the ModelSim pulldown menu bar, start by selecting View ->Signals. The following signal window will appear:
Figure 4. View signals.
To view all the signals in the model select Add->Wave->Signals in Region from the signal window. A waveform window will appear containing all of the signals in the design. We could have also use the add wave Tcl command as part of a command file. The display is now prepared for our simulation. You may wish to adjust window sizes and positions so that all signals are visible in the Wave window. Once you feel comfortable with these views, you are encouraged to explore others that are also available. The following window will appear.
Figure 6. Simulation results.
Observe the results. Verify that your design is working properly!
Simulation results can also be observed by selecting Add->List->Signals in Region from the signals window.
Figure 7. List signals view.
A convenient way to enter stimulus is to create a separate test bench file which is written in VHDL to drive the inputs of the module that is to be tested. In this arrangement, the original VHDL model which is being simulated is instantiated as a component within the test bench file. A file which will
accomplish this purpose for the binary converter example, called t2h_tb.vhd, is shown in Figure 2.
Figure 8. VHDL Testbench for the b2h.
To simplify things, the test bench file should be saved and compiled under the same folder (directory) as the model file, which is to be simulated. To do this for the binary converter example one would simply type
% vcom b2h_tb.vhd __
Start the simulator (Simulate->Simulate) and load the b2h_tb entity. Select the view you want and run simulation for 1600 ns. The list view is shown below.