LTSpice what is the difference between a Spiceline and a Spice Directive - Page 1
Forum section: electronics / projects

author: Konkedout
author_rank: Frequent Contributor
timestamp: February 20, 2025, 11:22:21 pm
content: I have spent a few hours trying to get a voltage controlled switch to work in LTSpice.I had found several websites showing how to define the switch operation. But no luck.Finally today I found a complete .asc (with a working voltage controlled switch) in Bordodynov's large collection which I had in a folder on my computer. It turns out that what I had in a "Spiceline" which you see when right clicking on the switch symbol:.model SW1 SW(Ron=.1 Roff=1Meg Vt=3 Vh=0.1)needed instead to be in a "Spice Directive." So I moved it. The sim works now. Why? What is the difference? Cannot find that....Using Version 24.0.12Below I show the dialog box defining the switch. It shows the "Spiceline" field which is blank now. (This works).

author: mtwieg
author_rank: Frequent Contributor
timestamp: February 21, 2025, 01:33:34 pm
content: Good question actually.First understand that the Value, Value2, SpiceLine, and SpiceLine2 fields simply get concatenated onto that component's instantiation in the netlist. So that has to end up being valid syntax.I tried making a circuit with two SW instances, one (S1) via prescribed method with a spice directive containing a model definition, and one (S2) where the model definition is in Value field. I also added in a log buffer component (A1) with some attributes set via the Value field. In the resulting netlist this is what they look like:Code:A1 IN 0 0 0 0 N003 N002 0 BUF Vhigh=5 Vlow=0 Trise=1u Tfall=1uS2 0 N002 IN 0 SW Ron=1 Roff=1Meg Vt=0 Vh=0 Lser=0n Vser=0S1 0 N002 IN 0 MySwitch1.model MySwitch1 SW(Ron=1 Roff=1Meg Vt=0 Vh=0 Lser=0n Vser=0)But when trying to run the sim, it complains saying "Unable to find definition of model "sw"" for both S2. It's a bit disappointing that this doesn't work, since it's using the same syntax as A1 (A1 works fine in this case).I can't find any explanation for why simple attributes work for some components, for example universal opamp models, or logic gate models. One pattern I do observe is that those components use the "SpiceModel" field. Other components like the voltage controlled switch seem to require an actual .model directive be passed in.

