2 * Copyright (c) 1999 Stephen Williams (steve@icarus.com)
4 * This source code is free software; you can redistribute it
5 * and/or modify it in source code form under the terms of the GNU
6 * General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21 * This example program simulates a 16x1 ram, and is used as an
22 * example for using VCD output and waveform viewers.
24 * Like any other Verilog simulation, compile this program with the
27 * iverilog show_vcd.vl
29 * This will generate the show_vcd command in the current directory.
30 * When you run the command, you will see the output from all the
31 * calls to $display, but also there will be a dump file ``show_vcd.vcd''.
32 * The name of this file is set by the statement:
34 * $dumpfile("show_vcd.vcd");
36 * in the main module. The output file uses the standard VCD file format
37 * so can be viewed using off-the-shelf waveform viewers. The remaining
38 * steps describe how to use GTKWave to view the file. If you are using
39 * a different viewer, see the documentation for that tool.
41 * To view the output generated by running show_vcd, start the GTKWave
42 * viewer with the command:
44 * gtkwave show_vcd.vcd
46 * The GTKWave program will display its main window, and show in a small
47 * status box (upper left corner) that it succeeded in loading the dump
48 * file. However, there are no waveforms displayed yet. Select signals to
49 * add to the waveform display using the menu selection:
51 * "Search --> Signal Search Tree"
53 * This will bring up a dialog box that shows in directory tree format
54 * the signals of the program. Select the signals you wish to view, and
55 * click one of the buttons on the bottom of the dialog box to display
56 * the selected signals in the waveform window. Click "Exit" on the box
59 * The magic that makes all this work is contained in the $dumpfile and
60 * $dumpvars system tasks. The $dumpfile task tells the simulation where
61 * to write the VCD output. This task must be called once before the
62 * $dumpvars task is called.
64 * The $dumpvars task tells the simulation what variables to write to
65 * the VCD output. The first parameter is how far to descend while
66 * scanning a scope, and the remaining paramters are signals or scope
67 * names to include in the dump. If a scope name is given, all the
68 * signals within the scope are dumped. If a wire or register name is
69 * given, that signal is included.
72 module ram16x1 (q, d, a, we, wclk);
82 always @(posedge wclk) if (we) mem[a] = d;
84 endmodule /* ram16x1 */
92 ram16x1 r1 (q, d, a, we, wclk);
95 $dumpfile("show_vcd.vcd");
96 $dumpvars(1, main.r1);
99 for (a = 0 ; a < 4'hf ; a = a + 1) begin
103 $display("r1[%x] == %b", a, q);
106 for (a = 0 ; a < 4'hf ; a = a + 1)
107 #1 if (q !== a[0]) begin
108 $display("FAILED -- mem[%h] !== %b", a, a[0]);