CirSpice

Text pages

The statements CirSpice reads from a circuit's text, generated from the app itself.

User guide / 4. Text pages

A Micro-Cap circuit can carry text beside its schematic: models, parameters, definitions and subcircuits written as statements, one per line. A line starting with * is a comment, a ; ends a line's statement and starts a comment, and a line starting with + continues the statement above it.

Each entry below says how CirSpice reads the statement, in the app's own words, and lists the messages that name it. A statement that is not listed here is kept in the file exactly as written, and saved back unchanged, but not used in the simulation; the Messages tab says so when the circuit opens.

.MODEL

Defines a model that parts name by their Model attribute. The type after the name says what kind of part uses it (D, NPN, NMOS, RES and so on, listed per part in Part types), followed by the parameters, optionally in parentheses. A long model can continue on lines starting with +.

.MODEL DSMALL D (IS=1e-14 N=1.8 RS=0.5)
.MODEL QSMALL NPN (IS=1e-14 BF=200
+ VAF=100)

A model on a single line can be edited from a part's attribute dialog (its Model... button). One that spans several lines is read and used but kept in the file exactly as written: edit it in the text.

Messages that name .MODEL (16)

.PARAM

Defines global parameters: names with values that parts' values, models and library subcircuits can use. Each may use the ones before it.

.PARAM VCC=5 RLOAD={VCC/10m}

A part's value can then be {RLOAD}.

How CirSpice reads it

  • .PARAM, a global parameter that parts' values and library calls see
  • .PARAM, a global parameter that library subcircuit calls, bodies and parts' values see
  • .PARAM …=… is not read: it names something not given, or a number with letters that are no scale or unit
Messages that name .PARAM (5)

.DEFINE

Defines a name that is replaced by its text wherever it appears in parts' values and model parameters, before they are read. Unlike .PARAM, it substitutes text rather than a number, so it can stand for any part of a value: a number, a waveform, or a piece of a formula.

.DEFINE RVAL 4.7k
.DEFINE CLOCK PULSE(0 5 0 1n 1n 50n 100n)

A resistor whose value is RVAL then has 4.7k, and a voltage source whose value is CLOCK gives a 10 MHz square wave.

A definition can take arguments, as in .DEFINE SQ(x) (x)*(x); a call must give as many as the definition names. A definition that refers to itself, directly or through others, is refused, and so are two enabled definitions of the same name with different text.

A part whose value is written with .DEFINE names shows them in its attribute dialog, read only: edit the definition on the text page, so that every part using it changes together.

How CirSpice reads it

  • .DEFINE, substituted into attribute values and model parameter values
Messages that name .DEFINE (15)

.SUBCKT

Defines a subcircuit: a block of SPICE elements with named ports that parts can call by name. The definition ends with .ENDS.

.SUBCKT DIVIDER IN OUT GND
R1 IN OUT 10k
R2 OUT GND 10k
.ENDS

When a circuit defines the same name twice, Micro-Cap uses the first definition, and so does CirSpice; the second is kept in the file but not read.

How CirSpice reads it

  • .SUBCKT …: an empty stub after the file's first definition of the name, which is the one used, kept verbatim
  • .SUBCKT … again: Micro-Cap runs the file's first definition of a name, so this one is kept verbatim and not read
  • .SUBCKT …: read into a subcircuit definition, kept verbatim
  • .SUBCKT … is not read: …
Messages that name .SUBCKT (8)

.ENDS

Ends a .SUBCKT definition. Every .SUBCKT needs one; a definition without it is refused, since CirSpice cannot tell where it stops. See .SUBCKT.

Messages that name .ENDS (1)

.LIB

Names a library file in which the circuit's parts are looked for, after the circuit's own text. See Models and libraries for the search order.

.LIB "mylib.lib"

How CirSpice reads it

  • .LIB statement, a library file the circuit's parts are looked for in
Messages that name .LIB (1)

.OPTIONS

Sets simulator options for the whole circuit, as NAME=value pairs. CirSpice passes on the options that mean the same in Micro-Cap and in ngspice: the tolerances RELTOL, ABSTOL, VNTOL and CHGTOL; GMIN; the iteration limits ITL1 and ITL4; the nominal temperature TNOM; RSHUNT; the default MOSFET sizes DEFL, DEFW, DEFAD and DEFAS; TRTOL; and METHOD, where the last one in the file wins.

.OPTIONS RELTOL=1e-3 ITL4=50 METHOD=GEAR

