Subcircuit definition ( .SUBCKT |
In some applications, describing a device by embedding the required elements in the main circuit file is not desirable. A hierarchical approach may be taken by using subcircuits. A subcircuit that consists of SPICE elements can be defined and referenced in a fashion similar to device models.
The subcircuit is defined in the input file by a grouping of element lines; the program then automatically inserts the group of elements wherever the subcircuit is referenced. There is no limit on the size or complexity of subcircuits, and subcircuits may contain other subcircuits. Subcircuit calls may not be recursive. Subcircuits are instantiated using X devices.
.SUBCKT <name> <node>* [OPTIONAL:
<<node>=<default node>>*] [PARAMS: <<name>=<default value>>*] [TEXT:
<<name>=<default value>>*] ...... elements ...... .END S [name] |
.SUBCKT
This statement marks the beginning of a subcircuit definition. The subcircuit definition ends with the .END S statement. All statements between the .SUBCKT and the .END S statements are included in the subcircuit definition.
name
Is the subcircuit name. The name is used by an X (Subcircuit Instantiation) device to reference the subcircuit.
node
Are the external nodes. Do not use 0 (zero) in this node list. Zero is reserved for the global ground node. There must be the same number of nodes in the subcircuit calling statements as in its definition. When the subcircuit is called, the actual nodes (the ones in the calling statement) replace the argument nodes (the ones in the defining statement).
PARAMS:
The keyword PARAMS: passes values into subcircuits as arguments and uses them in expressions inside the subcircuit. The parameters are specified by the pair: name = default value. The specified value is the default value for the parameter specified by name. If the call of a subcircuit do not specify a value for a given parameter then it will use its default value.
Note: If the value is in quotation marks then the parameter is of type text and is used as if it were specified after the keyword TEXT:.
OPTIONAL:
Allows specification of one or more optional nodes in the subcircuit definition. The optional nodes are stated as pairs consisting of an interface node and its default value. If an optional node is not specified in an X device, its default value is used inside the subcircuit; otherwise, the value specified in the definition is used. This feature is particularly useful when specifying power supply nodes, because the same nodes are normally used in every device.
TEXT:
The keyword TEXT: lets you pass text parameters to the subcircuit. Defines the name of the text parameter and the value it will assume if the text parameter is not included in the subcircuit call. It substitutes value for name everywhere within the subcircuit.
elements
The group of element lines which immediately follow the .SUBCKT line define the subcircuit. Control lines may not appear within a subcircuit definition; however, subcircuit definitions may contain anything else, including other subcircuit definitions, device models, and subcircuit calls. Note that any device models or subcircuit definitions included as part of a subcircuit definition are strictly local (i.e., such models and definitions are not known outside the subcircuit definition). Also, any element nodes not included on the .SUBCKT line are strictly local, with the exception of 0 (ground) which is always global.
.ENDS
The "Ends" line must be the last one for any sub-circuit definition. The subcircuit name, if included, indicates which subcircuit definition is being terminated; if omitted, all subcircuits being defined are terminated. The name is needed only when nested subcircuit definitions are being made. Since subcircuits can be listed sequentially, with the same effect, it is not recommended that subcircuits are nested.
X1 10 20 30 40 SUB1 PARAMS: P1=1 P3=5 TEXT: FILE=PWLDATA.TXT
.SUBCKT SUB1 1 2 3 4 PARAMS: P1=0 P2=0 P3=0 TEXT: FILE=SIMPLEPWL.TXT
.....
.ENDS SUB1