Professional Documents
Culture Documents
cs.utexas.edu/users/fussell/courses/cs352h/handouts/verilog/vcs_tut.html
Before running VCS the tool environment file must be source. If you have not done this please
go back to the environment setup page. Steps 1 through 5 may be done on in a telnet window
from anywhere to any department linux machine. Steps 6 on require the user be seated at a
departement linux machine.
1. Write verilog file. For the purposes of this tutorial you may use the following example:
endmodule // mux2_1
As you can see this is a very simple four bit 2 to 1 mux. You may also copy the file
from here.
Note: we use the naming convention that the basename of the file and the module
name will be the same. In this case the module name is "mux2_1" therefore the file
name for it will be "mux2_1.v". There will also only be one module per file.
2. Write a test bench for the verilog file. Here is an example testbench file:
// This stuff just sets up the proper time scale and format for the
// simulation, for now do not modify.
`timescale 1ns/10ps
module timeunit;
initial $timeformat(-9,1," ns",9);
endmodule
1/9
wire [3:0] out; // From dut of mux2_1.v
initial
begin
#10;
in0 = 4'b0110;
in1 = 4'b1001;
sel = 1'b0;
#10;
#10;
sel = 1'b1;
#10;
#10;
$finish;
end
endmodule // mux2_1_testbench
As can be seen, the test bench instantiates the mux and assigns each of its inputs to a
reg. It then asserts various different values on those inputs and tests the output for
the proper value. If the output is incorrect it will print an error message and quit. The
final section creates a value change dump file that can be used for off line analysis of
the test run (see step 5 below). You may download a copy of the testbench from here.
3. In order to use the test bench we must use VCS to build an executable model of it. To
do this first we must make a list of the files we are building. The list of files must be in
a top down heirarchical order. In this case we will make a text file called "filelist" which
3/9
has the following contents:
mux2_1_testbench.v
mux2_1.v
When the command is complete there will be an executable in the current directory
that is the model for the testbench:
4/9
pgratz@desk workingdir $ ls -l
total 520
drwxr-xr-x 2 pgratz guest 4096 Sep 11 10:12 csrc
-rw-r--r-- 1 pgratz guest 27 Sep 11 10:00 filelist
-rwxr-xr-x 1 pgratz guest 509960 Sep 11 10:12 mux2_1
drwxr-xr-x 2 pgratz guest 4096 Sep 11 10:12 mux2_1.daidir
-rw-r--r-- 1 pgratz guest 238 Sep 11 09:59 mux2_1.v
-rw-r--r-- 1 pgratz guest 2357 Sep 11 09:59 mux2_1_testbench.v
5. Now that the model has been built the next step is to execute it to find out if the tests
written in the testbench pass or not:
As can be seen in this output the "All tests completed successfully" has been printed
so each of the tests written in the testbench must have passed. Also note that the
$monitor command causes the values of all the variables to be printed when ever any
of them have changed.
6. For more extensive analysis of the device under test it can be useful to visually see the
signals and their transitions, similar to a logic analyzer. VCS has the VirSim tool for
just this purpose. Because of the $dumpfile statements at the end of the testbench,
when the model is executed a trace of all the signals is saved in a .dump file in the
local directory, VirSim is able to read this file and display the results. To start VirSim,
once the test has been run once, execute the following command:
5/9
To open the dumpfile select "open" under the File menu to bring up the "Open File
Dialog" window. On that window make sure that the "type" is "VCD" (not "VCD+"):
6/9
You should now see "mux2_1.dump" as one of the options under "Files", select it and
hit OK. This will load the dump file and the Hierarchy Window will show it, next select
"mux2_1_testbench" under the "Hierarchy" box of the Hierarchy Window. This will
cause the signals available at that level in the hierarchy to show up under signal
select:
7/9
Now select the "Waveform" under the Window menu on the Hierarchy Browser and
the Waveform window will appear:
8/9
As can be seen here there are no signals in the Waveform window. The easiest way
to look at signals is to first select the "mux2_1_testbench" under "Heirarchy" in the
Heirarchy Browser. Then select all the signals shown in the "Signal Select" box on the
Hierarchy Browser and drag them using the middle mouse button (chord left and right
together on 2 button mice) over to the black area on the Waveform window. This will
make the signals appear in the Waveform window, at this point select "Zoom
Percent/Zoom %100" under the Zoom menu to show the entire test. It should look like
this:
Note that the scale along the top is in ps. It may be adjusted with the "Time Scale.."
option under Display. Also it is possible to zoom in on areas by dragging the left
mouse button across the desired section.
This concludes the tutorial on the use of VCS. More extensive documentation may be found
on the main CAD page.
9/9