CirSpice

Values and expressions

Numbers, suffixes, expressions and source waveforms, as CirSpice reads them.

User guide / 5. Values and expressions

CirSpice reads values the way Micro-Cap writes them, so a circuit means the same in both. This page covers the basics: numbers, suffixes, simple expressions and the source waveforms. Parts' own fields are listed per type in Part types.

Numbers

A number can be written plainly (470, 0.5, .5), with a sign (-12, +3), or with an exponent (1e-6, 2.2E3).

Scale suffixes

A letter after the number scales it. Upper and lower case mean the same.

SuffixMultiplies byExample
T10121T is 1e12
G1092.4G is 2.4e9
MEG1061MEG is one million
K1034.7k is 4700
M10-310m is 0.01
U10-622u is 22e-6
N10-9100n is 1e-7
P10-1233p is 3.3e-11
F10-155f is 5e-15

Watch out for M: it means milli, not mega. A one-megohm resistor is 1MEG; 1M is one milliohm.

MIL is not a suffix either: 1MIL reads as 1m followed by the letters IL, that is 0.001.

Unit letters

Letters after the number and its suffix are a unit name and are ignored: 10kOhm is 10k, 1nF is 1n, 6V is 6. Only the suffix counts, so 1F is one femto, not one farad: write a one-farad capacitor as 1.

A letter in place of the decimal point

A scale letter between digits marks the decimal point, as on component markings: 2k2 is 2.2k, 4M7 is 4.7m, 4meg7 is 4.7MEG, 1u5 is 1.5u. R does the same with no scale, so 8R2 is 8.2. Other letters work as a plain point too: 3v3 is 3.3.

Expressions in values

A part's value can be an expression of constants, written in braces or bare: {2*4.7k}, {1/(2*PI*1k*100n)}. CirSpice works it out once, when the circuit opens, and the simulator sees the number.

An expression may use the names a circuit defines on its text page: global parameters from .PARAM and text substitutions from .DEFINE. See .PARAM and .DEFINE.

Formulas that change during a run

The function sources (Function Voltage Source and Function Current Source) take a formula that the simulator evaluates at every step. A formula can use:

  • time T, the constant PI, and numbers with suffixes;
  • node voltages V(node) and V(node1,node2), and the current I(part) of a voltage source or a plain resistor;
  • + - * /, comparisons, and AND, OR, NOT;
  • the functions SIN, COS, EXP, ABS, TANH, LN, LOG and LOG10 (both base 10), U (the unit step), MIN, MAX, LIMIT, IF, TABLE and DELAY.

For example, IF(V(IN)>2.5, 5, 0) or 10*TANH(V(A,B)/0.1). A name outside this list, such as SQRT or the ^ operator, is refused with a message rather than guessed. The current list for each source is in its entry in Part types.

Source waveforms

A voltage or current source's value describes its DC value, its AC value and its waveform in time, in any order. A number on its own at the start is the DC value.

WriteMeaning
DC vThe DC value, used by the operating point and the DC analysis. DC=v works too.
AC mag [phase]The source's size in an AC analysis, with an optional phase in degrees.
SIN vo va f [td [damping [phase]]]A sine wave: offset, amplitude, frequency, then optional delay, damping factor and phase, in the usual SPICE order.
PULSE v1 v2 [td tr tf pw per]A pulse from v1 to v2: delay, rise time, fall time, width and period.
EXP v1 v2 [td1 tau1 td2 tau2]An exponential rise to v2 starting at td1, then a fall back starting at td2 (an absolute time).
SFFM vo va [fc mi fs]A frequency-modulated sine: offset, amplitude, carrier frequency, modulation index, signal frequency.
GAUSSIAN amp tpeak width [period]A Gaussian pulse peaking at tpeak, repeating every period when one is given.
PWL t1 v1 t2 v2 ...A piecewise-linear wave through the points given, times in order.

The arguments may be in parentheses with commas, as in SIN(0 1 1k) or PULSE(0, 5, 1u). Each argument can use suffixes and constant expressions in braces.

Piecewise-linear sources

  • Spaces, commas and parentheses all separate the numbers, which are read two at a time: PWL 0 0 1m 5 2m 5 3m 0 and PWL (0,0) (1m,5) (2m,5) (3m,0) are the same wave.
  • Two points at the same time make a step. A time earlier than the one before it is refused, as Micro-Cap refuses it.
  • REPEAT FOR n ... ENDREPEAT around the points plays them n times, each pass starting where the last ended; REPEAT FOREVER repeats to the end of the run.
  • TIME_SCALE_FACTOR=x multiplies every time, and VALUE_SCALE_FACTOR=x every value.
  • Points read from a file, a trigger and a point written as an expression are not supported yet: CirSpice says so when the circuit opens.

Example: a 1 kHz square wave between 0 and 5 V with 1 us edges is PULSE 0 5 0 1u 1u 499u 1m.

Micro-Cap's own Sine and Pulse sources

Micro-Cap also has a Sine Source and a Pulse Source that take their settings from a model rather than from their value. They are listed with their fields in Sine Source and Pulse Source.

Worked examples

A filter set by one parameter

To try an RC low-pass at several corner frequencies without working out each capacitor by hand, put the design on the text page:

.PARAM FC=1k R0=1k
.PARAM C0={1/(2*PI*FC*R0)}

Give the resistor the value {R0} and the capacitor {C0}. With FC at 1k, C0 works out at about 159.2n; change FC to 10k on the text page and the capacitor follows, at about 15.92n. Each .PARAM may use those before it.

Reading a value

TypedRead asWhy
4k74700K in place of the decimal point
1M0.001M is milli
1MEG1000000MEG is mega
10uF0.00001U is micro; the F after it is a unit name, ignored
1F1e-15F alone is femto
3v33.3a letter between digits is the point
2.2E32200an exponent
{2*4.7k}9400a constant expression, worked out once

A repeating staircase

PWL REPEAT FOR 3 (0,0) (1m,0) (1m,1) (2m,1) (2m,2) (3m,2) ENDREPEAT

Each pass is a staircase of three 1 ms steps, 0, 1 and 2 V; the pairs at the same time make the steps sharp. Passes follow each other, each starting where the last ended, so the wave runs for 9 ms. With TIME_SCALE_FACTOR=2 before REPEAT, every step lasts 2 ms instead.

One source for every analysis

A voltage source with the value DC 2.5 AC 1 SIN(2.5 0.5 1k) holds 2.5 V for the operating point and a DC sweep, counts as 1 V in an AC analysis, and in a transient swings 0.5 V either side of 2.5 V at 1 kHz. Write all three parts once, and switch analyses without editing the source.