Tutorial

Purpose

The purpose of this tutorial is introduce you to the IEEE standard hardware description language, Verilog HDL, and to the tool chain.  The tool chain consists of the Modelsim simulation tool and the Synopsys synthesis tool.

Summary

The ultimate goal of chip-level design is to actually produce a chip.  There are many steps involved in doing this, and this tutorial focuses on two of them: simulation and synthesis.

A simulator accepts inputs that you specify and displays what the design's anticipated outputs will be.  In this tutorial, we will be doing rtl-level simulation, where rtl is an acronym for register transfer level, in which the input to the simulator is the compiled Verilog HDL source code. Verilog HDL is a programming language for defining the structural and behavioral description of digital circuits.  In rtl-level simulation, since no delay information is present, the simulation has no delays in it.   The simulator that you will be using is the ModelSim simulator, which is available in the Mentor Graphics toolset.

Synthesis is the process of taking human-readable input such as Verilog HDL source code files and creating a low-level description which describes the design in terms of simple gates.  The synthesis tool you will be using is Synopsys.  A TSMC (Taiwan Semiconductor Manufacturing Corporation) ASIC (application-specific integrated circuit) library will be used in Synopsys.

The Tutorial

1  Online ModelSim, Synopsys, and Verilog HDL Documentation

  1. Modelsim online documentation  
  2. Synopsys online documentation  
  3. ModelSim Quick Guide (pdf)  
  4. Verilog HDL Quick Reference Card (pdf)  
  5. Verilog HDL Quick Reference Guide
  6. Verilog Handbook
  7. Verilog Introduction for Digital Design
  8. comp.lang.verilog newsgroup
  9. Alternate Verilog FAQ
  10. Verilog Center

2  Preparation: UNIX paths

You can work in either your oce home directory or in your directory in the class directory.  For the instructions given below, we will assume that you are working in your oce home directory.  Setup the following recommended directory structure in your oce home directory:

3  Verilog HDL Source Code

In order to enter HDL source code, you will need to use a text editor.  Popular choices are vi, vim, gvim, xemacs, emacs and pico. 

Verilog source code is plain text contained in a single file or a group of files.  Verilog text files use the file extension, .v .

4  Simulation: ModelSim vsim

To initialize ModelSim vsim: To compile your design into the work library (this needs to be done whenever you make a change to your source code):
  1. % vlog full_adder.v
  2. % vlog h_4_bit_adder.v
  3. % vlog tb_h4ba.v
An option that is available to you in compiling files for ModelSim vsim is to write a make file

Since the full_adder module is used as a component in the h_4_bit_adder module, the full_adder module is compiled before the h_4_bit_adder module.  Likewise, since the h_4_bit_adder module is used as a component in tb_h4ba module, the h_4_bit_adder module is compiled before tb_h4ba module.

When you make a change in a HDL source code file, you must recompile not only that file, but any file that instantiates the module in that file as a component.  For example, if we made a change to h_4_bit_adder.v, we would then have to recompile tb_h4ba.v after we recompiled h_4_bit_adder.v, since the h_bit_adder module is used as a component in the tb_h4ba module.  We would not have to recompile full_adder.v since the h_4_bit_adder module is not instantiated as a component in the full_adder module.

To list the compiled modules in the work directory: To invoke the simulator with the name of the top-level design unit, which in this case is the module tb_h4ba: The following are a few examples of command-line interface commands: A couple of the questions that are asked about vsim are:
  1. How can I display signals from an module instantiated in my design on the wave diagram when running vsim?


  2. How can I set a breakpoint when running vsim?

In Modelsim vsim,

Note:If you ever have a simulation that does not halt, a good way to stop it is to click on the Break icon, which is the third icon from the right in the ModelSim vsim window.   You may need to use this if you ever choose Run | Run - All from the Modelsim vsim menu or the run - all icon in the Modelsim vsim window.  If you use either of these and the simulation time increases to a large value before you click the Break icon, you should type the command  ls -l vsim.wlf  in a xterm window in the directory in which you are running the simulator to check the memory usage of the file vsim.wlf.  The file vsim.wlf is a file generated by vsim during the simulation, if you have the wave window up, to hold the data displayed in the wave window.  The file size can reach your alloted memory usage quota if you use run - all and don't use the Break icon soon enough.  To view your memory usage and quota, type  quota -v  in a xterm window.  To remove the vsim.wlf file, use,  rm vsim.wlf  in a xterm window.  The vsim.wlf file is overwritten each time you run a simulation, so as long as you don't use run - all or set the run simulation time to an unnecessarily large number, you should not have to worry about it.

You may want to occasionally print out the simulation results that appear in the wave window.  You can use the zoom feature from the wave menu to obtain the proper zoom.  To print the wave, from the wave menu, select File | Print Postscript...  When the Write Postscript window opens, click File name: and type in a name for the file name, i.e., wave1.ps, and click ok..   Only the portion of the wave that is presently viewable will be printed out.  If the waveform is long, you will have to use more than one page.  To set the laser printer destination, in an xterm window, use the command, setenv PRINTER laser44 if you are in EBUI 3327/3329, or setenv PRINTER laser65 if you are in EBUII 313.  To view and print out a postscript file, you can use ghostview by typing the command, ghostview wave1.ps in an xterm window, where wave1.ps is the name of your postscript file.  To print out the postscript file in ghostview, choose File | Print..., type in laser44 if you are in EBU1 3327/3329 or laser65 if you are in EBU2 313 in the popup window and click ok.

