Sources & Waveforms

Every circuit needs something to push it out of equilibrium. A battery, a signal generator, a sensor producing a time-varying voltage -- without a source, all node voltages are zero and nothing happens. In SPICE, sources are the elements that inject energy into the circuit.

Sources come in two fundamental varieties, and understanding the distinction is essential to reading any netlist.

Independent sources (V and I elements) produce a voltage or current that depends only on time. A 5V battery, a 1 kHz sine wave, a pulsed clock -- these are all independent sources. They are the external stimuli that drive the circuit. During DC analysis, they supply a constant value. During transient analysis, they produce a waveform -- a function of time that can be a pulse, a sinusoid, a piecewise-linear signal, or several other shapes. The waveform is evaluated at every timestep to determine the source's current value.

Dependent sources (E, G, F, H elements) produce a voltage or current that depends on some other voltage or current in the same circuit. An operational amplifier's output voltage depends on the voltage difference at its inputs. A MOSFET's drain current depends on its gate voltage. Dependent sources model these kinds of controlled relationships. They are linear -- the output is always a constant gain times the controlling variable -- which makes them straightforward to stamp into the MNA matrix.


Independent Sources

An independent source produces a voltage or current that is entirely determined by its own parameters -- it doesn't depend on anything else in the circuit. In a netlist, voltage sources start with V and current sources start with I:

V1 in  0  DC 5             * 5V battery
I1 vcc 0  DC 1m            * 1 mA current source
V2 clk 0  PULSE(0 3.3 0 1n 1n 5n 10n)  * 3.3V clock

Independent sources serve three distinct roles depending on the analysis type:

A single source element can have all three specifications simultaneously. The DC value sets the operating point, the AC specification is used during .AC analysis, and the transient waveform drives .TRAN simulation.


DC sources

The simplest case. A DC source supplies a constant value throughout the simulation:

V1 vdd 0  DC 3.3
I1 bias 0 DC 100u

During DC operating point analysis, this is the only value that matters -- transient waveforms are ignored and the circuit is solved for the steady-state condition where all capacitors are open circuits and all inductors are short circuits.

In spice-rs, a DC-only source is represented by the Waveform::Dc(value) variant. Its eval() method returns the same value regardless of time.


AC sources

An AC source specifies the amplitude and phase of a small-signal excitation for frequency-domain analysis:

V1 in 0  AC 1 0          * 1V amplitude, 0 phase
V2 in 0  AC 0.5 90       * 0.5V amplitude, 90 phase

AC sources do not produce a time-domain signal. They define a complex phasor that is applied at each frequency point during .AC analysis. The amplitude is in the same units as the source (volts or amps), and the phase is in degrees.

Typically one source in the circuit has AC 1 0 (unit amplitude, zero phase), and all other voltages and currents are measured relative to it. The ratio of output to input phasor gives the transfer function at each frequency.


Transient waveforms

During .TRAN analysis, independent sources produce time-varying signals. SPICE supports several standard waveform types, each designed for a common use case.

PULSE -- periodic pulse

PULSE(V1 V2 TD TR TF PW PER)

The workhorse waveform for digital circuits. Produces a periodic trapezoidal pulse:

Parameter Meaning Default
V1 Initial value (low level) --
V2 Pulsed value (high level) --
TD Delay before first pulse 0
TR Rise time TSTEP
TF Fall time TSTEP
PW Pulse width (at V2) TSTOP
PER Period TSTOP

During the delay period (), the source outputs V1. It then ramps linearly to V2 over TR seconds, holds at V2 for PW seconds, ramps back to V1 over TF seconds, and stays at V1 until the next period begins. The entire pattern repeats with period PER.

The rise and fall times are important for transient accuracy. Setting TR and TF to zero would create an ideal step -- but that's numerically problematic because voltages would need to change infinitely fast. SPICE defaults to TSTEP (the requested print interval) when TR or TF are zero, ensuring a finite slope.

The pulse waveform also generates breakpoints -- it tells the transient engine to land exactly on the start and end of each edge. Without breakpoints, the adaptive timestep controller might step right over a fast transition and miss it entirely.

