Using Subcircuits In Ngspice

gschem Schematic

To include a subcircuit, you need to use the .include directive. We will add this to our netlist with the SPICE directive component, which can be found in the Add Component window (under SPICE simulation elements) of gschem. For example, to include a subcircuit file named name-of-file.cir that is in the same directory as your schematic, type this for the "value" field of the SPICE directive:
.include name-of-file.cir

In this example, I will use the SIRIUS PURPLE Class A operational amplifier subcircuit:

Spice Directive Attributes

I then select the opamp-1.sym or opamp-2.sym component in gschem. Note you need to change the refdes from U to X, as X signifies a subcircuit. I then enter the subcircuit name "sirius-purple-a" for the "value" attribute of the opamp (you can find the name of the subcircuit after .SUBCKT, on the same line, in the subcircuit file).

Opamp Attributes

In the Inverting Amplifier configuration, the gain should be -Rf2/Rf1. It is negative because it is inverting, please do not confuse inverting (negative gain) with attenuation (a gain of less than 1). The gain should be -100! +40dB!

Let's do some simulations!

Transient Analysis:

Ngspice Transient Analysis

Note that the signal has been inverted!

AC Analysis:

Ngspice AC Analysis