next up previous contents index
Next: .ends Line Up: Subcircuits Previous: Subcircuits   Contents   Index


.subckt Line

General Form:
.subckt subnam n1 [n2 ...] [param1=val1 param2=val2 ...]
Examples:
.subckt opamp 1 2 3 4
.subckt stage1 3 10 2 resis=2k cap=1nf

A subcircuit definition begins with a .subckt line. The parameter subnam is the subcircuit name, and n1, n2, ... are the external nodes, which cannot be zero. The group of element lines which immediately follow the .subckt line define the subcircuit. The last line in a subcircuit definition is the .ends line (see below). Control lines should not appear within a subcircuit definition, however subcircuit definitions may contain anything else, including other subcircuit definitions, device models, and subcircuit calls (see below). 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 or in .global lines are strictly local, with the exception of 0 (ground) which is always global.

The subcircuit declaration line can contain an optional list of param=value pairs. The params are tokens which must start with a letter, which can appear in the subcircuit lines. These are not shell variables, so there is no `$' or other punctuation, but the `%' concatenation character is recognized. The concatenation character is used to separate the token from the other text: for example RES%K allows RES to be identified as a token, and if RES is `1' the substitution would yield `1K'. The param token must be surrounded by non-alphanumeric characters. Parameters defined this way are always superseded by parameters given in the subcircuit call, but override parameters defined in .param lines.

WRspice can handle duplicate formal node args in .subckt lines. It does so by assigning a new node to one of the duplicates, then inserting a voltage source between the two nodes, which is added to the subcircuit text. This mainly solves a problem related to files generated by Xic. If two or more subcircuit terminals are attached to the same wire net, the resulting .subckt line will have duplicate nodes. In the limiting case where a subcircuit consists only of a wire with two connections, the subcircuit would in addition be empty.

Example:

.subckt xxx 1 1
.ends

is converted to

.subckt xxx 1 _#0
v_xxx_0 1 _#0
.ends
during subcircuit expansion, which avoids an empty subcircuit and has the intended effect of instances shorting the two terminals together.


next up previous contents index
Next: .ends Line Up: Subcircuits Previous: Subcircuits   Contents   Index
Stephen R. Whiteley 2006-10-23