2.3.7 The Translation Argument
Implicit Translation of Parameter Values
Another argument of the Model function which remains to be discussed is the Translation keyword. We can use it to define functional relations between formal subcircuit parameters and internal element values when there is no one-to-one correspondence between both. The syntax is:
Translation -> -> , -> ,
The purpose of the Translation argument is best explained by an example. Assume that we wish to analyze the Darlington amplifier from Section 2.3.5 (see Figure 3.3) using the VCCS transistor model from Section 2.3.6 (see Figure 3.4) instead of a CCCS model. For nodal analysis, the former is usually a better choice than the latter because the VCCS model does not increase the matrix size by introducing additional controlling currents into the modified nodal equations. However, even with a VCCS model we might like to describe the transistors in terms of their current gains beta instead of their transconductances gm by making use of the well-known relation . With the help of the Translation argument we can define a translation rule which maps the formal model parameters RB and beta to the transconductance gm used internally as the element value of the VCCS:
In[23]:= Circuit[ Model[ Name -> NPNTransistor, Selector -> ACgm, Scope -> Global, Ports -> {"B", "C", "E"}, Parameters -> {RB, beta}, Translation -> {gm -> beta / RB}, Definition -> Netlist[ {RB, {"B", "E"}, RB}, {VC, {"B", "E", "C", "E"}, gm} ] ] ] // ExpandSubcircuits;
In[24]:= darlNumParams = Circuit[ Netlist[ {I1, {0, 1}, 1}, {Q1, {1 -> "B", 2 -> "C", 3 -> "E"}, Model -> NPNTransistor, Selector -> ACgm, RB -> 400.0, beta -> 150.0}, {Q2, {3 -> "B", 2 -> "C", 0 -> "E"}, Model -> NPNTransistor, Selector -> ACgm, RB -> 100.0, beta -> 50.0}, {Load, {0, 2}, Type -> Resistor, Value -> RL, Pattern -> Impedance} ] ];
Just before subcircuit expansion the right-hand sides of the translation rules are evaluated with the parameter values specified in the value fields of the subcircuit references. The evaluated parameter translation rules are then applied to all value fields in the subcircuit netlist, resulting in the replacement of all symbols appearing on the left-hand side of the translations. Thus, gm is automatically calculated from RB and beta.
In[25]:= ExpandSubcircuits[darlNumParams] // DisplayForm
Out[29]//DisplayForm=
Delayed Translation Rules
In this simple example, using the Translation argument is not absolutely necessary. We could have achieved the same effect without a translation rule by writing the netlist entry for the VCCS like this:
{VC, {"B", "E", "C", "E"}, beta / RB}
So why should we use translation rules at all? The answer is that parameter value translations can also be specified by means of delayed rules, i.e. the RuleDelayed lhs :> rhs instead of the Rule lhs -> rhs. Since delayed rules are left unevaluated until the very moment they are needed, their right-hand sides also contain calls to external functions which perform calculations depending on the model parameter values. For instance, let's define a function which, given values for beta and RB, calculates the transconductance of a transistor by solving the formula numerically for gm, using as initial guess.
In[26]:= Transconductance[b_Real, r_Real] := Module[ {g}, Print["Computing gm for beta = ", b, " and RB = ", r]; g /. FindRoot[g * r == b, {g, 1.0}] ]
By means of a delayed translation rule for gm we can instruct Mathematica not to execute the function call at the time the transistor model is defined but to wait until the rule is used to compute gm for a particular subcircuit instance.
In[27]:= Circuit[ Model[ Name -> NPNTransistor, Selector -> ACgm, Scope -> Global, Ports -> {"B", "C", "E"}, Parameters -> {RB, beta}, Translation -> {gm :> Transconductance[beta, RB]}, Definition -> Netlist[ {RB, {"B", "E"}, RB}, {VC, {"B", "E", "C", "E"}, gm} ] ] ] // ExpandSubcircuits;
If we had used an immediate rule above, gm -> Transconductance[beta, RB], Mathematica would have already called Transconductance with the symbolic arguments beta and RB at the time of model definition. On the other hand, the delayed rule permits Analog Insydes to replace the arguments with instance-specific values before making the function call. This is done once per subcircuit instance as can be seen from the following output:
In[28]:= ExpandSubcircuits[darlNumParams] // DisplayForm
Out[32]//DisplayForm=
An advanced application of such a parameter translation scheme would be the calculation of transistor small-signal parameters from given operating-point voltages and currents via a set of predefined device equations.
Alternative Ways to Assign Values to Parameters
In combination with the Parameters setting there is one further useful application of the argument Translation. Specifying a translation rule for a symbol which is also designated as a parameter of the same subcircuit definition allows us to choose whether we let the instance value of the symbol be calculated from other parameters or whether we assign a value to this symbol directly. For example, let's add the transconductance gm to the list of model parameters while leaving the translation rule for gm unchanged:
Parameters -> {RB, beta, gm},
Translation -> {gm :> Transconductance[beta, RB]},
The value field of a reference to the transistor model can now be written in two alternative ways. Just as in the previous subsection we can assign values to RB and beta only and let Analog Insydes calculate gm from the two quantities automatically. Alternatively, we can bypass the translation rule by directly assigning a value to gm, such as gm -> 0.5. Any value given for beta is then effectively ignored because it is not needed anywhere else than in the argument list of the translation rule. In the netlist below, we let gm$Q1 be computed from RB and beta by means of the translation rule. In the case of Q2, however, we do not specify a value for beta but make a direct assignment to gm: gm -> gm2. Therefore, the parameter translation function Transconductance is not called for gm$Q2:
In[29]:= Circuit[ Netlist[ {I1, {0, 1}, 1}, {Q1, {1 -> "B", 2 -> "C", 3 -> "E"}, Model -> NPNTransistor, Selector -> ACgm, RB -> 400.0, beta -> 150.0}, {Q2, {3 -> "B", 2 -> "C", 0 -> "E"}, Model -> NPNTransistor, Selector -> ACgm, RB -> 100.0, gm -> gm2}, {Load, {0, 2}, Type -> Resistor, Value -> RL, Pattern -> Impedance} ],
Model[ Name -> NPNTransistor, Selector -> ACgm, Scope -> Global, Ports -> {"B", "C", "E"}, Parameters -> {RB, beta, gm}, Translation -> {gm :> Transconductance[beta, RB]}, Definition -> Netlist[ {RB, {"B", "E"}, RB}, {VC, {"B", "E", "C", "E"}, gm} ] ] ] // ExpandSubcircuits // DisplayForm
Out[33]//DisplayForm=
|