SIN -- damped sinusoid

SIN(VO VA FREQ TD THETA PHASE)

Produces a sinusoidal waveform, optionally damped by an exponential envelope:

Parameter Meaning Default
VO DC offset --
VA Amplitude --
FREQ Frequency (Hz) 1/TSTOP
TD Delay before oscillation starts 0
THETA Damping factor (1/s) 0
PHASE Phase offset (degrees) 0

The time-domain expression is:

for , and for .

When THETA is zero, the sinusoid oscillates forever at constant amplitude. When THETA is positive, the envelope decays exponentially -- the oscillation rings down. This is useful for modeling switched sinusoidal excitation or natural decay.

Note that the SIN waveform does not generate breakpoints. Unlike PULSE and PWL, a sinusoid has no sharp edges, so the adaptive timestep controller handles it naturally. However, the timestep must be small enough to resolve the waveform -- typically at least 10-20 points per period.

PWL -- piecewise linear

PWL(T1 V1 T2 V2 T3 V3 ...)

The most flexible waveform. Defines an arbitrary signal as a sequence of time-value pairs, with linear interpolation between them:

Parameter Meaning
T1, V1 First time-value pair
T2, V2 Second time-value pair
... Additional pairs

Between any two adjacent time points, the voltage changes linearly. Before the first time point, the source holds at V1. After the last time point, it holds at the final value. This means PWL can represent any waveform you can describe with straight line segments -- step functions (with very short ramps), triangular waves, arbitrary test patterns, or digitized real-world signals.

Each corner point in the PWL sequence generates a breakpoint, ensuring the transient engine lands on the exact times where the slope changes.

EXP -- exponential

EXP(V1 V2 TD1 TAU1 TD2 TAU2)

Produces a waveform with exponential rise and decay -- useful for modeling RC charging/discharging behavior or step responses of first-order systems:

Parameter Meaning Default
V1 Initial value --
V2 Target value --
TD1 Rise delay 0
TAU1 Rise time constant TSTEP
TD2 Fall delay TD1 + TSTEP
TAU2 Fall time constant TSTEP

The waveform has two phases:

Rise phase ():

Decay phase ():


How waveforms enter the matrix

Independent sources interact with the MNA matrix in specific ways depending on whether they are voltage or current sources.

A voltage source adds a branch equation to the MNA system (as described in Chapter 2). During each Newton-Raphson iteration, its waveform is evaluated at the current time to determine the voltage value stamped into the RHS:

A current source stamps directly into the RHS at its terminal nodes -- no branch equation needed:

In both cases, the waveform evaluation is the same -- only the stamping mechanism differs. In spice-rs, the Waveform::eval(t, step, final_time) method is called from the voltage source and current source load() functions at every iteration of every timestep.


Dependent Sources

A dependent source produces a voltage or current that is controlled by some other voltage or current in the circuit. Where independent sources model external stimuli (batteries, signal generators), dependent sources model internal relationships -- an amplifier's gain, a transistor's transconductance, or any linear coupling between two parts of a circuit.

SPICE has four types of dependent sources, covering every combination of voltage and current for both input and output:

Element Name Relationship Controlling variable Output
E VCVS Voltage-controlled voltage source Voltage Voltage
G VCCS Voltage-controlled current source Voltage Current
H CCVS Current-controlled voltage source Current Voltage
F CCCS Current-controlled current source Current Current

Each has a single parameter: the gain (dimensionless for E and F, transconductance in siemens for G, transresistance in ohms for H). The output is always the gain times the controlling variable. These are linear elements -- no matter how large the controlling signal, the relationship is a straight line through the origin. This makes them easy to stamp into the MNA matrix and means they don't require Newton-Raphson iteration.

Dependent sources are fundamental building blocks for modeling active devices. The small-signal model of a MOSFET, for instance, includes a VCCS () as its core gain element. Op-amp macromodels use VCVS elements with gains of or more. Feedback networks, current mirrors, and gyrators all use dependent sources.


VCVS -- Voltage-Controlled Voltage Source (E element)

E1 out 0 in+ in- 10