Note: Simulation can also be performed on the output of the synthesis tool.  This is called gate level simulation as opposed to rtl level simulation performed in this tutorial.  Gate level simulation is more accurate, but takes longer than rtl level simulation.   Gate level simulation will not be performed in this tutorial.

5  Synthesis: Synopsys

Your working directory should be ~/ece111/tutorial1.
  1. Copy the file, synopsys_dc.setup   to your directory as the file, .synopsys_dc.setup.
  2. Be sure you have copied full_adder.v and h_4_bit_adder.v
  3. Copy the synthesis script file, h4ba.scr  
  4. At the unix prompt, type, prep synopsys
  5. At the unix prompt, type, dc_shell
  6. To run the synthesis script,at the dc_shell prompt, type, include h4ba.scr
    Cell, area, and timing reports for the hierarchical four-bit adder will be written to the files, h4ba_cells, h4ba_area, and h4ba_timing.

6  4-bit Adder using an always block example

Processes in Verilog are modeled with the always block. In hardware description languages, processes are sections of sequentially executed statements, as opposed to the dataflow environment, where all statements are executed concurrently. In a process, the order of the statements does matter. In fact, processes resemble the sequential coding style of high level programming languages. Also, processes offer a variety of powerful statements and constructs that make them very suitable for high level behavioral descriptions. 

The Verilog description of a 4-bit adder using a process with a sensitivity list is p4ba.v.  The sensitivity list is to the right of always@.  Signals that are read in the always construct should be placed in the sensitivity list.  Since the signals, addend_one, addend_two, and carry_in are read in the process, they are included in the sensitivity list.  Whenever one of the signals in the sensitivity list changes value, the always block will be executed.  The assignment statements in the unclocked process use the blocking assignment operator, =.  Signals written to with the blocking assignment operator are updated instantaneously.  Combinational logic (unclocked always block) should be described using the blocking assignment operator.  The other type of Verilog assignment operator is the non-blocking assignment operator, <=. When a signal is written to with the non-blocking assignment operator, it is scheduled to be assigned the new value at the end of the current time unit. Sequential logic (clocked always block) should be described using the nonblocking assignment operator.  In the Verilog module, sum, carry_out, and carry are declared to be of type reg because they are assigned to in the always block.  No registers will be synthesized as no edge is specified in the event specification list (sensitivity list).

7  FSMs

  • Moore state machine.  moore.v .  The value of output Z depends on the value of CURRENT_STATE.  The fsm is composed of two always blocks.  One unclocked always block is used to hold the combinational elements and one clocked always block is used to hold the synchronous elements.  The always block to hold the combinational elements uses a sensitivity list which is comprised of signals read in the always block, X and CURRENT_STATE.  Signals assigned to in unclocked always block are synthesized as wires if no memory is inferred or as latches if memory is inferred.  In this unclocked always block, Z and NEXT_STATE are synthesized as wires. The clocked always block to hold the sequential elements uses the keyword posedge to signify the rising edge and using it in the second always block enables synthesis of CURRENT_STATE as the state register.   When the value of the signal CLK changes from 0 to 1, CURRENT_STATE is scheduled to be assigned the value of NEXT_STATE.  Signals assigned to in a clocked always block enables synthesis as registers.  CURRENT_STATE is synthesized as the state register of the state machine. This state machine uses state machine design style 1.
  • Mealy state machine.  mealy.v  The output value Z depends on both the value of CURRENT_STATE
  • and the value of the input X.

A sample Verilog testbench for the moore state machine is provided:  tb_moore.v.  Suppose that you want to view on the wave timing diagram the six signals: RESET, X, CLK, Z, NEXT_STATE, and CURRENT_STATE.

One method to do this is to use a .do macro file.  Another method is to use the window menus.

  • To use a .do macro file for the moore state machine, the steps are:

    1. Copy the .do file, moore.do to the directory that you are running vsim.


    2. Load the tb_moore module into vsim.

    3. In the vsim transcript window, type the command, do moore.do


  • To use the window menus for the moore state machine, the steps are:

    1. From the ModelSim vsim transcript window menu, choose View Structure.


    2. From the ModelSim vsim transcript window menu, choose View Signals.


    3. From the ModelSim vsim transcript window menu, choose View Wave.


    4. In the Structure window, click on uut: moore.


    5. The five signals of interest will be displayed in the Signals window.


    6. From the Signals window menu, choose View Wave > Signals In Region.


    7. The five signals of interest will be displayed in the wave timing diagram.

A synthesis script file for the moore state machine is moore.scr.

8  Counter example

9  Register File example

A four 32-bit register file example is reg4.v.  To read a register, the nr_w bit is set to 0; to write to a register, the nr_w bit is set to 1.  The register to be read from or written to is determined by a 2-bit address.  The register file module in reg4.v uses four instantiations of the 32-bit register module in the Verilog source, reg.v.  

10  A few notes

  • Unix note:If you ever need to terminate a process that is running, type the unix command, ps -eaf | more in an xterm window.  Locate the PID number that corresponds to the process and type the command, kill PID, in an xterm window, where PID is the process ID number corresponding to the process.
  • Cpu limit note.
  • Latches should be avoided.
  • Combinational loops should be avoided.  Combinational loops can produce oscillatory behavior and are generally not desired in a reliable digital design.  A combinational loop example
  • Register note


March 30, 2002