Tuesday, October 10, 2006

Subcircuits

There seem to be two different ways to accomplish subcircuits in LTspice. One of them is meant for creating models of components that might be used in many of your circuits. The other is for modularizing a particular project into smaller blocks, and wiring the blocks together. I'll be covering the latter.

Subcircuit blocks are made up of two pieces: The symbol used to represent the subcircuit, and the schematic of the subcircuit itself. Each piece is a separate LTspice file, and they must have the same filename, differing only in the 3 letter exension (.asc for the schematic and .asy for the symbol).

Create the subcircuit in the same way you would create any other schematic, except that anywhere you want to create a place to connect to your subcircuit from the outside world, leave a wire hanging on one end. Like this:



Then right-click on the schematic and choose "Label Net." This allows you to name a node whatever you want, so that instead of N001 it might be called Vout. If you want a nice little directional box around your label you can choose input or output from the "Port Type" menu. Place labels on any unconnected wires that you want to make into ports. Now save the schematic somewhere where you'll find it.

To create the symbol for the subcircuit, click "File," then "New Symbol." The important functional parts of a symbol are the Pins or Ports. Press 'p' to create a new pin/port. Give the port a name that matches one of the nodes that you named on your subcircuit schematic. The pin label positions will vary depending on how you want to lay out your circuit. You can use the graphics drawing functions under the "Draw" menu to make some sort of representative graphic for your subcircuit.

Now just save the symbol, making sure to use the same name that you used for the schematic, and in the same directory.

That's it. You now have a subcircuit that you can use just like any other component. To insert your subcircuit into another schematic, simply press 'F2' to bring up the "Select Component Symbol" dialog, and then in the "Top Directory" drop-down menu select the folder that contains the subcircuit. The folder that it lets you choose is whatever directory the current circuit is saved in, so make sure that the top-level circuit, the subcircuit schematic, and the subcircuit symbol are all be in the same directory.

Later I'll cover more advanced subcircuit techniques like passing parameters down to subcircuits.

No comments: