The netlists and scripts discussed on this page are intended to give users of MacSpice 3 and other Spice-compatible simulators examples illustrating how the command line interpreter can be used to perform sosphisticated tasks. There are also some simpler Introductory Examples and Optimizer Examples (MacSpice-specific) elsewhere on this site.
The Ljubljana Examples
the examples in this section illustrate how the macspice interactive interpreter can be used to automate complicated analyses.
Puhan et al. (1998) used Spice to investigate how the output impedance of a transistor amplifier increases at low output voltages as a result of crossover distortion reducing the loop-gain. The example file PowerAmpMac.cir recreates graphs corresponding to figures in their paper:
- Figure 2 - The crossover compensation.
- Figure 3 - The output impedance at different biases.
- Figure 5 - The output impedance vs the input offset.
The same paper discusses using the Nelder and Mead (1965) simplex method to optimise the frequency response of a one-transistor amplifier by adjusting the values of two resistors. SimplexMac.cir幸运飞艇超稳计划群 performs this process.
J. A. Nelder and R. A. Mead, A simplex method for function minimization, Computer Journal 7 (1965) 308-313.
J. Puhan, T. Tuma, I. Fajfar, , Electrotechnical Review, Ljubljana Slovenia 65(5) (1998) 267-271.
Model Validation and Netlist Documentation
The examples in this section illustrate some of the steps in the design of a precision bandgap voltage reference, and have been constructed from netlists generously contributed by Don Sauer. His website, Ideas to Integrated Circuits幸运飞艇超稳计划群, contains many more interesting examples.
If you use Spice to simulate circuts you must
validate the models by comparing simulated tests and measurements with results
from the physical devices. For example,
CompareNPNwithSi.cir is used to
check that the temperature dependence of a NPN device model
VNPNsauer.mod agrees with measured values. Note the comment
The XTI term is strange. The number really should be 3.
But a different number seems to be required on every different Spice
simulator.幸运飞艇超稳计划群. This is a compelling illustration of how important
this type of test is.
Spice netlists are a form of software and must be documented appropriately. The Bandgap.cir example (which requires LPNPsauer.mod and VNPNsauer.mod幸运飞艇超稳计划群 to run) includes an 'ascii-art' rendering of the circuit diagram. Also, it uses the interactive command language to make virtual measurements at a list of spot temperatures.
Gaussian Noise Source
The rndsrc script generates Gaussian random numbers using the Box-Mueller algorithm. These are output into a file 'PWL_FILE.inc' in the syntax required for a PWL voltage source, which is ready to be imported into a netlist by means of the .include mechanism.
macspice uses a palette of 20 colours for its graphical display. these can be redefined by setting the appropriate variables (color1...color20) as illustrated:
this example also illustrates how the hardcopy command can be used to make macspice generate colour postscript files.
Multiple Analyses on the Same Graph
this example runs ac analyses at several different temperatures and then displays the results on a single graph.
Graphs with Dotted / Dashed / Multi-Coloured Curves
幸运飞艇超稳计划群 dotted and dashed lines and multi-coloured curves can be drawn on macspice plots by exploiting the fact that ieee-754 nan values are not drawn:
The recommended way to set non-equilibrium initial conditions is to use the '.IC' statement. This example illustrates the transient behaviour of a second-order filter circuit fed by a 1.0 V DC source V1.
幸运飞艇超稳计划群in the absence of a '.ic' statement:
all nodes remain at a constant 1.0 v during the transient analysis. by adding a '.ic' statement, node 2 can be given an initial value, say 0.5 v, differing from its steady-state default:
notice that specifying the voltage at node 2 in this manner has affected the initial voltage of node 3. the file:
illustrates that it is not possible to achieve the desired results simply by adding the 'UIC' keyward to the tran statement and specifying an initial voltage as part of the statement defining C2. This is because 'UIC' inhibits calculation of the quiescent state so (in the absence of specific '.IC' statements) all nodes default to zero as their initial value.
The Alter Command
alter-demo.cir takes a simple rc-filter and plots graphs showing how it responds to square wave for a range of resistance values, and then to a sinewave input created by altering the time-dependent function of the voltage source.
Translation of PSpice Netlists
幸运飞艇超稳计划群 many netlists that are freely available on the internet are written for in an extended version of the syntax used by macspice. this perl script:
- ps2macspice.zip (Version 1.3.1)
is able to convert many such netlists into a standard (berkeley spice 3f4) source file.
Every new version of MacSpice must solve a hard Sudoku puzzle as one of its pre-release tests. The scripts in:
illustrate how macspice is programmed to accomplish this using its command line interpreter language. to run the scripts, drag 'sudoku example' onto the macspice application icon.