As mentioned before, this will be a series of posts for tips using LTSpice. This post will be covering the basics of making usable sub-circuits and hierarchical blocks based on existing library components. I will be putting together an idealized version of an Op-Amp from Analog Devices called the OP275GPZ (Digi-Key part number OP275GPZ-ND) which is an Audio Amplifier that I am using in a design. The actual device has more specific data values, so this version will not be to the same specifications.

Creating the First Sub-Circuit/Block

Start with a new schematic for the base-line circuitry.

From the first post, click the AND gate symbol for the component library and search for “Univ”.



I had a lot of headaches when I first tried to make this part before because some of the basic op-amps in the library have unusable models when making a valid Spice library component (this will be covered soon). It is better to use the UnversalOpamp2 device as the model has a good pre-installed sub-circuit. Place one of these into the circuit and mirror the other by pressing Control + E on the keyboard and place the other in close proximity to the first. Wire the circuit in a similar fashion to the picture below.



Like the last circuit, the wires can be sent in any direction to make the circuit custom to what is preferred. The only note is that distinct, unconnected wires must not connect to anything yet. Terminate a wire anywhere by clicking on the desired grid location then pressing escape on the keyboard. These will serve as the outputs and inputs labeled for use in an upper-level circuit. Each node has to have a unique name that is easy enough to remember, I will be going off the data sheet for the OP275 starting with “OUTA”. Use the Label Net tool to place names for the output/input nodes that are unconnected.

A. Click the Label Net tool or press F4.





When the dialogue box opens, there are two global pin names GND and COM. Underneath that is where the custom names for the pins need to be typed. It is also important to pick the type of port, in this case, OUTA is an output. Unsure if something is an input or output? Bi-directional might be a good option to pick.

B. Place the label nets on the appropriate wire ends/outputs.



When “OK” is clicked, place the clear blue rectangle on the output of U1 or on the end of the wire for the output of U1 as this is the equivalent of OUTA. Typically, I create the nodes in the order that the data sheet lists for pins 1-n where n = 8 for the part number, n can be any integer based on the number of pins the custom part has. The order does not strictly need to be followed when placing pins, but the Netlist order will matter later on for sub-circuits only. It might be faster from this point to use Control + C to copy the node output, place the copied label on all the open connections, and then edit each one to have a unique name. Here is what mine will look like when finished, make sure to edit the pin type for the Voltage Inputs and Op-Amp inputs to “Inputs” int he Label Net editor.



C. Copy the Netlist for this circuit and make a few edits in a basic text editor or Notepad++ to make this a valid sub-circuit.

a. The first step is to save the circuit as a unique name in the master folder.



The next steps through d. only apply to sub-circuits.

b. Click the View menu and chose the “SPICE Netlist” option, copy all the text in the next window, paste into a new blank text using Notepad or Notepad++.





c. Make sure that all the edits are made in the image below.



The second and second to last line is really important . The .subckt SPICE command makes a new sub-circuit called OPZ8DIP with the ordered pins named OUTA, -INA, +INA, V+, +INB, -INB, OUTB, and V+. The order of the pins absolutely matters in this case and must be remembered. Technically, the pin names can be re-ordered, but they will become different netlist numbers. If the wrong netlist number is referenced, when making a symbol, there will be unexpected results in analysis or it may fail to work. The netlist order begins at 1 starting after the name of the sub-circuit and ends with the last pin name. The pin names must be named the same as the names given to the nodes. Each pin name is separated by a space in the SPICE file. The .ends command ends the sub-circuit called OPZ8DIP.

d. Save this new file as any name with an extension of either .lib or .sub, this doesn’t have to be the same name of the sub-circuit, but I typically do that to make it easier.

Create a new symbol to represent the sub-circuit/block.

A. Click the Hierarchy menu at the top and choose either open this sheet’s symbol or create a new symbol.



I prefer the Create a New Symbol option because there is an extra dialogue box asking to automatically generate a drawing. The automatic drawing often doesn’t look very good and the pin order is often completely incorrect. There are some differences in the steps for Hierarchical and Sub-Circuits, so I will use specific directions for Sub-Circuits and call out the differences in the section below the Sub-Circuit section.

Sub-Circuits

Place the pins in the same order as the .lib file with the same names. The symbol drawing mode has shortcuts for drawing certain items.



Pressing “P” on the keyboard brings up the pins and always begins at Netlist Order 1, this is why it is important to remember the order of the pins in the .lib file. Keep adding the pins in the same order laid out similarly to the data sheet mentioned earlier. The justification will depend on the side that the pin is placed on. OUTA through V- will be Left justified while the other pins are Right justified. This is completely custom, so design it whatever way desired. I drew the pins this way to avoid clashing with text and wires.



Draw an outer rectangle that intersects with the middle of the pins by pressing “R” on the keyboard. This is a corner to corner rectangle. The drawing in this grid is very sensitive to mouse movement and provides a crosshair. If the crosshairs are a little off from the grid dots, it will be drawn that way.

Save the symbol as the same name of the circuit schematic (file type is .asy).

This is the same as Save As for the circuit schematic, except the file type is different. Following these steps require all of the steps mentioned in 3. C. above.

a. Press Control + A to bring up the symbol attributes.



b. Edit Prefix value to “X” and Value to the same name given to the sub-circuit saved in step “3. C. d.” above. Make sure symbol type is Cell before clicking “OK”.



c. Save the symbol once more.

Hierarchical Blocks

The main difference between Hierarchical Blocks and Sub-Circuits is Hierarchy is schematic based while the Sub-Circuit is SPICE library netlist based (I found this good explanation here). I will use the same steps listed on this page as this was my resource explaining the difference. The netlist order does not matter in this situation, but the pin names have to match and the circuit has to have the same name as the symbol like the Sub-Circuit. The circuit stays the same and so does the symbol drawing. The changes are adding an instance name to the symbol by clicking Control + W on the keyboard to add InstName (this can be done for the other process too) and the attribute editor is left completely blank and changed to Symbol Type: Block. Remember, Control + A on the keyboard brings up the Attribute editor.





NOTE: Sometimes LTSpice will not be able to find the Hierarchical part if you try to use the part in a circuit that is in a separate folder. Move your schematic for testing into the same folder that your Hierarchy parts are in to fix the issue if this error comes up:



Using the Newly Created Sub-Circuit/Block

Create a new circuit schematic to start with and then click the AND Symbol for a new component. Remember, if the folder created before is already linked then finding the new part is easy.