Unknown Subcircuit after creating a custom model

Thread Starter

richbai90

Joined May 14, 2021
3
I'm trying to model a simple mechanical switch that closes at a set time, remains closed for a set duration, and opens again. I am doing this with a behavioral resistor, but I want it to be clear from the schematic that what I mean is a switch, so I created a new symbol. When I attempt to use that symbol in my schematic I get an unknown subcircuit error. I have double checked that the files are all named the same. I have placed the .asy and .asc under lib/sym/switches

Screen Shot 2021-05-14 at 6.53.40 PM.png
 

Attachments

Papabravo

Joined Feb 24, 2006
16,163
Your problem is that the symbol and the schematic are not correctly linked. I will try to fix it for you. I have linked up two different symbols to identical copies of your schematic and provided a test schematic. It does not produce any interesting results because parameters must be fixed before the simulation runs, there needs to be a load resistor to ground for the switch output to be 0. Once you get the hierarchical schematic method to work we can create a library symbol and a sub circuit. It is good to learn to crawl before you run a marathon. You might need a low value load resistor on the output for the resistor method to work. You might wan to build the load resistor into you sub schematic - or not.
 

Attachments

Last edited:

eetech00

Joined Jun 8, 2013
2,366
I'm trying to model a simple mechanical switch that closes at a set time, remains closed for a set duration, and opens again. I am doing this with a behavioral resistor, but I want it to be clear from the schematic that what I mean is a switch, so I created a new symbol. When I attempt to use that symbol in my schematic I get an unknown subcircuit error. I have double checked that the files are all named the same. I have placed the .asy and .asc under lib/sym/switches

View attachment 238430
The error is due to LTspice not able to find a subcircuit definition for your switch symbol because you have specified "X" in the symbol's prefix attribute. The symbol needs to be defined as a hierarchial symbol to match the schematic MSW.asc . Remove all attributes from the symbol MSW.asy (all attribute fields should be blank). Both files, .asy and .asc, need to have matching filenames.

In addition,
The schematic contains parameters but they have not been defined in the symbols's schematic MSW.asc.
I've added the following spice directive on the symbol's schematic:

.param start=1 duration=1

This defines the parameters "start" and "duration" with default values. You can change the values by right clicking the symbol (after placing on schematic) and specifying the new values.

I'm uploading the files with the required changes for your reference.

1621054592874.png
 

Attachments

Last edited:

Thread Starter

richbai90

Joined May 14, 2021
3
The error is due to LTspice not able to find a subcircuit definition for your switch symbol because you have specified "X" in the symbol's prefix attribute. The symbol needs to be defined as a hierarchial symbol to match the schematic MSW.asc . Remove all attributes from the symbol MSW.asy (all attribute fields should be blank). Both files, .asy and .asc, need to have matching filenames.

In addition,
The schematic contains parameters but they have not been defined in the symbols's schematic MSW.asc.
I've added the following spice directive on the symbol's schematic:

.param start=1 duration=1

This defines the parameters "start" and "duration" with default values. You can change the values by right clicking the symbol (after placing on schematic) and specifying the new values.

I'm uploading the files with the required changes for your reference.

View attachment 238474
Thank you so much for the helpful explanation. So the prefix X, I read that was required for custom symbols. Is that not the case for heirarchacal symbols?
 

Papabravo

Joined Feb 24, 2006
16,163
Thank you so much for the helpful explanation. So the prefix X, I read that was required for custom symbols. Is that not the case for heirarchacal symbols?
That is correct. A hierarchical schematic is one of the easier was to develop a custom symbol. It is easy to accomplish and easy to see what is going on. Once you succeed with this approach you can switch to other methods of connecting symbols and subcircuits. With those methods, it is a bit harder to figure out what is going on. It really helps to get comfortable with hierarchial schematics and the methods for auto-generating and modifying those symbols. Let me know when and/or if you want to try to take that step. Pay attention to Bordodynov's examples, there is much you can learn from his work by observation.
 
Last edited:

eetech00

Joined Jun 8, 2013
2,366
Thank you so much for the helpful explanation. So the prefix X, I read that was required for custom symbols. Is that not the case for heirarchacal symbols?
Not necessarily. A custom symbol can be created, for a diode as an example, and if the diode behaivor is described using only a .model statement, a prefix "X" should not be specified. Instead, the prefix would be "D".

An "X" in the prefix attribute tells LTspice to look for a "subcircuit" defintion. A subcircuit definition describes the component behaivior and is defined within a spice code block that begins with a ".subckt" statement, and ends with ".ends" statement (without the quotes). It also describes the "wiring" between the devices that make up the component. This is standard spice coding.

Heirarchial symbols are proprietary to LTspice. The symbol should'nt contain any attributes and its filename should have a matching schematic file. The schematic file contains an LTspice schematic representing the component behavior. The schematic should also contain "port" symbols that define the pins of the component. A "link" between the symbol and schematic of a hierarchial design is established by using the same filename for both. You can verify a link by right-clicking the symbol to view the file path established to the symbol or schematic.

Hope that helps...
 
Last edited:

Papabravo

Joined Feb 24, 2006
16,163
Once you have established a hierarchical schematic and an associated symbol, it is fairly easy and straight forward to convert that to a symbol which references a sub-circuit. The symbol/sub-circuit method is suited for standard (aka thoroughly debugged) libraries. When and if you want to go there I can show you how it is done.
 
Top