next up previous contents index
Next: Subcircuit Expansion Up: Subcircuits Previous: Subcircuits   Contents   Index

.subckt Line

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

The keyword ``.macro'' is equivalent to ``.subckt''. The ``.subckt'' keyword is actually a default, and this keyword can be reset through setting the substart variable. The .macro variable applies in any case.

A subcircuit definition begins with a .subckt line. The 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 or underscore, 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.

The concatenation character can be set to a different character with the var_catchar variable. If this variable is set to a string consisting of a single punctuation character, then that character becomes the concatenation character.

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.

For example, the definition

.subckt xxx 1 1

is converted to

.subckt xxx 1 _#0
v_xxx_0 1 _#0
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: Subcircuit Expansion Up: Subcircuits Previous: Subcircuits   Contents   Index
Stephen R. Whiteley 2022-09-18