Transient Analysis
Transient analysis answers the most direct question you can ask a circuit simulator: given these input signals, what are the voltages and currents as a function of time?
Apply a step to an RC circuit and watch the exponential charge. Toggle a clock signal into a logic gate and see the propagation delay. Feed a pulse into a transmission line and watch it ring. Transient analysis simulates all of this by solving the circuit equations at every timestep from
Unlike DC analysis (one solve) or AC analysis (linearized, one solve per frequency), transient analysis is the full nonlinear problem at every single timestep. Every Newton-Raphson iteration from Chapter 3 runs at every time point. This makes transient analysis by far the most computationally expensive analysis in SPICE.
Numerical Integration
At the heart of transient analysis is a problem: capacitors and inductors are described by differential equations, but SPICE's matrix solver only handles algebraic equations. Numerical integration bridges this gap.
The differential equation
A capacitor's current:
Companion models
The key insight is that a numerical integration formula converts a capacitor's differential equation into an algebraic relationship: a conductance in parallel with a current source. This "companion model" changes at every timestep but is always a simple linear element that stamps directly into the MNA matrix.
This is the same trick that Newton-Raphson uses for nonlinear devices: convert something hard (a differential equation) into something the MNA matrix can handle (a linear conductance plus a current source).
Charge as the fundamental quantity
SPICE integrates charge (or flux), not voltage (or current) directly. Why? Because charge is conserved. Numerical errors in tracking charge lead to small voltage errors, but conservation of charge is maintained. Integrating voltage directly could create or destroy charge, causing instability.
The Trapezoidal Rule
The trapezoidal rule is the default integration method in SPICE. It approximates the integral by averaging the function's value at the beginning and end of each interval.
The formula
Since
The companion model for a capacitor
Applying the trapezoidal rule to
The equivalent conductance
Advantages
Second-order accuracy. The local truncation error is proportional to
A-stability. The method is stable for all timestep sizes -- it will never diverge.
Time-reversibility. A lossless LC circuit will oscillate forever at constant amplitude, which is the physically correct behavior.
The disadvantage: numerical ringing
The same time-reversibility that preserves oscillations can create spurious oscillations in stiff circuits. This is trapezoidal ringing -- the trapezoidal rule, having no numerical damping, can produce decaying oscillations around the true solution.
Gear (BDF) Methods
The Gear methods (Backward Differentiation Formulas) are the standard alternative to the trapezoidal rule. They trade some accuracy for guaranteed damping of spurious oscillations.
The idea
BDF methods approximate the derivative directly using a backward difference formula. Gear-1 (backward Euler):
Gear-2 uses two past points:
Why BDF methods damp ringing
BDF methods weight the new value more heavily than the old, introducing numerical damping that suppresses the high-frequency oscillations that plague the trapezoidal rule on stiff circuits.
Variable-order strategy
spice-rs uses a variable-order strategy:
- Start at order 1 (backward Euler) at the beginning and at breakpoints, where the solution may have discontinuities.
- Promote to order 2 (trapezoidal) when the solution is smooth and the higher order allows a significantly larger timestep.
- Drop back to order 1 at breakpoints to handle potential discontinuities.
Timestep Control
A fixed timestep is either too small (wasting computation) or too large (missing transitions). SPICE uses adaptive timestep control -- the simulator dynamically adjusts
The accept/reject loop
At every timestep:
- Choose timestep
, advance time, compute integration coefficients, run Newton-Raphson. - NR convergence check: If NR fails to converge, reject the step, divide
by 8, retry. - LTE check: If the local truncation error is too large, reject, compute a smaller
, retry. - If both checks pass, accept the step and record the solution.
Local Truncation Error (LTE)
The LTE measures how much error the integration method introduces at a single step. For the trapezoidal rule:
SPICE estimates the LTE using the predictor-corrector difference and adjusts the timestep accordingly.
The timestep floor
There is a hard lower bound:
The acceptance threshold: 0.9
The LTE check requires
The doubling cap
After a successful step, the timestep never more than doubles:
Breakpoints
Adaptive timestep control works when the waveform is smooth. But what about abrupt transitions? A PULSE source with a 1 ns rise time could be stepped right over if the simulator is cruising with a 10
Breakpoints are a list of future times where something interesting will happen. The transient engine ensures a timestep lands exactly on each breakpoint.
Three cases
At a breakpoint: Drop integration order to 1 (backward Euler). Restrict timestep aggressively. Take many small steps through the transition.
About to overshoot: Clip the timestep to land exactly on the breakpoint.
Far from a breakpoint: Normal adaptive operation.
Source registration
Breakpoints are registered dynamically. At each accepted step, each PULSE and PWL source reports its next transition time. Breakpoints that are too close together (within
Transient Circuits
RC Step Response
The simplest transient circuit: a resistor, a capacitor, and a voltage step.
The output voltage follows the classic first-order exponential:
where
The dashed line marks 63.2% of the final value, reached at
Formula vs SPICE
Now let's run the actual SPICE simulator on the same circuit and see what it does internally:
The top plot is the voltage waveform from spice-rs — it matches the analytical formula exactly. The bottom plot reveals something the formula can't: the timestep sizes the simulator chose. Small steps cluster near
What the simulator does
At
The companion model in action
At each timestep, the capacitor's companion model creates a conductance
A single equation, solved in one NR step -- trivial for the computer, but conceptually the same process that runs on a 10,000-node circuit.
RC step response circuit
MOSFET Switching
A more realistic transient scenario: a MOSFET driven by a pulse, switching a resistive load. This exercises every part of the transient engine -- nonlinear devices, Newton-Raphson iteration, breakpoints, and adaptive timestep control.
Turn-on (
Steady state (MOSFET on): The MOSFET is in the linear region, acting as a small resistance. The LTE mechanism ramps the timestep up to the maximum.
Turn-off (
What the simulator sees
For a turn-on edge, the timestep varies by four orders of magnitude within a single switching event -- picoseconds during the transition, microseconds during settling. The NR iteration count peaks during region transitions. The integration order drops to 1 at breakpoints and promotes back to 2 once the waveform is smooth.
From these examples to real circuits
The RC circuit and MOSFET switch are building blocks. A real digital circuit might have thousands of MOSFETs, each with its own gate capacitance, Miller effect, and switching trajectory. The transient engine handles all of these with the same machinery: companion models for energy storage, Newton-Raphson for nonlinearity, LTE for timestep control, and breakpoints for synchronization with the stimulus.