“Garbage in, garbage out.” —AnonymousSPICE is a very reliable piece of software, but it does have its little quirks that take some getting used to. By “quirk” I mean a demand placed upon the user to write the source file in a particular way in order for it to work without giving error messages. I do not mean any kind of fault with SPICE which would produce erroneous or misleading results: that would be more properly referred to as a “bug.” Speaking of bugs, SPICE has a few of them as well. Some (or all) of these quirks may be unique to SPICE version 2g6, which is the only version I’ve used extensively. They may have been fixed in later versions.
node voltage node voltage ( 1) 15.0000 ( 2) 0.6522In this analysis, there is a DC voltage of 15 volts between node 1 and ground (node 0), and a DC voltage of 0.6522 volts between node 2 and ground (node 0). In both these cases, the voltage polarity is negative at node 0 with reference to the other node (in other words, both nodes 1 and 2 are positive with respect to node 0).
netlist l1 2 4 10m l2 2 4 50m l3 2 4 25m
netlist v1 1 0 dc 12 l1 1 0 150m
netlist c1 5 6 33u c2 6 7 47uThe reason SPICE can’t handle these conditions stems from the way it performs DC analysis: by treating all inductors as shorts and all capacitors as opens. Since short-circuits (0 Ω) and open circuits (infinite resistance) either contain or generate mathematical infinitudes, a computer simply cannot deal with them, and so SPICE will discontinue analysis if any of these conditions occur. In order to make these component configurations acceptable to SPICE, you must insert resistors of appropriate values into the appropriate places, eliminating the respective short-circuits and open-circuits. If a series resistor is required, choose a very low resistance value. Conversely, if a parallel resistor is required, choose a very high resistance value. For example: To fix the parallel inductor problem, insert a very low-value resistor in series with each offending inductor.
original netlist l1 2 4 10m l2 2 4 50m l3 2 4 25m
fixed netlist rbogus1 2 3 1e-12 rbogus2 2 5 1e-12 l1 3 4 10m l2 2 4 50m l3 5 4 25mThe extremely low-resistance resistors R_{bogus1} and R_{bogus2} (each one with a mere 1 pico-ohm of resistance) “break up” the direct parallel connections that existed between L_{1}, L_{2}, and L_{3}. It is important to choose very low resistances here so that circuit operation is not substantially impacted by the “fix.” To fix the voltage source / inductor loop, insert a very low-value resistor in series with the two components.
original netlist v1 1 0 dc 12 l1 1 0 150m
fixed netlist v1 1 0 dc 12 l1 2 0 150m rbogus 1 2 1e-12As in the previous example with parallel inductors, it is important to make the correction resistor (R_{bogus}) very low in resistance, so as to not substantially impact circuit operation. To fix the series capacitor circuit, one of the capacitors must have a resistor shunting across it. SPICE requires a DC current path to each capacitor for analysis.
original netlist c1 5 6 33u c2 6 7 47u
fixed netlist c1 5 6 33u c2 6 7 47u rbogus 6 7 9e12The R_{bogus} value of 9 Tera-ohms provides a DC current path to C_{1} (and around C_{2}) without substantially impacting the circuit’s operation.
c1 4 7 22u .print ac v(4,7)However, if we wanted to have SPICE measure the current through that capacitor, it wouldn’t be quite so easy. Currents in SPICE must be specified in relation to a voltage source, not any arbitrary component. For example:
c1 4 7 22u vinput 6 4 ac 1 sin .print ac i(vinput)This .print card instructs SPICE to print the current through voltage source V_{input}, which happens to be the same as the current through our capacitor between nodes 4 and 7. But what if there is no such voltage source in our circuit to reference for current measurement? One solution is to insert a shunt resistor into the circuit and measure voltage across it. In this case, I have chosen a shunt resistance value of 1 Ω to produce 1 volt per amp of current through C_{1}:
c1 4 7 22u rshunt 6 4 1 .print ac v(6,4)However, the insertion of an extra resistance into our circuit large enough to drop a meaningful voltage for the intended range of current might adversely affect things. A better solution for SPICE is this, although one would never seek such a current measurement solution in real life:
c1 4 7 22u vbogus 6 4 dc 0 .print ac i(vbogus)Inserting a “bogus” DC voltage source of zero volts doesn’t affect circuit operation at all, yet it provides a convenient place for SPICE to take a current measurement. Interestingly enough, it doesn’t matter that V_{bogus} is a DC source when we’re looking to measure AC current! The fact that SPICE will output an AC current reading is determined by the “ac” specification in the .print card and nothing more. It should also be noted that the way SPICE assigns a polarity to current measurements is a bit odd. Take the following circuit as an example:
example v1 1 0 r1 1 2 5k r2 2 0 5k .dc v1 10 10 1 .print dc i(v1) .endWith 10 volts total voltage and 10 kΩ total resistance, you might expect SPICE to tell you there’s going to be 1 mA (1e-03) of current through voltage source V_{1}, but in actuality, SPICE will output a figure of negative 1 mA (-1e-03)! SPICE regards current out of the negative end of a DC voltage source (the normal direction) to be a negative value of current rather than a positive value of current. There are times I’ll throw in a “bogus” voltage source in a DC circuit like this simply to get SPICE to output a positive current value:
example v1 1 0 r1 1 2 5k r2 2 3 5k vbogus 3 0 dc 0 .dc v1 10 10 1 .print dc i(vbogus) .endNotice how V_{bogus} is positioned so that the circuit current will enter its positive side (node 3) and exit its negative side (node 0). This orientation will ensure a positive output figure for circuit current.
by Cabe Atwell
by Gary Elinoff
by George Biner
by Robert Keim