Simulation

Spice

Spice has a very long 30 years history in simulation. It is therefore a command line tool but many gui tools exist to make use (and abuse) of it. There is the originalhttp://bwrcs.EECS.Berkeley.EDU/Classes/IcBook/SPICE/ version but there is also the next generation spice ngspice http://ngspice.sourceforge.net/presentation.html#

Since many tools are used that can run standalone and exchange various data in various formates many things can go wrong. To get a good overview and troubleshoot it is good to spend some time and run everything using the command line.

Spice with command line

To work in the console a text file describing the schematics need to be created. Those files have usually cir as file extension.

astable oscillator
*
.tran 10us 10ms 1ms
*
vcc vcc gnd 12.0
r1 vcc b2 22k
r2 vcc b1 22k
r3 vcc o1 1k
r4 vcc o2 1k
c1 o1 b2 0.1uF
c2 o2 b1 0.1uF
q1 o1 b1 gnd generic
q2 o2 b2 gnd generic
*
.model generic npn
*
.end

The files start with a title line and end with .end. * is used to mark a line as comment. The term node is used for the electrical wires between the components. For the simulation it is important to name a node gnd (or 0) since many things default to gnd and therefore the simulation could fail. The lines start with the type of the component used with a number attached in case of multiple types. The follows a list of nodes where the components pins are attached. Finally a list of values that describe the characteristics follow. Some desired actions can be put in the file as .tran to define the transient analysis, the parameter following are the time between calculation steps, and the end time it is good to use units as e.g. 1ns for the step time. There are more options as adding a third time as start time to not see the initialization. Some components require a .model definition to set additional characteristics this seems to be necessary for junction transistors since the letter q does not specify if it is a PNP or a NPN type.

ngspice test.cir starts ngspice with the cir file and ends in the spice console. On the prompt type run to run the simulation. plot base will plot the node base (alternatively the command gnuplot<output filename> base can be used). A picture can appears that can be plotted as ps. op runs the DC simulation where print base gives the DC voltage on the node base. The command edit allows to modify the loaded file listing shows the input file Finally quit exits the spice shell.

ngspice can also run as a regular command line program and put the outputs as raw format to a file: ngspice -b osc.cir -r osc.out

The raw format output can be read by gwave osc.out

When gwave has successfully loaded the data, then two windows spear, one showing the wave form that look after the first start very empty but the second window shows all available signals as buttons, click on the buttons and drag the cursor into the panel area and the wave forms become visible

Spice with gui

Many programs to be used come from the http://wiki.geda-project.org http://wiki.geda-project.org/. An alternative of ngspice is gnucap, that is also supported.

To not work in the command line, the schematic has to be drawn fist. This is made preferably with gschem

Figure 2.7. gschem

gschem


To use the schematics there is gspiceui.

Figure 2.8. gspiceui

gspiceui


However gspiceui makes use of many other programs as ngspice (alternatively gnucap), gwave, gschem and makes mandatory to understand how the data is exchanged between those programs. Knowing that, allows also semi gui way by having multiple windows open and work partly in the console. Inside gspiceui there is also a console where the commands and their responses can be observed.

A .cir file used by spice has not all the information a schematics has, especially the 2D placement of the components, so an editor as gschem has to be used to draw a schematics and then imported in gspiceui. gspiceui does the creation of the cir file in two steps. When importing, it creates a file with that has .ctk extension. This file holds everything a cir file has except the simulation commands, that obviously do not come out of the schematics.

The schematics must hold all necessary spice characteristics so check the automatic created spice file (net list) to see what it got.

Note

Add the attribute netname gnd to the ground, since without gnd it is highly probable that the simulation will fail.

The spice component library in gschem holds the necessary components as power sources. Attributes have to be added to the components until the space behavior is fully defined.

For complexer components as transistors a reference to a model is required. ngspice supports certain models as (R, C, L, D, PNP, NPN, PMOS, NMOS, ...). The default values of those models can be overwritten by adding a parameter list. Such models are used in two steps. The first attribute is a reference to a model_name. The second attribute that needs to be set just once on the schematic page is the model itself. In the .ckt file this creates a .model line. This line defines the model and it characteristics (the following models uses defaults so just npn remains):

model_name mytransistor
model mytransistor NPN

Other model descriptions look more complete and can be found on the internet as

.model Q2N2222A NPN (IS=14.34F XTI=3 EG=1.11 VAF= 74.03
BF=255.9 NE=1.307 ISE=14.34F IKF=.2847 XTB=1.5 BR=6.092 
NC=2 ISC=0 IKR=0 RC=1 CJC=7.306P MJC=.3416 VJC=.75 FC=.5 
CJE=22.01P MJE=.377 VJE=.75 TR=46.91N TF=411.1P ITF=.6 
VTF=1.7 XTF=3 RB=10)
.model D1N4148 D (IS=0.1PA, RS=16 CJO=2PF TT=12N BV=100
IBV=0.1PA)

Those models are not enough to model integrated circuits. However integrated circuits can be modeled using those models. Any circuit including integrated circuit can therefore be defined as sub circuit and can be put between .SUBCKT <name of th IC> <list of pins> and .end. The .end <name of IC> can have optionally the component line to see to what the .end belongs to. For most of IC those spice models are available through the IC manufacturers, however they can be more or less precisely. Luckily those complex .subckt files from the manufacturer can be kept apart from the schematics. The link from the schematics to the .subckt file is done by setting the file attribute in gschem. Additional the model-name attribute needs to be set, since the file might contain multiple devices.

Note

The number of pins and its sequence need to match between schematic file and spice model, this is often not the case since both file have mostly different authors.

What is still missing are the type of simulation and its parameters to be performed, this can be set via the simulation tab. The a complete cir file with the extension .ckt is created and the simulation can be started. After the simulation has finished a ASCII file with .tr for transient is created. Inside the console of gspiceui just the first 1000 lines (as defined in the preferences) can be observed. Additionally the preferences allow an automatic delete of the simulation output files.

Simulation results can be observed using the wave form viewer gwave (or alternatively gaw gtk analog wave viewer). gwave can be started within gspiceui or as standalone application. It does not make use of the ASCII file with the .tr extension. It works with raw format.

Note

Versions below 1.0.0 of gspiceui seem to pass the tr file to gwave and gwave will show nothing. If running into a problem working in the console using cthe following commands might help: ngspice -b irtrans.ckt -r irtrans.out and gwave irtrans.out

Figure 2.9. gwave

gwave


Digital simulation

A pure java application is http://www.tetzl.de/java_logic_simulator.html it allows button led simulations java -jar LogicSim.jar starts it

java -jar hades.jar additional to button led simulation it also supports wave forms.

Irsim is a digital simulator http://opencircuitdesign.com/irsim/ on level of transistors but not circuits. It treats transistors as ideal. A good digital design does not make use of non ideal situations. Again, this simulator requires a .sim text file, xcircuit http://opencircuitdesign.com/xcircuit/is a tool to draw schematics and then export them to irsim.


Linurs startpage