Difference between revisions of "Simulation Tutorial"

From Vlsiwiki
Jump to: navigation, search
Line 24: Line 24:
  
 
== Select Analog Environment ==
 
== Select Analog Environment ==
With the schematic file open, Spectre can be invoked from within Virtuoso.  
+
With the schematic file open, hspice can be invoked from within Virtuoso.  
 
:Select <b>Launch &rarr; ADE L</b>. <br>
 
:Select <b>Launch &rarr; ADE L</b>. <br>
  
Line 114: Line 114:
 
You can also select <b>Simulation &rarr; Create Raw</b> to create the raw simulation file for debugging. You should be able to see your include stimulus, netlist, and a bunch of other stuff.
 
You can also select <b>Simulation &rarr; Create Raw</b> to create the raw simulation file for debugging. You should be able to see your include stimulus, netlist, and a bunch of other stuff.
  
If this pops up a window that says it failed, fix the previous options. You need to debug this by looking at the output of the simulator in si.log (which is the output of running the simulator, if the simulator failed to run) or si.out (which is the actual simulator output if it ran successfully, but simulation may have failed). This will show you if it even got to the point of running the simulator. The simulator output of the simulator itself can be seen with  <b> Spectre &rarr; Show Output </b> (or in the file si.out).
+
If this pops up a window that says it failed, fix the previous options. You need to debug this by looking at the output of the simulator in si.log (which is the output of running the simulator, if the simulator failed to run) or si.out (which is the actual simulator output if it ran successfully, but simulation may have failed). This will show you if it even got to the point of running the simulator.  
 +
 
  
 
If it succeeded, you can select <b> Tools &rarr; Waveform  </b>. When you do this, you get three windows:
 
If it succeeded, you can select <b> Tools &rarr; Waveform  </b>. When you do this, you get three windows:
Line 155: Line 156:
 
== Power/Energy Analysis ==
 
== Power/Energy Analysis ==
  
To enable power analysis in Spectre, add this statement to your input stimulus:
+
To enable power analysis in hspice, add this statement to your stimulus file:
  
  save :pwr
+
  .measure tran toplvl_avg_power avg  power from=0ns to=100ns
 +
.measure tran toplvl_avg_energ integ power from=0ns to=100ns
 +
.measure tran toplvl_avg_current avg I(VDD) from=0ns to=100ns
  
This will save the instantaneous power of your entire circuit. You can specify a specific instance with "x1:pwr" for an instance called x1. Re-run your simulation.
+
For more information on the .measure syntax, please refer hspice user guide at:
 +
/mada/software/synopsys/H-2013.03/hspice/docs_help/hspice_sa.pdf
  
 
You can then plot the power in the waveform viewer. It will be shown with all the other signals. In order to find the average power, you select :pwr and click on the calculator option instead of the plot option. In the calculator window, select "average" in the special functions. Then select the "Evaluate" button. (It is on the right of the "Clip" option and to the left of the Table and Append options). This will give you the average power in Watts.  
 
You can then plot the power in the waveform viewer. It will be shown with all the other signals. In order to find the average power, you select :pwr and click on the calculator option instead of the plot option. In the calculator window, select "average" in the special functions. Then select the "Evaluate" button. (It is on the right of the "Clip" option and to the left of the Table and Append options). This will give you the average power in Watts.  

Revision as of 17:20, 3 April 2013

There are many ways to simulate from Virtuoso. Which one is best depends on your PDK and your final goals.

Setting up analogLib

Before you start virtuoso, make sure to add the analogLib to your libraries. Do this by editing cds.lib in your home directory (or in the project directory). You should see something like this:

