Documentation /  Analog Insydes /  Tutorial /  Circuits and Subcircuits /

Defining Subcircuits and Device ModelsSubcircuit Expansion

2.3.3 Referencing Subcircuits

The Netlist Entry Format for Subcircuit References

Subcircuits or device models defined with the Model command can be referenced from a netlist on a higher hierarchy level by a netlist entry whose value field contains the options Model and Selector:

subcircuit instance name, port connections,

Model -> subcircuit class name, Selector -> selector

To reference a subcircuit object (see Section 3.1.8) the subcircuit class name and the selector must be the same identifiers as those given as arguments to the Name and Selector parameters in the corresponding Model statement. The subcircuit instance name may be any symbol or string which can serve as the unique identifier of this instance of the subcircuit object.

You can even use subcircuit instance names which begin with an element type tag known to Analog Insydes. A subcircuit reference with an instance identifier such as RX will never be confused with a resistor because the reference will have been expanded before circuit equations are set up.

A netlist entry which marks a reference to an instance of the NPN transistor model NPNTransistor/ACsimple, using the instance identifier Q1, would be written as follows:

Q1, connectivity,

Model -> NPNTransistor, Selector -> ACsimple

This line does not yet specify how the instance Q1 of NPNTransistor/ACsimple should be embedded into the surrounding circuit structure, i.e. which nodes of the latter should be connected to the subcircuit's port nodes. Associating external nodes with subcircuit port nodes is done by means of a special format of the connectivity field. All entries of this field must be written as rules of the form

external node -> subcircuit port node

In our common-emitter amplifier (see Figure 3.1 in Section 2.3.1), node 1 of the top-level netlist is connected to the base node "B" of the transistor, node 3 to the collector node "C", and node 4 to the emitter node "E", resulting in a node-to-port mapping such as this:

{Q1, {1 -> "B", 3 -> "C", 4 -> "E"},

Model -> NPNTransistor, Selector -> ACsimple}

Since the mapping is defined by names, the relative positions of the entries in the connectivity field are not important. We could have written the connectivity field as

{3 -> "C", 1 -> "B", 4 -> "E"}

equally well.

A Hierarchical Netlist Description of the Amplifier

Having learned how to define and how to make references to subcircuits (see Section 3.1.8), we can now write a hierarchically structured netlist for the common-emitter amplifier from Section 2.3.1 (see Figure 3.1).

In[1]:= <<AnalogInsydes`

In[2]:= commonEmitterAmplifier=
Circuit[
Netlist[
{V1, {1, 0}, inputVoltage},
{VCC, {2, 0}, Type -> VoltageSource,
Value -> supplyVoltage},
{R1, {2, 1}, R1},
{R2, {1, 0}, R2},
{RC, {2, 3}, RC},
{RE, {4, 0}, RE},
{Q1, {1 -> "B", 3 -> "C", 4 -> "E"},
Model -> NPNTransistor, Selector -> BJTModel}
],

Model[
Name -> NPNTransistor,
Selector -> ACsimple,
Ports -> {"B", "C", "E"},
Definition ->
Netlist[
{RB, {"X", "E"}, RB},
{CC, {"B", "X", "C", "E"}, beta}
]
],

Model[
Name -> NPNTransistor,
Selector -> ACdynamic,
Ports -> {"B", "C", "E"},
Definition ->
Netlist[
{RB, {"X", "E"}, RB},
{CM, {"B", "C"}, CM},
{CC, {"B", "X", "C", "E"}, beta},
{RO, {"C", "E"}, RO}
]
]
]

Out[2]=

Note that in the top-level netlist of this circuit description we used a generic subcircuit selector BJTModel and not ACsimple or ACdynamic. This allows us to select the model at run time by replacing BJTModel with ACsimple or ACdynamic just before the subcircuit hierarchy is expanded. In addition, for reasons which will become apparent in the next section, we have used the variables inputVoltage and supplyVoltage to denote the values of the voltage sources V1 and VCC.

Remember that the Type directive in the value field of VCC prevents Analog Insydes from falsely interpreting the netlist entry as belonging to a voltage-controlled current source.

Defining Subcircuits and Device ModelsSubcircuit Expansion