How PLECS Spice Works

Section Physical Model Equations describes how the standard PLECS software simulates physical models using piecewise linear state-space equations. The approach is well-suited for circuits involving mostly linear electrical components, but falls short in the presence of highly nonlinear semiconductor models.

This section briefly describes the inner workings of the transient analysis in SPICE. Using a simple example, it introduces the concept of modified nodal analysis (MNA), shows how MNA is used to derive the differential algebraic equations (DAE), and explains how netlists are used to describe electric circuits.

Modified Nodal Analysis

Example RC Circuit

../../_images/example-rc-circuit.svg

The connections between the components of a circuit are called nodes. In the above example, the nodes are labeled N1, N2 and 0. The node labeled 0 is connected to ground. The nodal voltage of a node connected to ground is defined as zero (reference node). The nodal voltage of any other node is defined as the potential difference (voltage) between that node and the ground. The algebraic relationship between the current and voltage of a component is called branch equation.

In a state-of-the-art implementation of SPICE such as PLECS Spice, a sophisticated algorithm is used to build the MNA equations efficiently. Nevertheless, the MNA recipe described below conveys sufficiently well what it’s algorithm achieves:

  1. At every node, write the equation provided by Kirchhoff’s current law (KCL).

  2. Substitute currents (except for capacitors, inductors and sources) using branch equations.

  3. Write the branch equations in terms of nodal voltages using Kirchhoff’s voltage law (KVL).

  4. Add the identities provided by the sources.

  5. Add the capacitor and inductor equations.

In the resulting set of equations, the unknown variables are

  • Nodal voltages (excluding the ground)

  • Currents in voltage sources

  • Currents in capacitors

  • Currents in inductors

Note

In PLECS Spice, a connected SPICE electrical circuit must have an Electrical Ground, because it is used as reference node for the nodal voltages. To specify a ground, simply connect the ground component to a node.

Let’s apply the MNA recipe to the example RC circuit.

Step 1 Apply KCL at the nodes N1 and N2

\[\begin{split}\begin{aligned} i_V - i_R &= 0\\ i_R - i_C &= 0 \end{aligned}\end{split}\]

Step 2 Substitute the resistor branch equation \(i_R = v_R/R\)

\[\begin{split}\begin{aligned} i_V - \frac{1}{R}v_R &= 0 \\ \frac{1}{R}v_R - i_C &= 0 \end{aligned}\end{split}\]

Step 3 By KVL, the voltage across the resistor satisfies \(v_R = v_{\text{N1}} - v_{\text{N2}}\)

\[\begin{split}\begin{aligned} i_V - \frac{1}{R}(v_{\text{N1}} - v_{\text{N2}}) &= 0 \\ \frac{1}{R}(v_{\text{N1}} - v_{\text{N2}}) - i_C &= 0 \end{aligned}\end{split}\]

Step 4 Append the source equation \(v_1 = V\)

\[\begin{split}\begin{aligned} i_V - \frac{1}{R}(v_{\text{N1}} - v_{\text{N2}}) &= 0 \\ \frac{1}{R}(v_{\text{N1}} - v_{\text{N2}}) - i_C &= 0 \\ v_{\text{N1}} &= V \\ \end{aligned}\end{split}\]

Step 5 Append the capacitor equation \(C\dot{v}_C = i_C\)

\[\begin{split}\begin{aligned} i_V - \frac{1}{R}(v_{\text{N1}} - v_{\text{N2}}) &= 0 \\ \frac{1}{R}(v_{\text{N1}} - v_{\text{N2}}) - i_C &= 0 \\ v_{\text{N1}} &= V \\ \frac{d}{dt}Cv_{\text{N2}} &= i_C \\ \end{aligned}\end{split}\]

General Form

By grouping all the unknowns into a single vector \(\mathbf{x}\), the MNA equations can be written as the differential algebraic equation system (DAE)

\[\begin{split}\begin{aligned} \frac{d}{dt}\mathbf{q}(\mathbf{x}) &= \mathbf{f}(\mathbf{x}) \\ \mathbf{0} &= \mathbf{g}(\mathbf{x}, t) \end{aligned}\end{split}\]

where

\[\begin{split}\begin{aligned} \mathbf{q}(\mathbf{x}) &\equiv \text{electric charges and magnetic fluxes} \\ \mathbf{f}(\mathbf{x}) &\equiv \text{capacitor currents and inductor voltages}\\ \mathbf{g}(\mathbf{x}, t) &\equiv \text{KCL equations at every node} \end{aligned}\end{split}\]

Operating Point

The above DAE system of equations is solved by PLECS Spice during a transient analysis. Unlike for state-space systems, initial conditions \(\mathbf{x}_0\) must satisfy the algebraic constraint (KCL)

\[\mathbf{0} = \mathbf{g}(\mathbf{x}_0, t_0).\]

The process of finding valid initial conditions is called operating point analysis. The resulting vector is called operating point. Unless initial conditions are provided, a SPICE operating point typically represents the DC steady-state of the circuit at \(t_0\), where capacitor currents and inductor voltages are zero (all time-derivatives are zero).

By default, a transient analysis always starts with an operating point analysis. SPICE Simulation Parameters provide the option to configure or even skip the operating point analysis completely, but it is generally not recommended to do so. Simulating a physical system with inconsistent initial conditions can lead to unphysical solutions.

Benefits

The state-space approach adopted by PLECS is computationally very efficient for piecewise linear physical systems. By comparison with our earlier example, the ordinary differential equation (ODE) for the RC circuit is the single equation

\[\frac{d}{dt} v_C = \frac{1}{RC} V - \frac{1}{RC} v_C.\]