DEFINE      basic                   $CDK_DIR/lib/basic
DEFINE      NCSU_Analog_Parts 	    $CDK_DIR/lib/NCSU_Analog_Parts
DEFINE      NCSU_Digital_Parts 	    $CDK_DIR/lib/NCSU_Digital_Parts
--DEFINE      MOSIS_Layout_Test       $CDK_DIR/lib/MOSIS_Layout_Test
DEFINE      NCSU_TechLib_ami06      $CDK_DIR/lib/NCSU_TechLib_ami06
DEFINE      NCSU_TechLib_ami16      $CDK_DIR/lib/NCSU_TechLib_ami16
DEFINE      NCSU_TechLib_hp06       $CDK_DIR/lib/NCSU_TechLib_hp06
DEFINE      NCSU_TechLib_tsmc02     $CDK_DIR/lib/NCSU_TechLib_tsmc02
DEFINE      NCSU_TechLib_tsmc02d    $CDK_DIR/lib/NCSU_TechLib_tsmc02d
DEFINE      NCSU_TechLib_tsmc03     $CDK_DIR/lib/NCSU_TechLib_tsmc03
DEFINE      NCSU_TechLib_tsmc03d    $CDK_DIR/lib/NCSU_TechLib_tsmc03d
DEFINE      NCSU_TechLib_tsmc04_4M2P    $CDK_DIR/lib/NCSU_TechLib_tsmc04_4M2P

Then add the following line:

DEFINE   analogLib $CDS_ROOT/dfII/etc/cdslib/artist/analogLib

Save the file and start virtuoso. You should see a new library in the library manager.

Select Analog Environment

With the schematic file open, hspice can be invoked from within Virtuoso.

Select Launch → ADE L.

Select Simulator (hspiceD)

Virtuoso Analog Design Environment supports various simulators such as hspiceD, Spectre, and Ultrasim. hspiceD was previously chosen. Now, run

Select Setup → Simulator/Directory/Host.

A follow up window will pop up giving your simulator options. Select hspiceD. Also specify a run directory. Press ok.


Simulation Run Directory indicates where your simulation files will be stored. The generated netlist file will be stored within in a file called "netlist". All of the other options necessary for running the simulation are stored in this directory as well in the form of separate files like netlistHeader, netlistFooter. When you run the simulation, all the options are put together by the simulator. This is useful for storing separate simulation setups for different parts of your design.


Choosing Analysis Type and Length

From the Analog Environment window

Select Analysis → Choose

Make sure to select tran and specify an appropriate stop time and time step (example 1ns). The start time is typically 0. Be sure to choose a stop time that is greater than the period of the input signal. Hspice supports the SI prefixes so 500n would be 500 nano seconds.


Adding Model Library Files

The next step is to add the spice data for the simulator.

Select Setup → Model Library Setup .

We will be adding the data for the NMOS and PMOS transistor.



Click on Add File and add these files:

/mada/software/techfiles/FreePDK45/ncsu_basekit/models/hspice/tran_models/models_nom/NMOS_VTL.inc
/mada/software/techfiles/FreePDK45/ncsu_basekit/models/hspice/tran_models/models_nom/PMOS_VTL.inc

For tsmc_02d, the spice files are:

/mada/software/techfiles/ncsu/models/hspice/public/tsmc18dP.m
/mada/software/techfiles/ncsu/models/hspice/public/tsmc18dN.m


Select OK when finished.

These options will be added to a file called input.ckt

Running Simulation

To run a simulation, first select the type of analysis in Analysis → Choose... For a transient, specify the stop time (e.g. 1n).

It is easier to not add voltage sources to the inputs directly and instead make stimulus in a file. You can edit a stimulus file directly and include it in your simulation. Open a text file in your simulation directory and create something like this:

// Stimulus Statements Hspice format 
.param tdelay=0n
.param trise=1n
.param tfall=1n
.param tpulse = 500n
.param vhigh=1800mV
.param vlow=0
v_A  A  0 pat (vhigh vlow tdelay trise tfall tpulse  b01010101  rb=1 r=1)
C_Z Z     0 10p

The .param statements above are used for parameterizing simulation variables. This way, if you wish to change some values for simulation, you only need to change it in the .param statement and it will take effect throughout. The v_A is a voltage source statement producing a bit stream of 01010101 as stimulus with rise,fall and pulse width times defined in the .param statements. Save the file you have now created as stimulus.sp and store it in your simulation directory.

To specify the stimulus, select Setup → Simulation Files... and provide the path to your stimulus.sp. Or, if you have a large design, you can generate a VCD file from verilog to perform your stimulus.


For more information on Hspice commands you can look at the manual:

/mada/software/synopsys/H-2013.03/hspice/docs_help/hspice_sa.pdf

