Mentor Graphics Tutorial 3
Verilog Simulation in ModelSim

Estimated Time: 30 minutes

In this tutorial we will simulate a 2-bit binary incrementor in ModelSim. ModelSim is a package in Mentor Graphics and is used for logic simulation of HDLs.

  1. The Verilog code used for this tutorial can be downloaded here, increment.v, or you can use your favorite text editor to make it.
  2. module increment(in, out);
    input [1:0] in;
    output [1:0] out;
    assign out = in + 1'b1;
    endmodule

  3. Open ModelSim by typing ./msim in your home directory. (You should have the msim script file in your home directory that initializes the environment variables and runs ModelSim. You can get it here if you don't already have it.)
  4. Click on File>New>Library to create a new library, and name it ‘increment’. You will see the library appear in the workspace.
  5. Click on the Compile button on the Compile toolbar around the top of the window. Choose ‘increment’ as the library, and then select the file increment.v by browsing to its location and compile it.
  6. Fig: Compile icon is the first icon in the Compile Toolbar

  7. You should see the file, increment, under the increment library in the Workspace. Double-click this file. This should take you into Simulation mode, and also bring up the Objects window. You can click on View>Objects in the menu bar to bring up the objects window if you accidentally close it later.
  8. Go to View>Wave on the menu bar to bring up the waveform window.
  9. Right-click on 'out' in the Objects window, and add it to the wave by clicking Add to Wave>Selected Signals.
  10. Add inputs to 'in' by right-clicking it and clicking on Create Wave. Choose the type of input as Repeater. Set the Initial Value to 00 and change the Period to 250. Enter values 00, 00, 10, and 11 separated by commas and spaces in the Values section.
  11. Fig: Wave Toolbar. ‘Edit Mode’ is the third icon from the left

  12. Enter the wave edit mode by clicking on the ‘Edit Mode’ button in the Wave palette in the toolbar near the top of the window. Select the '[0]' part of the 'in' wave from around 250 ns to 500 ns. Right-click on the selected wave, and then click on Wave>Invert. Enter the Start Time as 250 and the End time as 500 if it is not already so and click OK. The signal should be modified to a 1 from a 0. You can modify the input wave in this fashion.
  13. Fig: Input wave after editing it.

  14. Run the simulation by typing 'run 1000' in the command line at the bottom of the screen. This will run the simulation for 1000 ns.

Fig: Waveform after running the simulation