Simulators & Design
Steve's Notes on Simulation & Design Tools
* SPICE * Schematic Capture * Verilog * VHDL * Layout *
Contents
Links either scroll to my notes or open an external webpage:
Spice Help & Programs
Hspice - Industry standard Spice vendor
NGspice, NGnutmeg - Free SPICE!
Tclspice (External Link) - FREE!
Spice & Schematic Capture
LTspice (Linear Technology's tremendous free schematic capture & spice program) - FREE!
Note: LTspice is highly recommended for schematic capture and SPICE.
Spice, Schematic Capture, & Logic Sim Combined
QUCS - FREE!
Verilog (Note some items listed elsewhere may include Verilog)
Sutherland's Tutorial (External Link)
Free Verilog Simulators (External Links)
VHDL: Ashenden's Tutorial (External Link)
Layout Only
Magic (External Links) - FREE!
Design, Sim, & Layout Suites
Berkeley Spice Resources
Includes free Berkeley spice, Hspice, Pspice, free Magic (layout). Promises to make IRSIM (logic simulator) available soon
General Spice Help Links
U of Exeter Berkeley Spice3 Manual (External Link)
U of Exeter's Electronics Resources Page (External Link)
Scroll to the section with Spice links.
This PDF is for Berkeley Spice3 but may apply quite well to the Spice you use.
In AC analysis of an amp with feedback in LTspice, using a reference DC amp and another copy with an AC stimulus, I have gotten convergence by:
Double-check no stupid mistakes, such as floating nodes, shorts, or feedback going to the wrong amp input.
First get .OP to converge, and savebias internal to a file. I.e., .savebias <filename> internal
Run the AC analysis using .loadstate <filename>. Sometimes I still need to lower the tolerances for the AC to converge.
To get .OP convergence:
Overcompensate all amps. Add caps to nodes that may benefit from them.
Add large series R to V sources
Loosen tolerances and Gmin as much as necessary. If you loosen these enough, you will converge.
After getting convergenc, use .savebias internal and.loadbias to initialize a 2nd .OP with slightly less series R's or slightly tighter tolerances. Still use .savebias.
Continue savebias/loadbiase with gradually lower series R's, tighter tolerances, and less over-compensation until you get convergence for under acceptable conditions.
Do not remove large caps or overcompensation from portions of the circuit that are not meant to respond to the AC stimulus.
NGspice's List of Other Spices (External Link)
Hspice
A page on .measure cards in Hspice: http://www.ece.uci.edu/docs/hspice/hspice_2001_2-48.html
There’s an Hspice manual at http://www.ece.tamu.edu/~spalermo/ecen474/hspice_mosfet.pdf
Spice Models & Modeling
Help with Spice Models
A great doc on spice models: http://people.rit.edu/lffeee/SPICE.pdf
Converting Level 49 HSPICE to Level 9 PSpice
When writing your own SPICE MOS models, be sure to make your PMOS VT’s negative. If your amp’s gain < 1 or your PFETs conduct too much, double-check those VT’s.
Free Spice Models
These seem to be only NMOS & PMOS:
Some Berkely 0.25um/2.5V Models See also http://bwrc.eecs.berkeley.edu/Classes/icdesign/ee141_s00/Project/latest.htm
Fairchild Models Includes logic gates.
Ngspice, Ngnutmeg
Ngspice and ngnutmeg are free wrappers around Berkeley's spice and nutmeg free tools.
Typical command line
ngspice -o test.out -r test.raw -b test.cir
-o specifies the text output file
-r specifies the waveform output file
-b instructs ngspice to run in batch mode
test.cir is the netlist to run.
You should be able to invoke the ngspice command without specifying the full path, whether in UNIX, LINUX, or MSDOS. Just make sure the executable's directory is in your PATH variable.
Starting ngspice from MS Explorer window (interactive mode):
Double click on ngspice.exe which you probably put in C:\Spice\bin
*** ngspice window:
cd c:\spice\tests\bsim4
source comprt.cir
run
display
plot v(1) v(2) v(3) v(8) v(9)
write comprt2.raw
quit
To view waveforms, type ngnutmeg test.raw
Nothing exciting comes up when you invoke ngnutmeg. But type, for instance, plot v(d_in) and a plot of d_in comes up.
LTspice
Aka SwCADIII
LTspice Section Contents
Description
LTspice is a schematic capture and SPICE simulation tool by Linear Technology. The tool works great. I have read that (allegedly) Linear uses it for its own designs. A nice user's manual is included but not comprehensive, but websites and user forums provide quite a lot of assistance.
Links
Linear Website: http://www.linear.com/
Linear's Software Page: http://www.linear.com/designtools/software/
Help Not in LT's Docs
Users' group: http://tech.groups.yahoo.com/group/LTspice/ Join this group!
http://ltwiki.org/index.php5?title=Undocumented_LTspice
http://denethor.wlu.ca/ltspice/
Super-long “tutorial” on simulating in LTspice: http://www.scribd.com/doc/51765014/LTspice-4-e2
http://www.ece.uic.edu/~vahe/ltspice/Introduction_to_LTspice.pdf
Steve's Personal Help Notes
Sub-Contents
Moving Device Parameters
MOSFETs
Op Amp, Ideal
Devices
BJTs
You can change the model of a PNP. You do not have to place a PNP4. A PNP4 may be undesirable, since it has 4 terminals and you may mean for the collector to be the substrate. Just place a PNP. The model name does not seem editable with a right-click, but it is editable with a <ctrl><right click>.
Moving Device Parameters
Move parameters like you move anything else: F7, then click what you wish to move.
MOSFETs
If you want to edit W and L, instantiate (F2) nmos4 or pmos4, the monolithic 4-terminal MOSFETs. Do not instantiate the 3-terminal nmos or pmos, because those come without the W and L parameters. You can probably get around that limitation by editing the spice lines using <ctrl><right-click>, but I’m not sure and why bother.
To change the model to whatever model you want, just right-click and edit the model name.
To make W, L, MI visible, ctrl-right-click the symbol. Click twice, in the right column, the W, L, MI line (Value2). This assumes you placed NMOS4 or PMOS4 and already right-clicked to set the values of W, L, and MI. You can’t even set W, L, and MI in NMOS and PMOS.
To move a symmattribute, such as W or L, just move it (F7). If you need to rotate it, do <ctr l>R during the move.
Op Amp, Ideal
I usually instantiate the universal opamp 2, because that one does not need you to provide a subcircuit. You can set its parameters in its dialog box.
Busing
Instances and nets are bused if named using bus notation:
Bussed instance example names:
PLL<7:0>
LDO[5:99]
V1<3:1>
V1<1>
Bussed net names
PLL<7:0>
LDO[5:99]
V1<3:1>
V1<1>
You may not wish to name a net PLL or LDO, but you can. Scalar names are in the form net0, N1, VDD, XTEST, etc. LTspice likes to name instances starting with an "X", but the "X" is not necessary.
To bus an instance, simply give it a bussed name. To change the name, right-click. Then double-click the instance name and append the bus notation. E.g., change M1 to M1<1:0>.
From the edit menu you can add a bus tap. The wide end goes to the bus, and the point goes to the 1-bit net tapped off, which gets named [n], where n is the bit number. However, bus taps are not truly necessary, so why use them?
Functions, Constants, Parameters
Pi = pi
Abs(x) returns the absolute value of x.
Cos, sin work as expected, in radians.
To specify a parametric value for an element, for instance to set a cap’s value to a parameter CL, in the dialog box set the value to {CL}. I.e., you must use curly braces. Then you can do .step param CL LIST 1pF 17pF 22pF or .step param CL 10pF 110pF 20pF (20 pF increments).
.step PARAM CL LIST 1pF 10pF 88pF 1.2pF
When I give a resistor value of, say, {100k*RF} and define RF to some number using .param, I get warnings saying RF is undefined. But in tests, it all works correctly.
Gotchas & Troubleshooting
Add the u after all dimensions in microns.
Flip your PFETs. MOSFETs get instantiated with source downward. This is hard to tell from looking at them. The gate terminal is on the source side. So when instantiating PFETs, usually you have to turn them upside down. This might not affect performance for symmetric devices, but it will certainly affect what LTspice tells you is the VGS.
Be sure to instantiate PNP’s with the emitter connected correctly. The emitter tends to default downward, which is normal but not how the device is used in twin-well CMOS bandgap references.
Backup sub-directory: LTspice has an aggravating habit of changing the primitives directory on you. At least for me, when I instantiate a promitive from the normal lib\sym directory, the next time I try this the menu goes down into the Backup subdirectory. The difference is very hard to notice. Minimize the times you instantiate anything from the sym directory. Instead, once you know you have a primitive from the sym directory already instantiated, just copy it.
If .OP reports gds=0, Cbd=0, etc., you may have messed up your .include <model file pathname> syntax. If you set your device names to generic names like NMOS and PMOS, LTspice uses default level 1 models. It is safer to never use such generic model names, because if you incorrectly include your model path, you may not know you are simulating with default models.
.Measure Cards
Parameters can be enclosed in single quotes or curly braces. All text is case insensitive. One may type .MEASURE or .MEAS.
Functions Include
ABS: absolute value. Works on real and complex variables.
D: Derivative with respect to the X-axis. E.g., d(vout) returns the deriviative of vout.
MAG: magnitude of a complex (AC) variable. For instance, if a unit AC stimulus goes through an amp, whose output is vout, then unity gain is at mag(v(vout)) = 1
When writing magnitudes, LTspice includes the phase. I.e., if you print mag(v(vout)), you get the same result as when printing v(vout). This is only an issue when printing the value to file. Math performed using .measure cards leaves out the phase, when you use the mag function.
.Measure in AC Analysis
Default output format is “Bode,” but you can change to Cartesian or Polar. Refer to the manual.
Default output looks like this: (-0.00811642dB,38.7379°) 325348
.Measure AC outputs report values as complex numbers in dB (Bode mode). But math performed on these numbers is on the complex numbers, not 20log(the numbers). For instance, if an amp’s 2nd stage output mag is 90db and the 1st stage’s output is 40db, then to get the gain of the 2nd stage (which is 50db), you divide: .measure AC A2Gain PARAM a2out/a1out (assuming a2out and a1out are the outputs of stages 2 & 1 respectively).
All AC .measure outputs are complex numbers. If you print measure the mag, you'll get a complex number with a phase of 0. So you might as well not use MAG when printing a value, because you'll still get complex format, just with the phase set to 0.
Measuring Phase Margin
To print a phase margin, measure the signal at the unity gain frequency, then post-process the data:
.meas ZeroGainValue find v(vout) when mag(v(vout)) = 1
If you used a unit AC stimulus and vout is the amp's output, then the phase returned by the .measure statement is your phase margin.
Example .Measure Cards that Work (or at least have worked)
.measure AC fug WHEN mag(v(vout)) = 1
Reports frequency at which v(vout) has a magnitude of 1 (0 dB, unity gain)
.measure AC ZG_value FIND v(vout) WHEN mag(v(vout)) = 1
Returns the complex value of v(vout), and the frequency when its magnitude is unity (0dB).
.measure AC MaxGain max mag(v(vout))
Returns complex value of v(vout) at its max magnitude.
.measure AC Gain1KHz FIND mag(v(vout)) AT 1000
Returns magnitude of v(vout) at 1000 Hz. But prints output in complex format, so you might as well have just asked for v(vout) instead of mag(v(vout)).
.measure AC AmpIn FIND v(plus) - v(minus) AT 1 ; Reports voltage difference between plus and minus. Output is in complex format.
.measure AC Vcmin FIND (v(plus) + v(minus))/2 AT 1 ; Have not proven whether this reports the correct value, but have demonstrated it to print something.
.measure AC A1 FIND v(xtest:xamp:a1out) AT 1
.measure AC A2 FIND v(xtest:xamp:a2out) AT 1
.measure AC A2Gain PARAM A2/A1
.measure AC DCGain FIND v(vout) AT 1m
.measure AC Pole WHEN abs(DCGain/mag(v(vout))) = 1.414
.measure AC a1out FIND v(xtest.a1out) AT 0.01 ; This dives down the hierarchy into subcircuit xtest.
.measure tPer TRIG v(A) = 1.0 RISE=5 TARG v(A) = 1.0 RISE=6
.measure freq PARAM '1/tPer'
.measure 1xFreq PARAM {3*freq}
.Measure with .OP
.measure does not seem to work in OP mode when parameters are stepped. I think it's supposed to, but when I step parameters, only the last result gets printed. Not very helpful.
Operating Points
After a .OP sim, you can view operating point voltages by mousing over nodes in the schematic. For gm, gds vdsat, and other parameters, read the SPICE Error Log file. One can do that from the View menu, but I just open the file directly from the directory. The file has the same name as the sim schematic, with a .log extension.
.OP does not seem to work with stepped parameters. I have never gotten LTspice to output .OP results, not even from .measure cards, using any kind of stepped .OP analysis.
Saving Outputs
By default, LTspice does not save sub-circuit voltages and currents. You can fix that. In the schematic, select ToolsàControl Panel. Under Save Defaults, turn on subcircuit voltage and subcircuit current saving.
Saving Node Voltages & Currents
By default, LTspice limits "available" voltages and currents to those at the top level. You can change these and related defaults from the Control Panel. From the Tools menu, select Control Panel, and click the Save Defaults tab. You can also add a control card, ".save dialog" to bring up a dialog box asking you which nodes to save. This also allows you to click on the schematics--sort of. But you still won't be able to select voltages and currents below top-level, without first changing the defaults in the Control Panel.
Stepping
.step Vsupply LIST 1.6 1.8 2.5 2.8 3.0 ; where Vsupply is the name of a voltage source
.step temp LIST -40 27 125 ; Temp can also be specified using .PARAM.
.step PARAM CL LIST 1pF 10pF 88pF 1.2pF
LTspice allows 3 nested steps. You can effectively do more than that with clever tricks, such as:
.step param RC LIST 1 3 5 7
.param Rfactor = (sin(RC*pi/4))*1.414*.1 + 1
.param Cparam = (abs((cos(RC*pi/4) + sin(RC*pi/4))/1.414236))*19
.param CL = (1 + Cparam)*1e-12
*RC = 1,3,5,7
*RFactor = 1.1, 1.1, 0.9, 0.9,
*CL = 20pF, 1pF, 20pF, 1pF
One can run what is like a DC sim that sweeps a parameter instead of a voltage or current source:
.dc temp -40 125 1
.step Vsupply 1.5 3.0 0.25 (may also do .dc)
.step temp -40 125 82.5
Temp Coefficient
To add a temp coefficient, say of 0.0015, to a resistor or other device, right-click and add a Value2 of TC=0.0015.
Waveforms
<CTRL>A brings up the add a trace form. From there, you can click on as many outputs as you wish to plot. You can also type the signal names, and functions thereof. This is quite handy, as you can easily plot complicated functions, such as v(vout)/(v(in_plus)-v(in_minus).
To get data points, deltas, and slopes, right-click the desired signal name at the top of the plot window, and set Attached Cursor to 1st & 2nd. There will be a 1 and 2 in the center; you can move 1 and then move 2. It takes faith; trust this to work.
Tools==>Control Panel has an option to plot with or without thick lines. This setting gets remembered between program invocations.
Tools==>Color Preferences will tell you which color is which.
If you cannot view a waveform, check:
For floating nodes or wrongly-connected (not connected) nets in the testbench or schematic hierarchy.
Whether the node you’re trying to plot is already plotted, but from another level of hierarchy.
Whether schematic and symbol pins truly match.
Undocumented Functions
You can add a signal function or define the function in the netlist, or define a function to use frequently in the waveform viewer. Some aspects of this is in the documentation, but the available functions and constants are not documented. This is what help pages, like this one, and the LTspice user forum are for.
QUCS
Qucs (Quite Universal Circuit Simulator) is a free open-source GPL schematic capture and simulation program that simulates spice models, VHDL, etc. It is still under development but may be a great choice for logic simulation.
Electric
Steve Rubin's CAD Page Table of Contents - Chapter 11 is on Electric.
Installation & Download
These instructions assume a Windows environment but should be easily adaptable to other environments:
Go to Electric's Download Page and download the latest JAR file.
Unzip the JAR file into a directory, using any unzip program. Opening JAR files
You should end up with your original JAR file and a sub-directory filled with stuff. You can move the file and sub-directory anywhere you want to keep them.
It may help to read the README.txt file.
You should be able to invoke Electric by double-click the JAR file icon.
You may create a shortcut to the JAR file and place it in your Start menu or on your desktop.
You may add the JAR file to your DOS path. Adding Commands to DOS Path
If double-clicking the JAR file does not successfully invoke Electric:
Consult the README.txt file.
Check whether your Java is sufficiently up to date, as discussed in README.txt.
If your Java is not sufficiently up to date:
Uninstall Java using the normal Windows uninstaller.
Install latest Java.
These Installation Instructions include an applet you can use to test successful installation.
Electric User Groups & Email
You can also send email to info@staticfreesoft.com
Selected Helpful Info