Ouput Window

Before Running, select Output → Save All... to save all schematic data. (Note, this might not be best on big designs!) Or, you can select Outputs → To Plot → Select on Schematic and then click on all of the items on the schematic.

Then,

Select Simulation → Run

This will generate the netlist file, run the simulation, and save the results for the waveform viewer. You should re-run this every time you change your schematic.

You can also select Simulation → Create Raw to create the raw simulation file for debugging. You should be able to see your include stimulus, netlist, and a bunch of other stuff.

If this pops up a window that says it failed, fix the previous options. You need to debug this by looking at the output of the simulator in si.log (which is the output of running the simulator, if the simulator failed to run) or si.out (which is the actual simulator output if it ran successfully, but simulation may have failed). This will show you if it even got to the point of running the simulator.


If it succeeded, you can select Tools → Waveform . When you do this, you get three windows:

Waveform graph.jpg Waveform browser.jpg Waveform results.jpg

Select the "File Open" icon and then find the appropriate "raw" result file in the browser. This should open the data in the browser. Double click on the transient simulation directory and you should see signal names that correspond to your design. Double click on "A" to add it. Change the upper right option to "Append" and double click on "Z" to add it as well. If you don't change the option, it will replace the A waveform with Z. If there are problems with vdd! and gnd! you can debug that here.

You should get something that looks similar to this in the graph window:

Output waveform.jpg

Note that your signals should always rise to full vdd (1.2V) and down to gnd (0V) or else something is wrong with your logic. This is CMOS so everything is "rail to rail". It is likely an unconnected supply voltage or floating body.

Waveform - Zooming and Trace

With the waveform window open, you can zoom in and find exact values.

Zoom

Select Zoom → X Zoom .
Now click and drag in the waveform window to select the x-range you want to zoom to.

Tracing

Select Marker → Place → Trace Marker

Zoom waveform.jpg

Click on one of the waveforms in the window. This places a small label on the waveform. You can drag this marker anywhere on the waveform.

Separate Windows

Sometimes the window will get too cluttered. You can plot each signal in a separate window by clicking the 4th icon in the toolbar from the left to put it in "Strip Mode".

Reloading

If you make a change and resimulation, you can simply click File → Reload

Exporting Tip

If you intend to export the plot, it would be wise to change the background color to something other than black. In addition you can change the width of the lines by right clicking on the line and selecting properties.

Power/Energy Analysis

To enable power analysis in hspice, add this statement to your stimulus file:

.measure tran toplvl_avg_power avg   power from=0ns to=100ns
.measure tran toplvl_avg_energ integ power from=0ns to=100ns
.measure tran toplvl_avg_current avg I(VDD) from=0ns to=100ns

For more information on the .measure syntax, please refer hspice user guide at:

/mada/software/synopsys/H-2013.03/hspice/docs_help/hspice_sa.pdf

You can then plot the power in the waveform viewer. It will be shown with all the other signals. In order to find the average power, you select :pwr and click on the calculator option instead of the plot option. In the calculator window, select "average" in the special functions. Then select the "Evaluate" button. (It is on the right of the "Clip" option and to the left of the Table and Append options). This will give you the average power in Watts.

SpectrePower.jpg



To enable power analysis in Ultrasim

1) go to Simulation->Options->Analog
2) In the "Advanced Checks" section, check the button near "Power analysis" and click on Setting
3) In the window that opens up
3.1) Enter * for the "subckt name"
3.2) Select max in the "Output Sorting" section
3.3) Click on the power and enabled button
3.4) Click on Add at the top
3.4) Click OK to close the window
4) Click OK to close the "Simulator Options" window
5) Simulate as usual (Simualte->Netlist and Run)
6) Look for a file called "input.pa", most likely under /cse/grads/USERNAME/cadence/simulation/comb_adder/UltraSim/schematic/psf/input.pa
The file will list Max,Avg and RMS power for each pin in your design, and the time in which the maximal power consumption occurred.

Energy is simply the RMS power multiplied by time

Power.jpg

Documentation

Finally, for more help...


Open file:///home/cadence/MMSIM61/doc/UltraSim_User/UltraSim_UserTOC.html in your web browser on firedance.