However, for circuits with algebraic dependencies, this ODE approach relies on an indirect method to resolve Algebraic loops that often fails to converge in the presence of strong nonlinearities. The DAE formulation in PLECS Spice solves algebraic constraints of physical models directly as part of an implicit numerical method. This direct approach is significantly more robust and is essential for handling typical SPICE semiconductor models.

Differential Algebraic Equation Solver

SDIRK and ESDIRK Methods

In PLECS Spice, we provide two 3rd-order accurate implicit Runge-Kutta methods to solve the DAE system of equations obtained from MNA. The numerical methods are augmented with dedicated circuit-tailored convergence helpers that make them perfectly suited for the simulation of SPICE models.

(E)SDIRK numerical methods solve each time step using multiple stages. At each stage the information from previous stages is combined with that of the current stage to increase the quality and accuracy of the approximation. The data from these stages is also used to evaluate a polynomial interpolant for refinement and an error estimate for stepsize control.

Because no information from previous time steps is necessary during this process, Runge-Kutta methods are called one-step methods. The key benefit of a one-step method is that it is inherently self-starting. This property is crucial for integrating hybrid schematics containing both standard PLECS and SPICE models.

Standard PLECS components may introduce physical and signal discontinuities that must be precisely located during zero-crossing detection using polynomial interpolation. After such an event, the algorithm cannot rely on memory from a different system topology. To remain performant in the presence of frequent ideal switching, the solver must be able to compute the next time step using only information from the current state, a task for which one-step methods are perfectly suited.

SDIRK (Singly Diagonally Implicit Runge-Kutta)

This method was specifically designed for DAEs of index higher than 1. It provides excellent stability and should be used when ESDIRK shows signs of instability.

ESDIRK (Explicit first stage SDIRK)

This is the default method chosen by PLECS Spice when the solver parameter is set to auto in the presence of a SPICE model. It is faster than SDIRK for most well-behaved systems.

Both methods are L-stable with L-stable embedded error estimators, ensuring robust behavior when solving stiff equations.

Mixed-Signal Hybrid Simulation

The DAE solvers can simulate complex mixed-signal hybrid systems that combine standard PLECS and SPICE models in a single schematic. The only restriction is that SPICE and standard PLECS physical models must be connected through sources and meters, or in other words through the control domain.

This feature enables a powerful top-down modeling workflow. A system initially designed and simulated entirely with fast ideal PLECS models can be refined by converting ideal switches to device-specific SPICE netlists. The controls can remain in standard PLECS.

Note

A connected electrical circuit is a SPICE physical model if it contains a Netlist or Netlist File Reference component. All the standard PLECS components of a SPICE physical model must be compatible with SPICE.

Warning

Electrical grounds in PLECS electrical circuits are not connected to electrical grounds in SPICE electrical circuits.

Netlists

Format

A SPICE netlist is a text-based description of an electric circuit. The format is widely adopted by manufacturers to provide device-level models of specific semiconductor devices. While there are slight differences between the dialects of popular SPICE solvers, they all rely on comparable syntaxes. This allows importing netlists from varied sources into the PLECS Spice Netlist component.

The syntax supported by PLECS Spice is summarized in Netlist Cheat Sheets and covered in detail in Netlist Syntax Reference.

Example Netlist

The netlist description of the above Example RC Circuit is simple.

.SUBCKT RC_Circuit N2

R N1 N2 1
V N1 0 1
C N2 0 1e-4
.IC V(N2)=0

.ENDS

It defines

  • a \(1\Omega\) resistor identified as R connected to nodes N1 and N2

  • a \(1V\) voltage source identified as V connected to the node N1 and ground

  • a \(100 \mu F\) capacitor identified as C connected to node N2 and ground

  • an initial nodal voltage of zero at node N2

Note

When a node in a netlist is named 0, it always refers to ground.

Remark. By setting the initial nodal voltage at N2 to zero with .IC V(N2)=0, we match the standard PLECS state-space formulation behavior that sets the initial voltage across the capacitor to zero. The nodal voltage at N2 would otherwise be set to one by the operating point analysis, because the capacitor current is initialized to zero in the operating point (its DC steady-state). Accordingly, constant nodal voltages would be observed during transient simulation.

The circuit description starts with .SUBCKT RC_Circuit N2 and is completed by .ENDS. These instructions specify that the subcircuit is named RC_Circuit and that N2 is an exposed node. Both the name and the exposed node are visually reflected in the Netlist component of the schematic:

../../_images/example-rc-netlist.svg

N2 can be electrically connected to other components of the schematic. For example, connecting a voltmeter to N2 and an Electrical Ground measures the nodal voltage at N2.

Note

More than one node can be exposed. For example, .SUBCKT RC_Circuit N1 N2 creates two terminals labeled N1 and N2 for the Netlist component on the PLECS schematic. These terminals correspond to the exposed nodes N1 and N2. Their labels can be changed independently of the netlist via the Terminals Tab.

Compact Models

In addition to sources and passive elements, SPICE solvers provide a set of MNA compatible models for standard semiconductor elements such as mosfets, diodes and bipolar junction transistors. These models, also referred to as compact models, are designed to capture the fundamental electrical behavior of nonlinear devices while also retaining reasonably low complexity. They are made out of a mixture of physics-based modeling and empirical corrections.

To achieve optimal simulation performance, compact models are tightly integrated in the implementation of the solver. Customization of the model equations by the user is not possible, but every compact model defines a set of parameters that can be tuned to match the electrical response of the model to the response of the physical device. This restriction permits tailored optimization and the use of convergence helpers to increase robustness of the simulation. In PLECS Spice, classical compact models were improved to guarantee continuity of key physical quantities.

M drain gate source source mosfetModel
.MODEL mosfetModel NMOS VTO=3.5 KP=100 ; more parameters can be specified here