Documentation /  Analog Insydes /  Tutorial /  Circuits and Subcircuits /

Referencing SubcircuitsSubcircuit Parameters

2.3.4 Subcircuit Expansion

The ExpandSubcircuits Command

Before we can set up circuit equations we must resolve all references to subcircuit objects. Subcircuit instantiation and flattening the netlist is done by the command ExpandSubcircuits which accepts a Circuit or a Netlist object as argument and returns a flat netlist object.Such a flat netlist is similar to a Netlist, except that it is guaranteed to contain only circuit primitives and no subcircuit references.

Please note that subcircuit expansion is taken care of automatically by CircuitEquations, so that there is usually no need to call ExpandSubcircuits explicitly, except for inserting models into the global data base. Section 2.3.6 deals with this topic.

We can now use ExpandSubcircuits to generate one flat netlist of the common-emmitter amplifier from Section 2.3.1 (see Figure 3.1) for each of the two transistor models we have defined. As the circuit description is still generic we must first personalize it by replacing its variables according to the specific analysis task. Our task was to calculate the small-signal voltage transfer function, so besides choosing an appropriate transistor model we must set the value of the supply voltage source VCC to zero and the value of the input signal source to (see Section 2.9.2). Then, the node voltage at the output node 3 will be identical to the transfer function. We apply these variable settings to the netlist with the Mathematica command ReplaceAll (or /. in short notation) and pass the resulting netlist to ExpandSubcircuits.

In[3]:= flatAmpSimple = ExpandSubcircuits[
commonEmitterAmplifier /.
{supplyVoltage -> 0, inputVoltage -> 1,
BJTModel -> ACsimple}];
DisplayForm[flatAmpSimple]

Out[4]//DisplayForm=

In[4]:= flatAmpDyn = ExpandSubcircuits[
commonEmitterAmplifier /.
{supplyVoltage -> 0, inputVoltage -> 1,
BJTModel -> ACdynamic}];
DisplayForm[flatAmpDyn]

Out[6]//DisplayForm=

As we can see from the flattened netlists, ExpandSubcircuits has not simply replaced the subcircuit references by the original netlists from the Model definitions. The function has also generated unique symbols for all internal reference designators and node identifiers in the subcircuit netlists by appending a separator character ($) and the subcircuit instance name (Q1) to the original identifiers. This eliminates possible name conflicts with reference designators from the top-level netlist and allows for using multiple instances of a subcircuit definition.

Analysis of the Common-Emitter Amplifier

Now we can analyze the circuit by means of the functions CircuitEquations and Solve. We start by setting up the modified nodal equations for the simple AC model from the flattened netlist. Note that we could call CircuitEquations on the Circuit object equally well. We used ExpandSubcircuits for demonstrating the subcircuit expansion mechanism.

In[5]:= eqAmpSimple = CircuitEquations[flatAmpSimple];
DisplayForm[eqAmpSimple]

Out[8]//DisplayForm=

To compute the small-signal voltage transfer function we must solve the MNA equations for the node voltage V$3 at the output node 3.

In[6]:= v3 = Solve[eqAmpSimple, V$3]

Out[9]=

The following command extracts the symbolic transfer function expression from the return value of Solve.

In[7]:= vtf = V$3 /. First[v3]

Out[10]=

Now, let's see what happens when we make the (usually realistic) assumption that the transistor current gain is very large:

In[8]:= Limit[vtf, beta -> Infinity]

Out[11]=

The above result is indeed identical to the well-known approximate formula for the voltage gain of a common-emitter amplifier. Doing the same calculations for the other transistor model shall be left to the reader as an exercise.

Referencing SubcircuitsSubcircuit Parameters