MacSpice > Advanced Examples

MacSpice Icon

Advanced Examples

Introduction

The netlists and scripts discussed on this page are intended to give users of MacSpice 3f5 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:

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.

I am grateful to Janez Puhan for providing a copies of the original (poweramp.cir) and (simplex.cir) examples referred to in the above paper.

References

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, SPICE for Windows 95/98/NT, 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.

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 observing that The XTI term is strange. The number really should be 3. But a different number seems to be required on every different spice simulators.. 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. 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.

Plot Colour Schemes

MacSpice uses a palette of 20 colours for its graphical display. These can be redefined by setting the appropriate variables (color1...color20) as illustrated in the colorscheme.src example file. It also illustrates how the hardcopy command can be used to make MacSpice generate colour PostScript files.

Initial Conditions

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.

Equation

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 v(3) has zero as its initial value.