4
\$\begingroup\$

LTSpice Hierachy block can not be found if it is not in current working directory.

I am using this tutorial to create sub-circuits in LTSpice:

http://www.audio-perfection.com/spice-ltspice/hierarchical-blocks-in-ltspice.html

Everything is fine except that the sub-circuit that I make can not be used globally. Every time that I have a new design I must copy my sub-circuits to the directory that my top-level design resides.

I even moved my sub-circuit (both .asc and .asy files) into a folder under E:\Program Files (x86)\LTC\LTspiceIV\lib\sym but LTSpice can not find it. I suspect there must be a directive such that includes a folder into the global search path (or top-level search path) but I can't locate the option.

I appreciate if you tell me how to make LTSpice sub-circuits available globally?


Update:

This is my inverter_035_1.asc:

Version 4
SHEET 1 880 680
WIRE 208 -96 208 -160
WIRE 272 -96 208 -96
WIRE 208 -80 208 -96
WIRE 160 -32 80 -32
WIRE 272 -32 272 -96
WIRE 272 -32 208 -32
WIRE 80 32 80 -32
WIRE 80 32 -16 32
WIRE 208 32 208 16
WIRE 448 32 208 32
WIRE 208 48 208 32
WIRE 80 96 80 32
WIRE 160 96 80 96
WIRE 400 96 208 96
WIRE 208 176 208 144
WIRE 400 176 400 96
WIRE 400 176 208 176
WIRE 208 240 208 176
FLAG 448 32 out
IOPIN 448 32 Out
FLAG 208 -160 VDD
IOPIN 208 -160 BiDir
FLAG 208 240 GND
IOPIN 208 240 BiDir
FLAG -16 32 in
IOPIN -16 32 In
SYMBOL nmos_035 160 48 R0
SYMATTR InstName M1
SYMATTR Prefix X
SYMATTR Value2 W=1u L=0.35u
SYMATTR SpiceLine ""
SYMBOL pmos_035 160 -80 R0
SYMATTR InstName M2
SYMATTR Value2 W=3u L=0.35u
SYMATTR Prefix X
SYMATTR SpiceLine ""

And this is my inverter_035_1.asy:

Version 4
SymbolType BLOCK
LINE Normal -16 32 -16 -32
LINE Normal 33 0 -16 32
LINE Normal -16 -32 33 0
LINE Normal 64 0 44 0
LINE Normal 0 -48 0 -21
LINE Normal 0 48 0 22
LINE Normal -16 0 -48 0
CIRCLE Normal 44 5 33 -5
PIN -48 0 NONE 8
PINATTR PinName in
PINATTR SpiceOrder 1
PIN 64 0 NONE 8
PINATTR PinName out
PINATTR SpiceOrder 2
PIN 0 -48 NONE 8
PINATTR PinName VDD
PINATTR SpiceOrder 3
PIN 0 48 NONE 8
PINATTR PinName GND
PINATTR SpiceOrder 4

Both files reside in a sub-folder under E:\Program Files (x86)\LTC\LTspiceIV\lib\sym\

\$\endgroup\$
5
  • 1
    \$\begingroup\$ If you don't get a good answer here, try this \$\endgroup\$
    – EM Fields
    Commented Jul 17, 2016 at 8:38
  • \$\begingroup\$ wow they have a yahoo group?! Ok I will, thanks for letting me know. \$\endgroup\$ Commented Jul 17, 2016 at 10:05
  • 1
    \$\begingroup\$ If you post the asc file, I may be able to convert it for you. \$\endgroup\$ Commented Jul 17, 2016 at 12:00
  • \$\begingroup\$ I posted both files. \$\endgroup\$ Commented Jul 17, 2016 at 12:24
  • \$\begingroup\$ This will need to wait until the morning now - I will get to it then. \$\endgroup\$ Commented Jul 17, 2016 at 14:16

3 Answers 3

4
\$\begingroup\$

First, make yourself a user directory under 'sym':

New directory

Before adding anything (I already did, but we will get to that).

Start LTSpice, start a new schematic and then select add component:

I get this view with my parts directory shown:

My directory now viewable in LTSpice

Close LTSpice for now.

For an opamp (which is what I did here), copy the OPAMP2.sym file from the sym\Opamps directory to your directory and rename it with the name you want (which is what I did in the first picture).

Now get the subcircuit file and save it in the lib\sub directory:

Model added to sub directory

Now open the asy file in your user directory in a text editor:

Here is part of the file:

SYMATTR Value ADA4666
SYMATTR Prefix X
SYMATTR Description Micropower Rail to Rail amplifier
SYMATTR SpiceModel ADA4666.cir

If there are no SYMATTR lines, then add them:

