# 01_dc: sheet preparation and DC op point

## Scope

In this simulation we are going to calculate the DC operating point of a simple voltage divider. This is also an introduction to setting up a sheet for circuit simulation. This tutorial deals with differences between spice implementations by describing the process for ngspice and then any differences for other implementations are described at the bottom.

## The schematics

The single-sheet schematic contains the voltage divider with all networks named and two extra symbols for the simulation:

- a 5V voltage source, V1
- a spice command symbol

Note: these symbols do not have a footprint attribute so they are not exported in the PCB workflow.

Click the image to get the sch-rnd sheet

## SPICE: what is a DC op point

In SPICE simulation there are different analysis options available: these are different simulation actions or operations or modes. Basically each analysis is a different algorithm to run on the circuit. The simplest analysis is called the "DC operating point analysis".

In the op point analysis, the simulator will apply all sources, assume all inductors are shorted and assume all capacitors are open and then calculate the voltage for all nodes. (Node is the spice terminology for an equipotential electrical network.) This simulation is not time or frequency dependent, and represents a single DC operating point once the circuit has already stabilized.

In our example, this means V1's 5V is applied and the voltages at in, out1 and out2 are calculated. Since V1 is an ideal voltage source capable of supplying any amount of current, the voltage on the in network will be 5V; but the voltages on out1 and out2 will depend on the resistor values of R1, R2 and R3.

## Preparing for simulation

### Symbols and nets

Draw the schematics as usual; make sure there is a gnd network, spice won't work without that. Ideally, use the stock gnd symbol for that. Make sure all resistors have a unique name and a value. Spice understands the normal SI suffixes such as k for kilo, but as it is generally not case sensitive, m and M are both milli, so you will need to write meg to get mega.

Your symbols also need to have the proper spice pin numbers. First switch your view from the default pcb to spice_raw: there's a button for this on the top right part of the main window, on the left of the help/support button. This pops up a view selector; click raw_spice twice and the selector will close and the view will change. The new view will show pin numbers as seen by the spice target. For plain resistors, pin ordering does not matter, but it is important for polarized parts like diodes, transistors, and sources. The stock library has spice pin numbers set up and should work without modification. Later chapters of this tutorial will explain how to deal with spice pin numbers in symbols.

### V1

In the raw spice approach, the voltage source needs to be specified in the concrete model. The easiest way is to place a source-DC symbol from the stock library in between the in network and the ground. The name of the symbol does not matter; as we are using it as a voltage source, it is best to name it V1. To make it produce a steady 5V output, create an attribute called spice/params and set it to DC 5V. It is also a good idea to make this visible in the form of a floater.

External resource: ngspice manual on voltage and current sources explains all the different parameter options; spice/params is the part that gets written after N-; later chapters will demonstrate using more complex waveforms than plain flat DC. For a DC operating point we are only interested in the DC component, tho.

### Raw spice commands

The circuit is complete. It could be exported and the simulator could read it, but command to start any simulation would need to be specified by hand, on the simulator's command line. It is more convenient for now to specify these commands in the schematics. For that, the spice_command symbol is placed from the stock library. The actual spice commands are stored in the spice/command attribute. This is typically a multiline string attribute. Use the attribute editor (accessible from the right click menu over the symbol), select the attribute and click on the "edit multiline" button.

It contains two lines:

    op
    print v(out1) v(out2)

The first line instructs spice to do the "DC operating point analysis", the second tells it to print the voltage of out1 and the voltage of out2 (each measured to ground) on stdout. You can list more voltages here by v(netname) and it is possible to print currents and other properties, as will be shown in later chapters of this tutorial.

Note: this symbol has no name attribute, so it is not exported as a normal component.

## Export the netlist

GUI export: make sure your view is set to spice_raw, as it affects not only how the circuit is displayed on the GUI but also how it is exported. Open the file menu, click on export project (hotkey: {f j}). Select spice in the export dialog, verify the file name and click the export button.

CLI export:

    sch-rnd -x spice --view spice_raw 01_dc.rs

## Run ngspice

From a shell run this command (assuming the exported netlist is called 01_dc.cir):

    ngspice 01_dc.cir

This will print a lot of noise and these two lines:

    v(out1) = 2.380952e+00
    v(out2) = 1.190476e+00

These are the voltages (in V) measured on the networks out1 and out2 in steady state. Type quit to exit the spice prompt.

## Using other implementations

### gnucap

Gnucap uses a different command syntax. Modify the spice command symbol's spice/command attribute to:

    print dc v(out1) v(out2)
    dc

This tells gnucap what to print after a dc simulation then runs the dc simulation.

After the export, write the single word spice in the first line of the file (e.g. using a text editor), otherwise gnucap won't know the file is in spice syntax. Then run gnucap 01_dc.cir and it will print (among tons of noise) the two voltages.

The gnucap-modified schematic is also available.

### xyce

TODO