author: Konkedout
author_rank: Frequent Contributor
timestamp: February 21, 2025, 05:26:49 pm
content: Quote from: mtwieg on February 21, 2025, 01:33:34 pmThanks a lot for looking into this. I have been circuit designing power for many years, and what I like about hardware is that the rules are largely fixed and governed by physics. But when it comes to software such as this, the rules often appear to be "arbitrary and capricious". Sometimes they just do not seem to make sense. My final clue to fix this problem is that my color scheme has different text colors for Spiceline versus Spice Directives. The Bordodynov .asc which ran had the switch definition appearing in a different color from what I had. AHA!!! :-(

author: Zero999
author_rank: Super Contributor
timestamp: February 23, 2025, 07:09:17 pm
content: Quote from: mtwieg on February 21, 2025, 01:33:34 pmWhat's interesting is, if the symbol uses a pre-defined model, then it works differently. Value is just a label and Value2 is the model.There's an interesting hack which demonstrates this.I'll use a behavioural rail-to-rail comparator made with voltage controlled switches, for this example.Compator R2R source.asc(0.64 kB - downloaded 28 times.)Create a subcircuit from the comparator model schematic I posted above. Open the file and click View SPICE netlist. Select the following text and copy it:S1 out +V +in -in SWCS2 out -V -in +in SWC.model SWC SW(Ron=1 Roff=1T Vt=0 Vh=100u)Create a new file.Paste the above into a SPICE directive and add .subckt model +in -in +V -V to the first line and append .ends..subckt cmpR2R +in -in +V -VS1 out +V +in -in SWCS2 out -V -in +in SWC.model SWC SW(Ron=1 Roff=1T Vt=0 Vh=100u).endsDraw the circuit, using one of the comparator symbols which come pre-installed with LTSpice. In this case I've used the LT1720. Save the file.Open the .asc file in a text editor. Find the following lines:SYMBOL Comparators\\LT1720SYMATTR InstName U1Add the following:SYMATTR Value comparatorSYMATTR Value2 cmpR2RSave the file.This will change the label of the component to comparator and the model to cmpR2R.Comparator R2R test sym.asc(1.52 kB - downloaded 19 times.)This can be useful if you want to have a component with a different label to the SPICE model.I've written a bit more about this hack here:https://www.eevblog.com/forum/projects/this-ltspice-model-for-tl431-is-bonkers/msg5760423/#msg5760423

author: Konkedout
author_rank: Frequent Contributor
timestamp: February 24, 2025, 05:48:35 am
content: Thanks a lot. I need to chew on it for a little while and follow your instructions. I have downloaded your behavioral comparator model and it is laughably simple.IMO, for so much software, I feel that HELP needs to be written by the people who recently learned it, rather that by the people who know it so well that everything is obvious. The problem is that F1 help is seldom much help.For example to me it seems obvious that if SPICELINE is the name of a field when I define a model, then SPICELINE needs to be a searchable term in HELP. But no, it is not.Thanks again. I think I will learn something from this exercise...BTW I thought that Word inserted a lot of non-printing characters such as formatting?

author: mtwieg
author_rank: Frequent Contributor
timestamp: February 24, 2025, 01:16:46 pm
content: Quote from: Konkedout on February 24, 2025, 05:48:35 amI tried searching for SPICELINE in help and the first (and only result) was a page with the explanation:QuoteThat's all it really is. Those attributes are all just concatenated onto the end of the component declaration. Doesn't matter which one(s) you use, or in what order. I'm guessing these were added because the attribute editor window doesn't support text wrapping, so this is a hack to allow adding lots of stuff in a way that is somewhat readable.

author: tggzzz
author_rank: Super Contributor
timestamp: February 24, 2025, 02:00:44 pm
content: Quote from: mtwieg on February 24, 2025, 01:16:46 pmWhat is this "window" of which you speak? Is it one of the holes in the deck of punched cards containing the Spice directives? Or maybe paper tape.I'll let the experts argue as to whether tape or cards are better(Emacs vs vi(le) is a latecomer)

author: mtwieg
author_rank: Frequent Contributor
timestamp: February 24, 2025, 03:02:12 pm
content: Quote from: tggzzz on February 24, 2025, 02:00:44 pmSee attached

author: Zero999
author_rank: Super Contributor
timestamp: February 24, 2025, 10:14:40 pm
content: Quote from: Konkedout on February 24, 2025, 05:48:35 amI've not tried MS Word, only LibraOffice, I presume any modern word processor will notice the format is plain text and no use any non-printing characters, other than space and linefeed of course.How familiar are you with SPICE? Bear in mind that the SPICE engine doesn't care about schematics. LTSpice's schematic editor editor converts your schematic into a netlist which is passed to the SPICE engine and simulated. Clicking on View SPICE net list or pressing ctrl+V then N, will show you the netlist. I've found the SPICE 3f3 user manual handy.http://www.gianlucafiori.org/appunti/Spice_3f3_Users_Manual.pdfEDIT: Here's a version of the same manual with links and indexing in the PDF to aid navigation:http://www.spiceopus.si/download/spice3_manual.pdfQuote from: mtwieg on February 24, 2025, 01:16:46 pmInterestingly some symbols don't show a list of parameters, rather than that window.Compare opamp2 (used for my behavioural comparator) and UniversalOpAmp used in the attached .asc file. I've added the attribute Rout so the output resistance of the comparator can be changed, by adding said attribute.

author: Geoff-AU
author_rank: Frequent Contributor
timestamp: February 24, 2025, 10:52:04 pm
content: Quote from: Konkedout on February 24, 2025, 05:48:35 amLTSpice's help is a bit ordinary. I wish they would give examples to make syntax clearer. ltwiki.org is often a good bet to try.

author: Someone
author_rank: Super Contributor
timestamp: February 24, 2025, 11:19:56 pm
content: Quote from: Geoff-AU on February 24, 2025, 10:52:04 pmLTSpice is a bit like Python, the assumption seems to be the community will produce examples and tutorials and that will be enough. But those "tutorials" have several problems, in general they:show a solution with steps but don't explain the underlying methods/techniques, "type this in and it works" rather than this function/line/item produces the following effectsare for some other version of the tool that has broken compatibility (this thread)assume you already know thelanguageof the software (this thread)That last one is often really hard, so glad to have this well indexed thread to improve the situation!