Skip to content

User's guide

Luca Giaccone edited this page Jan 6, 2018 · 15 revisions

The SpicePy wiki provides the minimum information to use the code.

Netlist

SpicePy makes use of a netlist to describe the circuit. The notation used is very similar to the SPICE one. A netlist is a text file (common extensions are .net or .cir).

Components

In a netlist every component is defined as:

<label><X>  <node+>  <node->  <value>  <other optional information>

where:

  • <label><X> is the label of the component and X is an identification number,
  • <node+> is one node to which the component is connected. The sign + indicates that it is conventionally the positive node. It can be either a number or a letter,
  • <node-> is one node to which the component is connected. The sign - indicates that it is conventionally the negative node. It can be either a number or a letter,
  • <value> is the value of the component,
  • <other optional information> can be, for example, initial conditions for dynamic components of the phase of a generator to be used in AC problems

To give an example, a 5.6 ohm resistor caller R3 connected between nodes 1 and 5 is described in the netlist by:

R3  1  5  5.6

Analysis

The analysis is defined using standard SPICE simulation commands. The simulation command have to be included at the end (last line) of the netlist. Right now SpicePy supports three kind of simulation:

  • Operating point analysis: used to solve direct current (DC) networks and also to compute the initial conditions of circuits including dynamic components,
  • AC analysis: used to solve AC network in frequency domain,
  • Transient analysis: used to solve network in time domain.

Operating point analysis

To perform an operating point analysis it is sufficient to add at the end of the netlist the following simulation command:

.op

AC analysis

The AC analysis is defined by the following simulation command:

.ac  type  n  f1  f2

where:

  • .ac indicates the AC analysis
  • type indicates how to create the frequency range. It can be:
    • lin for a linear sweep with n points between frequencies f1 and f2 (> f1)
    • dec for a logarithmic sweep (by decades) with n points between frequencies f1 and f2 (> f1)
    • oct for a logarithmic sweep (by octaves) with n points between frequencies f1 and f2 (> f1)

SpicePy supports:

  • single-frequency simulation using the following notation: .ac lin 1 f f

  • multi-frequency simulation using the general notation .ac type n f1 f2

In the case of multi-frequency simulations, it is better to plot (rather than print) the results. Therefore, there is another command that must be included in the network to specify transfer functions. Defining a transfer function makes it possible to plot it bode diagram later (as shown in the examples).

.tf var1(<label><X>) var2(<label><X>) ... varN-1(<label><X>) varN(<label><X>)

where:

  • .tf indicates the intention to define a transfer function
  • var1(<label><X>) var2(<label><X>) defines the transfer function: var1(<label><X>)/var2(<label><X>)
  • varN-1(<label><X>) varN(<label><X>) defines the transfer function: varN-1(<label><X>)/varN(<label><X>)

It goes without saying that the number of variables after .tf must be even. Finally, variables can be either voltages (e.g. v(R1)) or current (e.g. i(L3)).

Transient analysis

The transient analysis is defined by the following simulation command:

.tran  step  tend

where:

  • .tran indicates the transient analysis
  • step is the time step for numerical integration
  • tend set the final integration time (i.e. the transient is analyzed in the range 0 - tend)

In transient analysis it is better to plot (rather than print) the results. Therefore, there is another command that must be included in the network to specify what to plot:

.plot v(<label><X>) ... i(<label><X>) ...

where:

  • .plot indicates the intention to plot something
  • v(<label><X>) means the voltage across the component <label><X> (same notation as in the component description)
  • i(<label><X>) means the current through the component <label><X> (same notation as in the component description)

The user can specify as many variable as desired and it not required any specific order. In the final plot voltages are grouped in the same plot and separated by currents which are grouped in another plot. Voltages and currents appear in the plot according to the order defined by the user in the .plot command.

Circuit solution with SpicePy

Since all information about the circuit and the problem type are included in the netlist. The code to solve the circuit is always the same.

The following modules have to be imported.

import netlist as ntl			# module to read the netlist
from netsolve import net_solve		# module to solve the circuit

Given a netlist in the file circuit.net, the following code provides the circuit solution using the modified nodal analysis:

net = ntl.Network('circuit.net')	# read the netlist
net_solve(net)				# compute the circuit solution

Branch quantities as voltages, currents and powers can be calculated using the methods of the python class Network:

net.branch_voltage()	# compute branch voltages
net.branch_current()	# compute branch currents
net.branch_power()	# compute branch powers

Branch quantities can be eventually printed netprint module:

net.print()

More details can be found in the examples page.