(X) Subcircuit Instance Statement
X statements allow you to instantiate subcircuits. Be aware of Scopes and Shadowing.
Xname n1 <n2 ...> subName <PARAMS: <p1=val1 ...>>
Creates an instance of the subcircuit
subName.The nodes in the X statement are the nodes in the current scope. Inside the instantiated
.SUBCKTcall they correspond to the node names of the.SUBCKTstatement.You can override some or all of the
.SUBCKTstatement parameters values by specifying them aftersubName. Any parameter not overwritten uses the default value of the.SUBCKTstatement. Any parameter passed to a subcircuit in an X statement immediately evaluates the parameter value before passing it on (see Subtleties of Shadowing).
Note
We recommend to always specify all parameters that you want to pass to a subcircuit in both the .SUBCKT and the X statement.
PARAMS: can be skipped.
Equal signs for assigning parameters can be skipped as long as all expressions are in curly braces.
Curly braces can be skipped around parameters.
This can lead to ambiguity.
As long as we find a unique matching subcircuit, we do not throw an error.
.SUBCKT main a b
.PARAM c=3
X1 a b c; Unclear which of the following two subcircuits is desired.
.ENDS
.SUBCKT a PARAMS: b=1
...
.ENDS
.SUBCKT c n1 n2
...
.ENDS
You may also provide additional parameters that do not have explicit defaults in the corresponding .SUBCKT statement.
If you provide an additional parameter, it cannot be set to a different value in the .SUBCKT.
Be aware of Subtleties of Shadowing.
.SUBCKT main n1
X1 n1 helper PARAMS: a=1
.ENDS
.SUBCKT helper1 PARAMS: b=1
* The instance created by X1 has access to a=1 even though a is not defined in helper1.
.ENDS
subName can be put inside of curly braces.
We evaluate it as a parameter when determining which .SUBCKT to load.
.SUBCKT main n PARAMS: a=1
X1 n {a}; Calls subcircuit 1 or 2 depending on value of a.
.ENDS
.SUBCKT 1 n
*...
.ENDS
.SUBCKT 2 n
*...
.ENDS
Warning
When importing a netlist that uses {subName} as syntax to select a SUBCKT based on parameter values, we only copy the .SUBCKT needed to simulate with default parameters.
If changing parameters loads another .SUBCKT, one needs to copy and paste that subcircuit manually below the main subcircuit.
Examples
.SUBCKT main n1 n2 n3
X1 n1 helper1
X2 n1 helper2 PARAMS: a=3
.ENDS
.SUBCKT helper1 m1
* the node called n1 in the main subcircuit is now accessible as m1
.ENDS
.SUBCKT helper2 m1 PARAMS: a=1 b=2
* The instance created by X2 sets a to 3 instead of 1.
R1 m1 0 {a}
R2 m1 0 {b}
.ENDS