The output voltage equals the gain times the controlling voltage difference:

where is the voltage gain (dimensionless).

Because the output is a voltage, the VCVS needs a branch equation -- just like an independent voltage source. The branch current flows through the source, and the MNA system enforces the voltage constraint. The stamps are:

         pos  neg  ctrl+  ctrl-  branch
pos   [                            +1  ]
neg   [                            -1  ]
branch[ +1   -1    -mu     +mu        ]

VCCS -- Voltage-Controlled Current Source (G element)

G1 out+ out- ctrl+ ctrl- 0.01

The output current equals the transconductance times the controlling voltage difference:

where has units of siemens (A/V).

Because the output is a current, no branch equation is needed. The VCCS stamps directly into the conductance matrix:

         ctrl+  ctrl-
out+  [  +gm    -gm  ]
out-  [  -gm    +gm  ]

The VCCS is the most physically intuitive dependent source -- it's exactly how a transconductance amplifier works. The small-signal model of a MOSFET's drain current is , which is a VCCS.


CCVS -- Current-Controlled Voltage Source (H element)

H1 out+ out- Vsense 1000

The output voltage equals the transresistance times the controlling current:

where has units of ohms (V/A).

There's a subtlety with current-controlled sources: SPICE cannot directly observe current through an arbitrary branch. It can only access the branch current of a voltage source. So the controlling current must be the current through a named voltage source -- often a zero-volt "sense" source inserted just for this purpose.


CCCS -- Current-Controlled Current Source (F element)

F1 out+ out- Vsense 5

The output current equals the gain times the controlling current:

where is the current gain (dimensionless).


The pattern

Looking across all four dependent sources, a clear structure emerges:

Voltage output (needs branch eq) Current output (no branch eq)
Voltage controlled VCVS (E): 6 stamps VCCS (G): 4 stamps
Current controlled CCVS (H): 5 stamps CCCS (F): 2 stamps

Voltage outputs always require a branch equation because the MNA framework enforces voltage constraints through auxiliary equations. Current outputs stamp directly into the conductance matrix at the output node rows. Voltage-controlled sources reference the controlling nodes directly. Current-controlled sources reference the branch equation of a sensing voltage source.

The VCCS (G element) is the most commonly used dependent source in practice, because transconductance is the natural gain mechanism of field-effect transistors.


Transmission Lines

When a signal travels along a wire, cable, or PCB trace, it doesn't arrive instantaneously. At high frequencies -- or over long distances -- the propagation delay becomes significant, and the wire can no longer be modeled as a simple node connecting two points. It becomes a transmission line: a distributed element with its own impedance and a finite speed of signal propagation.

The lossless transmission line is defined by just two parameters:

-- characteristic impedance. The ratio of voltage to current for a wave propagating along the line. A 50-ohm coaxial cable, a 100-ohm differential PCB pair, a 75-ohm television cable -- is the intrinsic property that determines how the line interacts with whatever is connected at its ends.

-- propagation delay. The time it takes a signal to travel from one end of the line to the other.

T1 port1+ port1- port2+ port2- Z0=50 TD=1n

The physics

A transmission line is a distributed LC network. Every infinitesimal segment has inductance per unit length () and capacitance per unit length ():

where is the physical length.


How SPICE models it

SPICE doesn't discretize the line into hundreds of LC segments. Instead, it uses the exact analytical solution for the lossless case. The model works by maintaining a delay table -- a history of past excitation values at each port. At each timestep, the simulator looks back in time by seconds, interpolates the stored values, and uses them as sources driving the current timestep.

Each equivalent current source is computed from the voltage and current at the opposite port, delayed by :


AC behavior

For AC analysis, the delay translates into a phase shift that depends on frequency:

At low frequencies (), the phase shift is negligible and the line looks like a short wire. At , the line introduces a half-wavelength delay -- a 180-degree phase shift.


When to use transmission lines

Transmission lines matter when the propagation delay is comparable to the signal's rise time. A common rule of thumb:

where is the signal's 10-90% rise time. For a 1 ns rise time, this means any trace longer than about 2.5 cm on a typical PCB.