Version 4
SymbolType CELL
LINE Normal -32 32 32 64
LINE Normal -32 96 32 64
LINE Normal -32 32 -32 96
LINE Normal -28 48 -20 48
LINE Normal -28 80 -20 80
LINE Normal -24 84 -24 76
LINE Normal 0 32 0 48
LINE Normal 0 96 0 80
LINE Normal 4 44 12 44
LINE Normal 8 40 8 48
LINE Normal 4 84 12 84
WINDOW 0 16 32 Left 2
WINDOW 3 16 96 Left 2
SYMATTR Value ADA4666
SYMATTR Prefix X
SYMATTR Description Micropower Rail to Rail amplifier
SYMATTR SpiceModel ADA4666.cir
PIN -32 80 NONE 0
PINATTR PinName In+
PINATTR SpiceOrder 1
PIN -32 48 NONE 0
PINATTR PinName In-
PINATTR SpiceOrder 2
PIN 0 32 NONE 0
PINATTR PinName V+
PINATTR SpiceOrder 3
PIN 0 96 NONE 0
PINATTR PinName V-
PINATTR SpiceOrder 4
PIN 32 64 NONE 0
PINATTR PinName OUT
PINATTR SpiceOrder 5

Add any SYMATTR lines immediately before the PIN and PINATTR statements.

I changed the SYMATTR values to give a correct display name (Value), the Description field for what LTSpice shows in the selector window and the SpiceModel to the model I added in the sub folder.

Here it is:

New amplifier with description

I then place it:

ADA4666 placed

Right click on the part and you get this:

ADA4666 attributes

This can now be used in any schematic.

I went through this when I added the Wurth magnetics library a while back.

The keys are:

  1. Put the subcircuit in the sub folder

  2. Put the symbol file in a directory of your choosing

  3. Make sure the SYMMATR statements point at the subcircuit properly, and edit the name and description to get an accurate representation of what it is.

Note that the subcircuit must be complete in its own right.

In your case, you are trying to create a hierarchical block; there is an excellent description at the link.

As links die, here is the procedure:

Make the schematic you desire to use as a hierarchical block and save it with a name

Now label all nets that must have external visibility and save again.

Create a new symbol. The pins on this symbol must have the same name as the labels you attached.

Save this symbol as (the names must be the same for the schematic and symbol).

If your schematic has external models or subcircuits, use the .include directive using full path names in the schematic before saving (so they do not have to be in a working directory).

You should now be able to instantiate your hierarchical block.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks for the step by step explanation. I don't have a .cir file. What I have is a .asc file (just a schematic created in LTSpice itself) which describes the circuit and a .asy file. When I open my .asy file I can't locate any line starting with "SYMATTR " \$\endgroup\$ Commented Jul 17, 2016 at 11:50
  • \$\begingroup\$ If there are no SYMATTR lines, then add them. I have expanded the listing above to show where they are. \$\endgroup\$ Commented Jul 17, 2016 at 11:55
1
\$\begingroup\$

Alright, I found a workaround by myself that works!

1) Design your circuit in LTSpice and name all nets that will be connect to outside world. Save the circuit in .asc format in a subfolder under E:\Program Files (x86)\LTC\LTspiceIV\lib\sym. Like this:

Simple inverter

2) Before leaving the schematic editor go to View - SPICE Netlist. Copy and paste the netlist into a lib file, let's say 'mysubcir.lib'. Add a line above the pasted netlist to define a subcircuit like this:

mysubcir.lib:

.subckt inverter_035_1 in out VDD GND   * Add this line, inverter_035_1 must match the .asy filename 
* E:\Program Files (x86)\LTC\LTspiceIV\lib\sym\5827\inverter_035_1.asc
XM1 out in 0 0 NM W=1u L=0.35u
XM2 out in VDD VDD PM W=3u L=0.35u
.end inverter_035_1    * you need to add this also

3) Go to File - New Symbol and design your symbol. Put the pins with same net names in your schematic, in this case we have four pins: "in out VGD GND". And then save the .asy file in the same folder that you saved .asc file. Like this:

inverter symbol

Now your new subcircuit is available globally. You only need to add ".lib mysubcir.lib" to your top schematic.

The only problem with this approach is that whenever you update the .asc file then you have to export the netlist and copy/paste it again into the .lib file. Any other solution that avoids this double rework is very welcome.

\$\endgroup\$
0
\$\begingroup\$

You need to add the address of the lib folder relative to LTspice's sub folder into the symbol file: Change SymbolType BLOCK to SymbolType CELL Before the first PIN assignment, place the following symbol attributes o SYMATTR Prefix X o SYMATTR SpiceModel o SYMATTR Description o SYMATTR ModelFile <model folder address relative to LTspice’s sub-folder Folder address example: MySubFolder\VLimiter.lib

  • If parameters must be passed to the model, the following line must be added o SYMATTR SpiceLine Vlim=2.8 Rlim=6.67 Iunit=248u
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.