SPICE Reference Guide #
Comprehensive reference for SPICE netlist syntax and commands supported in Breadpad. Breadpad uses ngspice, which is compatible with SPICE3 and includes many extensions.
Netlist Structure #
Basic Format #
* Circuit Title
* Comments start with asterisk
* Component Definitions
R1 nodeA nodeB 1k
C1 nodeB 0 100n
V1 nodeA 0 DC 5
* Analysis Commands
.TRAN 1u 10m
.PRINT TRAN V(nodeB)
.END
Netlist Rules #
- First line: Circuit title (comment)
- Node names: Alphanumeric, case-insensitive
- Ground: Node
0orGND - Comments: Start with
*or; - Line continuation:
+at start of next line - Last line:
.ENDcommand - Units: Use SI prefixes (k, M, m, u, n, p, f)
Component Syntax #
Passive Components #
Resistor
R<name> <node+> <node-> <value> [TC1=<val>] [TC2=<val>]
Examples:
R1 1 2 10k
R2 vcc out 4.7k TC1=0.001
RLOAD out 0 1Meg
Capacitor
C<name> <node+> <node-> <value> [IC=<val>]
Examples:
C1 in out 100n
C2 vcc 0 10u IC=0
CBYPASS 5 0 1u
Inductor
L<name> <node+> <node-> <value> [IC=<val>]
Examples:
L1 in out 1m
L2 vcc 0 100u IC=0
LCHOKE vcc vdd 10m
Semiconductor Devices #
Diode
D<name> <anode> <cathode> <model> [area=<val>]
Examples:
D1 vin vout DMOD
D2 0 input 1N4148
.MODEL DMOD D (IS=1e-14 N=1.8)
.MODEL 1N4148 D (IS=2.52n RS=.568 N=1.752 CJO=4p VJ=.4 BV=100 IBV=100u)
BJT (Bipolar Junction Transistor)
Q<name> <collector> <base> <emitter> [<substrate>] <model>
Examples:
Q1 col base emit NMOD
Q2 vcc in out 0 2N3904
.MODEL NMOD NPN (BF=100 IS=1e-14 VA=100)
.MODEL 2N3904 NPN (IS=6.734f BF=416.4 VA=74.03 BR=.7371 CJE=4.493p CJC=3.638p)
MOSFET
M<name> <drain> <gate> <source> <bulk> <model> [L=<val>] [W=<val>]
Examples:
M1 drain gate source bulk NMOS
M2 vdd in out 0 2N7000 L=1u W=10u
.MODEL NMOS NMOS (VTO=1 KP=20u LAMBDA=0.01)
.MODEL 2N7000 NMOS (VTO=2.0 KP=0.15 LAMBDA=0.001)
JFET
J<name> <drain> <gate> <source> <model>
Examples:
J1 drain gate source JMOD
.MODEL JMOD NJF (VTO=-2.0 BETA=1e-3)
Sources #
Voltage Source
V<name> <node+> <node-> [DC <val>] [AC <mag> <phase>] [<transient>]
DC Examples:
VCC vcc 0 DC 5
VBIAS base 0 DC 2.5
AC Examples:
VIN in 0 AC 1 0
VSIG in 0 AC 1.414 90
Transient Examples:
VPULSE in 0 PULSE(0 5 0 1n 1n 10u 20u)
VSIN in 0 SIN(0 1 1k 0 0)
VEXP in 0 EXP(0 5 0 1u 1m 0)
Current Source
I<name> <node+> <node-> [DC <val>] [AC <mag> <phase>] [<transient>]
Examples:
IBIAS 0 base DC 10u
IAC in 0 AC 1m
IPULSE 0 out PULSE(0 1m 0 1n 1n 100u 200u)
Subcircuits #
Definition
.SUBCKT <name> <pin1> <pin2> ... <pinN>
* Internal circuit
R1 pin1 internal 1k
C1 internal pin2 100n
.ENDS <name>
Example:
.SUBCKT OPAMP in+ in- out vcc vdd
* Op-amp internal circuit
.ENDS OPAMP
Usage
X<name> <node1> <node2> ... <nodeN> <subcircuit_name>
Example:
XAMP inp inm output vcc 0 OPAMP
Analysis Commands #
DC Operating Point #
.OP
Example circuit:
VCC vcc 0 DC 5
R1 vcc base 10k
R2 base 0 4.7k
.OP
DC Sweep #
.DC <source> <start> <stop> <step> [<source2> <start2> <stop2> <step2>]
Examples:
.DC VIN 0 5 0.1 (Single sweep)
.DC VIN 0 5 0.1 TEMP -25 125 25 (Nested sweep)
.DC VCE 0 10 0.1 IB 0 100u 20u (Family of curves)
Transient Analysis #
.TRAN <tstep> <tstop> [<tstart>] [<tmax>] [UIC]
Examples:
.TRAN 1n 1u (1ns steps, 1μs total)
.TRAN 1u 10m 0 10n (1μs steps, 10ms total, max 10ns internal step)
.TRAN 1n 1u UIC (Use initial conditions)
AC Small-Signal Analysis #
.AC <sweep_type> <points> <fstart> <fstop>
Types: DEC (decade), OCT (octave), LIN (linear)
Examples:
.AC DEC 10 1 100k (10 points per decade, 1Hz to 100kHz)
.AC LIN 1000 1k 10k (1000 linear points, 1kHz to 10kHz)
.AC OCT 8 1 1Meg (8 points per octave)
Temperature Sweep #
.DC TEMP <start> <stop> <step>
Example:
.DC TEMP -40 125 25 (Temperature from -40°C to 125°C in 25° steps)
Monte Carlo Analysis (ngspice) #
.CONTROL
let run = 0
repeat 100
alter R1 = 1k*(1 + gauss(0, 0.05/3, 6))
run
let run = run + 1
end
.ENDC
Example with tolerance:
R1 1 2 {1k*(1+gauss(0,0.05/3,6))} (1kΩ ±5% tolerance)
Model Statements #
.MODEL Syntax #
.MODEL <name> <type> (<parameter>=<value> ...)
Types:
D - Diode
NPN - NPN BJT
PNP - PNP BJT
NMOS - N-channel MOSFET
PMOS - P-channel MOSFET
NJF - N-channel JFET
PJF - P-channel JFET
Common Diode Parameters #
.MODEL <name> D (
+ IS=<saturation current> default: 1e-14
+ N=<emission coefficient> default: 1
+ RS=<series resistance> default: 0
+ CJO=<zero-bias capacitance> default: 0
+ VJ=<junction potential> default: 1
+ M=<grading coefficient> default: 0.5
+ BV=<breakdown voltage> default: inf
+ IBV=<breakdown current> default: 1e-3
)
Common BJT Parameters #
.MODEL <name> NPN (
+ IS=<saturation current> default: 1e-16
+ BF=<forward beta> default: 100
+ BR=<reverse beta> default: 1
+ VA=<Early voltage> default: inf
+ VJE=<B-E junction potential> default: 0.75
+ VJC=<B-C junction potential> default: 0.75
+ CJE=<B-E capacitance> default: 0
+ CJC=<B-C capacitance> default: 0
+ TF=<forward transit time> default: 0
+ TR=<reverse transit time> default: 0
)
Common MOSFET Parameters #
.MODEL <name> NMOS (
+ VTO=<threshold voltage> default: 0
+ KP=<transconductance> default: 2e-5
+ LAMBDA=<channel modulation> default: 0
+ PHI=<surface potential> default: 0.6
+ GAMMA=<body effect> default: 0
+ CBD=<B-D capacitance> default: 0
+ CBS=<B-S capacitance> default: 0
+ CGSO=<G-S overlap cap> default: 0
+ CGDO=<G-D overlap cap> default: 0
)
Output Commands #
.PRINT #
.PRINT <analysis> <output1> <output2> ...
Examples:
.PRINT DC V(out) I(VCC)
.PRINT TRAN V(in) V(out) V(base)
.PRINT AC VM(out) VP(out) VDB(out)
.PLOT #
.PLOT <analysis> <output1> <output2> ...
Example:
.PLOT TRAN V(in) V(out)
.PROBE #
.PROBE [<output1> <output2> ...]
Example:
.PROBE (All voltages/currents)
.PROBE V(out) (Specific outputs)
Control Commands #
.OPTIONS #
.OPTIONS <option1> <option2> ...
Common options:
.OPTIONS ABSTOL=1p (Absolute current tolerance)
.OPTIONS RELTOL=0.001 (Relative tolerance)
.OPTIONS VNTOL=1u (Voltage tolerance)
.OPTIONS ITL1=100 (DC iteration limit)
.OPTIONS ITL4=10 (Transient iteration limit)
.OPTIONS TRTOL=7 (Transient tolerance)
.OPTIONS METHOD=TRAP (Integration: TRAP or GEAR)
.OPTIONS TEMP=27 (Default temperature in °C)
.PARAM (Parameters) #
.PARAM <name>=<value> ...
Examples:
.PARAM VCC=5 IB=10u
.PARAM RC={VCC/10m} (Calculated parameter)
Usage in components:
R1 vcc out {RC}
V1 vcc 0 DC {VCC}
.FUNC (Functions) #
.FUNC <name>(<args>) {<expression>}
Examples:
.FUNC parallel(r1,r2) {r1*r2/(r1+r2)}
.FUNC Q(c,v) {c*v}
Usage:
R1 a b {parallel(1k,2k)}
Advanced Features #
Initial Conditions #
Capacitor IC
C1 in out 100n IC=2.5
Inductor IC
L1 in out 1m IC=10m
Global IC
.IC V(nodeA)=5 V(nodeB)=2.5
UIC (Use Initial Conditions)
.TRAN 1u 10m UIC
Temperature #
Component Temperature Coefficient
R1 1 2 1k TC1=0.001 TC2=1e-6
Simulation Temperature
.TEMP 27 (Set to 27°C)
.TEMP -40 25 125 (Simulate at multiple temperatures)
Expressions #
Arithmetic Operators
+ - * / ^ Addition, subtraction, multiplication, division, power
Functions
abs(x) Absolute value
sqrt(x) Square root
exp(x) Exponential
ln(x), log(x) Natural and base-10 logarithm
sin(x) Sine (radians)
cos(x) Cosine
tan(x) Tangent
Statistical Functions
gauss(nom, rvar, sigma) Gaussian distribution
unif(nom, rvar) Uniform distribution
Waveform Sources #
PULSE #
PULSE(v1 v2 td tr tf pw per)
Parameters:
v1 - Initial value
v2 - Pulsed value
td - Delay time
tr - Rise time
tf - Fall time
pw - Pulse width
per - Period
Example:
VIN in 0 PULSE(0 5 0 1n 1n 10u 20u)
SIN #
SIN(vo va freq td theta)
Parameters:
vo - Offset
va - Amplitude
freq - Frequency
td - Delay
theta - Damping factor
Example:
VIN in 0 SIN(0 1 1k 0 0)
EXP #
EXP(v1 v2 td1 tau1 td2 tau2)
Parameters:
v1 - Initial value
v2 - Final value
td1 - Rise delay
tau1 - Rise time constant
td2 - Fall delay
tau2 - Fall time constant
Example:
VIN in 0 EXP(0 5 0 1u 1m 1u)
PWL (Piecewise Linear) #
PWL(t1 v1 t2 v2 t3 v3 ...)
Example:
VIN in 0 PWL(0 0 1u 0 1.1u 5 10u 5 10.1u 0 20u 0)
Measurement Output #
Voltage Measurements #
V(node) - Voltage at node (relative to ground)
V(node1, node2) - Voltage between nodes (node1 - node2)
VM(node) - Magnitude (AC analysis)
VP(node) - Phase in degrees (AC analysis)
VDB(node) - Magnitude in dB (AC analysis)
VR(node) - Real part (AC analysis)
VI(node) - Imaginary part (AC analysis)
Current Measurements #
I(Vsource) - Current through voltage source
I(element) - Current through element
IM(Vsource) - Magnitude (AC analysis)
IP(Vsource) - Phase (AC analysis)
IDB(Vsource) - Magnitude in dB (AC analysis)
SPICE Shell Commands (ngspice) #
Access via SPICE Shell in Breadpad:
run - Execute the simulation
stop at <time> - Set breakpoint
resume - Continue simulation
print <output> - Display value
plot <output> - Graph output
write <file> - Save results
setplot - Select plot
display - Show available plots
quit - Exit shell
Best Practices #
Netlist Organization #
* Power Supply Design Example
* Author: Your Name
* Date: 2025-01-10
***** Power Sources *****
VIN vin 0 DC 12
VREF ref 0 DC 2.5
***** Input Stage *****
R1 vin div 10k
R2 div 0 10k
C1 div 0 100n
***** Output Stage *****
RLOAD out 0 1k
COUT out 0 10u
***** Analysis *****
.TRAN 1u 10m
.PROBE
.END
Naming Conventions #
- Descriptive names:
RLOADnotR27 - Grouping:
VCC,VDD,VEEfor supplies - Signals:
IN,OUT,SIGNAL_NAME - Nodes:
base,collector,drain
Convergence Aids #
* Add small resistances
RGMIN sensitive_node 0 1G
* Add series resistance to voltage sources
VSRC vsrc 0 DC 5
RSRC vsrc actual_vcc 0.001
* Parallel resistance for inductors
L1 a b 1m
RP1 a b 1G
* Series resistance for capacitors
C1 in mid 100n
RS1 mid out 0.001
Common Units & Prefixes #
| Prefix | Symbol | Value | Example |
|---|---|---|---|
| Tera | T | 10¹² | 1TΩ |
| Giga | G | 10⁹ | 1GHz |
| Mega | M, Meg | 10⁶ | 1MΩ, 1Meg |
| Kilo | k, K | 10³ | 1kΩ |
| Milli | m | 10⁻³ | 1mA |
| Micro | u | 10⁻⁶ | 1uF |
| Nano | n | 10⁻⁹ | 1nF |
| Pico | p | 10⁻¹² | 1pF |
| Femto | f | 10⁻¹⁵ | 1fF |
Note: Use Meg for mega-ohms to avoid confusion with milli (m).
See Also #
- SPICE Shell - Interactive SPICE commands
- Components - Component documentation
- Troubleshooting - Common issues
- Glossary - Term definitions
Reference: This guide is based on ngspice documentation. For complete ngspice reference, visit ngspice.sourceforge.net.