Subcircuit Definition

The main circuit refers to the circuit definition which begins with the title statement, which is the first line in the input file, and ends with the .END statement, which is the last significant line in the input file. Any number of subcircuits can be defined within the main circuit. The subcircuits can also be nested within other subcircuits. As many as 20 levels of nesting are allowed. A typical group of statements defining a subcircuit definition duplicates the following pattern of statements:

  • Start Subcircuit Statement
  • Comment Statements
  • Device Statements
  • Model Statements
  • Subcircuit Definitions
  • Control Statements
  • End Subcircuit Statement

Obviously, the "Start Subcircuit Statement" and the "End Subcircuit Statement" must be the first and the last statements, respectively, in the definition of a subcircuit. Between these start and end statements, the comment statements, device statements, model statements, subcircuit definitions, and control statements can appear in any order or sequence without any effect on the reading of the input file.

In this topic:

Parent and Child Relationships for Subcircuits

When a subcircuit named "AAA" is defined in a general circuit named "BBB", then the subcircuit "AAA" is considered the child of the general circuit "BBB" and the general circuit "BBB" is considered the parent of the subcircuit "AAA". Each subcircuit can have only one parent and each general circuit can have zero, one, or more children. The main circuit is the ancestor of all subcircuits defined in the entire input file and it does not have a parent.

.SUBCKT Statement

In this section, a brief description of the .SUBCKT statement is given. The format of the .SUBCKT statement is defined as:

.SUBCKT  sname  n1  n2  n3 ...
where
.SUBCKT is the seven-character keyword ".SUBCKT" signifying the start of the subcircuit definition
sname is a legal subcircuit name as explained in Model Names and Subcircuit Names. A subcircuit name must be unique within a general circuit. If a name is used as a subcircuit name in a general circuit, it cannot be used as a model name in the same general circuit and vice-versa
n1 is the node name of the first external node of the subcircuit
n2 is the node name of the second external node of the subcircuit
n3 is the node name of the third external node of the subcircuit, and so on
The elements defined in a subcircuit interact with the subcircuit's parent circuit only through the subcircuit's external nodes and the ground node (node 0). Node 0, the ground node, is not allowed to be used as an external node unless the option of MAPNODE0 is used in an .OPTION control statement. Refer to Sections Scope of Definition for a Device and for a Node and Option Statements on the properties of MAPNODE0.

.ENDS Statement (End of Subcircuit Statement)

In this section, a brief description of the .ENDS statement is given. The format of the .ENDS statement is defined as:

.ENDS [sname]
where
.ENDS is the five-character keyword ".ENDS" signifying the end of one or more subcircuits
sname is the name of a subcircuit whose definition has not been terminated. The subcircuit name may be omitted to form the special case of the non-specific .ENDS statement.

Subcircuits are normally terminated with a .ENDS statement in the .ENDS [sname] , or specific form. If a subcircuit has not been terminated with this form of .ENDS statement, the non-specific form of the .ENDS statement:

.ENDS
will terminate the subcircuit. All subcircuits whose definition have not been terminated individually will be terminated in a group by the .ENDS statement without a subcircuit name. For example, in the statements shown in the example below, the three subcircuits SUB1, SUB2, and SUB3 are all terminated by the .ENDS statement. In this example, because of the use of the non-specific form of the .ENDS statement, subcircuit SUB1 is the parent of subcircuit SUB2, which is itself the parent of subcircuit SUB3. The placement of .ENDS statements determines the parent-child relationships of the subcircuits. The line immediately following the .ENDS statement is considered to be part of the definition of the parent of subcircuit SUB1.
Example 5.1
.SUBCKT SUB113
R1 1 2 1K
C1 2 3 1U IC=1
X1 2 3 SUB2
.SUBCKT SUB2 101 103
R2 101 102 1K
C2 102 103 1U IC=1
X2 102 103 SUB3
.SUBCKT SUB3 201 203
R3 201 202 1K
C3 202 203 1U IC=1
.ENDS
If sname is given in an .ENDS statement, then sname must be the name of the subcircuit currently defined or the name of a subcircuit which is an ancestor of the subcircuit currently defined. In this case, the definition of the current subcircuit, its parent, its grandparent, ..., and the subcircuit whose name matches sname are all terminated at this .ENDS statement. For the statements in the example below, the statement .ENDS SUB2 terminates the definition of subcircuits SUB2 and SUB3 but not the definition of subcircuit SUB1. The line immediately following the ".ENDS SUB2" statement is considered part of the definition of subcircuit SUB1, which is the parent of subcircuit SUB2.
Example 5.2
.SUBCKT SUB113
R1 1 2 1K
C1 2 3 1U IC=1
X1 2 3 SUB2
.SUBCKT SUB2 101 103
R2 101 102 1K
C2 102 103 1U IC=1
X2 102 103 SUB3
.SUBCKT SUB3 201 203
R3 201 202 1K
C3 202 203 1U IC=1
.ENDS SUB2
Notice that there is a unique correspondence between each .SUBCKT statement and the start of a subcircuit while each .ENDS statement may be "shared" by several subcircuits. The recommended practice, however, is to terminate each subcircuit with a unique .ENDS statement having a matching subcircuit name instead of using the implied termination. This will make reading the input file easier and will make the subcircuit definitions less susceptible to error.