Sub topic 19
Describing Sources in SPICE Netlists
This chapter assumes you can read a circuit diagram with independent and dependent sources. It also assumes you can write a nodal equation and have run a simple SPICE simulation. Here you will turn each source type into a netlist line. You will also learn which sign conventions SPICE uses and how to check a simulation against a hand calculation.
One letter per source type
A SPICE netlist describes a circuit as a list of elements. The first letter of an element name sets its type, and the node names that follow set its connections. Node 0 is always ground.
| Element | Letter | Type | Line format |
|---|---|---|---|
| Independent voltage source | V | independent | `Vname n+ n- DC value` |
| Independent current source | I | independent | `Iname n+ n- DC value` |
| VCVS | E | dependent | `Ename n+ n- nc+ nc- gain` |
| VCCS | G | dependent | `Gname n+ n- nc+ nc- transconductance` |
| CCVS | H | dependent | `Hname n+ n- Vsense transresistance` |
| CCCS | F | dependent | `Fname n+ n- Vsense gain` |
The first two nodes are where the source connects. For E and G, the next two nodes (nc+, nc-) are where the controlling voltage is measured. For H and F, the controlling quantity is a current. SPICE cannot read a current from a bare wire, so it reads the current through a named voltage source, Vsense.
Independent sources and the sign of a current
A voltage source line names the positive terminal first. V1 in 0 DC 10 makes node in 10 V above ground.
* Independent voltage source driving a resistor divider
V1 in 0 DC 10
R1 in out 1k
R2 out 0 1k
.op
.endBy hand, v(out) = 10 V × 1k/(1k+1k) = 5 V. The simulation reports v(out) = 5. It also reports the source current i(v1) = -5 mA. The negative sign is a convention, not an error. SPICE defines a voltage source's current as flowing into the + terminal and through the source to the − terminal. A source that delivers power sends current out of its + terminal, so SPICE reports that current as negative. Your power-sign rules from earlier chapters give the same result. The source delivers 10 V × 5 mA = 50 mW.
A current source line gives a direction instead of a polarity. I1 a b 1m means 1 mA flows from a, through the source, to b. The source therefore pulls current out of node a and pushes it into node b.
* 1 mA pushed into node out, returning through R1 to ground
I1 0 out DC 1m
R1 out 0 1k
.op
.endCurrent flows from node 0 through the source into out, then through R1 to ground. The hand calculation is v(out) = 1 mA × 1k = 1 V.
Dependent sources with a controlling voltage
The E element is the VCVS. The output voltage is the gain times the voltage across the controlling node pair.
* Voltage-controlled voltage source (VCVS) with gain 5
V1 in 0 DC 1
R1 in 0 1k
E1 out 0 in 0 5
RL out 0 1k
.op
.endE1 out 0 in 0 5 reads as follows. The output is between out (+) and 0 (−). The controlling voltage is v(in) − v(0). The gain is 5. With V1 = 1 V, v(out) = 5 V.
The G element is the VCCS. Its gain has units of siemens, and its output is a current. Direction follows the I element: current flows from n+ through the source to n-.
* Voltage-controlled current source (VCCS), 2 mS
V1 in 0 DC 1
R1 in 0 1k
G1 0 out in 0 2m
RL out 0 1k
.op
.endThe controlling voltage is 1 V, so the source drives 2 mS × 1 V = 2 mA. Because G1 0 out sends current from node 0 into out, that current flows through RL. The result is v(out) = 2 mA × 1k = 2 V.
Dependent sources with a controlling current
SPICE needs a branch it can measure. You insert a 0 V source in series with the controlling branch. It has no effect on the circuit, like an ideal ammeter. Its current follows the same convention as before: positive current flows from its + node to its − node. Orient it so the current you care about enters the + terminal.
* Current-controlled current source (CCCS) with gain 3
V1 in 0 DC 1
Vsense in n1 DC 0
R1 n1 0 1k
F1 0 out Vsense 3
RL out 0 1k
.op
.endCurrent from V1 flows in → Vsense → n1 → R1 → ground, so i(Vsense) = 1 V/1k = 1 mA. F1 0 out sends 3 × 1 mA = 3 mA into out, and v(out) = 3 mA × 1k = 3 V.
The H element is the CCVS, and its gain is in ohms. Reusing the same sense branch:
* Current-controlled voltage source (CCVS), 2 kilohm transresistance
V1 in 0 DC 1
Vsense in n1 DC 0
R1 n1 0 1k
H1 out 0 Vsense 2k
RL out 0 1k
.op
.endThe output is v(out) = 2k × 1 mA = 2 V.
Checking a simulation against your hand work
A reliable routine has four steps:
- Solve the circuit by hand, including the sign of every source current.
- Write the netlist and read each source line aloud as "from n+ to n-".
- Run
.opand compare node voltages first, then source currents. - If they disagree, check the three usual causes below.
The usual causes of a mismatch are:
- Swapped nodes. Reversing
n+andn-on an I, G or F element reverses the current. - Wrong sense orientation. A reversed
Vsenseflips the sign of i(Vsense), and so flips the output of every H or F element that uses it. - Floating nodes. A node with no DC path to ground makes the matrix singular. Add a resistor to ground or restructure the circuit.
Exercise
A netlist has V1 in 0 DC 2, Vsense in n1 DC 0, R1 n1 0 500, and F1 0 out Vsense 4. A 250 ohm resistor RL connects out to ground. What is v(out), and what current does SPICE report for Vsense?
Show answer
Current through R1 and Vsense is 2 V / 500 ohm = 4 mA. SPICE reports i(Vsense) = +4 mA, because the current flows from its + node in to its − node n1. F1 sends 4 × 4 mA = 16 mA into out, so v(out) = 16 mA × 250 ohm = 4 V.
Exercise
Write the netlist line for a VCCS that drives 5 mA into node x when the voltage from node a to ground is 1 V, with 0 as the other source terminal.
Show answer
G1 0 x a 0 5m. Current flows from node 0 through the source into x, and the 5 mS gain times 1 V gives 5 mA.