An option whose effect has been checked against Micro-Cap only at its default value is refused at any other value, with a message naming it. The settings offered when a run fails (see When a run fails) are written into this line when you save.

Messages that name .OPTIONS (3)

.IC

Sets initial node voltages for the start of a transient run, as V(node)=value entries. CirSpice reads V(node)= entries today; other forms are refused with a message that says which.

.IC V(OUT)=0 V(N1)=2.5
Messages that name .IC (17)

.ARRAY

Defines a named list of numbers that values can index: .ARRAY name v0,v1,v2,.... A value can then use name(i) with a constant index, counting from 0, and CirSpice puts the element's number in its place when the circuit opens.

.ARRAY RS 1k,2.2k,4.7k

A resistor with the value {RS(2)} is 4.7k. An array whose elements are not all numbers, or that a value uses in a way that cannot be worked out once, is kept in the file but reported as not read.

How CirSpice reads it

  • .ARRAY … is named in a value it could not be folded into, or is not a list of numbers
  • .ARRAY, folded into the values that name it
Messages that name .ARRAY (1)

.IF

Keeps or drops lines of the text page depending on a condition, as a preprocessor would: .IF condition, then optionally .ELIF condition and .ELSE, ending with .ENDIF. The condition can use the names defined with .DEFINE above it, and a single = means equality.

.DEFINE FAST 1
.IF FAST=1
.DEFINE RLOAD 100
.ELSE
.DEFINE RLOAD 10k
.ENDIF

CirSpice drops a branch not taken only when it holds .DEFINE lines, comments and blank lines. Any other statement inside a branch not taken is refused with a message, since it may be read elsewhere and dropping it silently could change the circuit.

Messages that name .IF (4)

.ENDIF

Ends a .IF block; see .IF. A .IF without its .ENDIF, or an .ENDIF without its .IF, is refused.

Messages that name .ENDIF (2)

.PARAMETERS

Declares a macro's parameters, with their defaults, on the macro's own schematic: .PARAMETERS(GAIN=10, ROUT=1k). A circuit that uses the macro can set each one per part; one left unset takes its default. Inside the macro, the names stand for the values given.

Each item must be name=default, and a name may be declared once.

How CirSpice reads it

  • .PARAMETERS, the macro's parameters, read as symbols holding the call's values or the defaults
Messages that name .PARAMETERS (2)

.HELP

Documents a macro's parameter for Micro-Cap's dialogs. It does not affect the simulation, so CirSpice reads past it and keeps it in the file.

How CirSpice reads it

  • .HELP, a macro parameter's documentation, not simulation input

.SPICE

Starts a block of plain SPICE lines that are part of the circuit, ended by .ENDSPICE. CirSpice reads the block's top-level R, C, L, V, I and X lines as parts of the circuit, joined to the schematic by node name, and also SPICE E and G lines written with TABLE or VALUE. Its .TRAN, .PROBE and .END are ignored: the circuit's own Analysis Limits rule.

.SPICE
RBIAS VCC BASE 47k
CBYP EMIT 0 10u
.ENDSPICE

Other kinds of SPICE line in the block are not read yet, and the Messages tab says which. Parts defined here appear in the simulation but not on the schematic, so they are edited in the text.

How CirSpice reads it

  • .SPICE: the lines up to .ENDSPICE are SPICE circuitry spliced into the schematic
Messages that name .SPICE (10)

.ENDSPICE

Ends a .SPICE block; see .SPICE.

How CirSpice reads it

  • .ENDSPICE: ends a .SPICE block

.SMOKE

A model for Micro-Cap's smoke test, which checks parts against their ratings. It is not a simulation input, so CirSpice keeps it in the file without using it.

How CirSpice reads it

  • .SMOKE model for the smoke analysis, not a transient input

.MACRO

In a Micro-Cap library, .MACRO gives a macro a second name, an alias. CirSpice follows aliases when it looks for a part in your imported library (see Models and libraries). When one name is both a definition and an alias, it is refused, since which one Micro-Cap takes is not known.

Messages that name .MACRO (2)

.DC

On a circuit's text page, a .DC line is kept but not used: set a DC sweep in the DC analysis's limits instead (see DC). The sweep variable must be an independent voltage or current source, or TEMP.

Messages that name .DC (3)

.FUNC

Defines a function in a vendor's PSpice model file, such as .FUNC LIMIT3(x) {MIN(MAX(x,-3),3)}. CirSpice reads it when it imports vendor models (File > Import Vendor Models), and refuses a call to a function the file does not define.

Messages that name .FUNC (2)