I'm currently new to using LTspice as a circuit simulation software.

Right now I'm trying to check if the IC (BD6221F-E2) that I included in the program is working. The process of making this IC is through the use of subckt. (I download the .lib file from the manufacturer website)

One of the steps that I need to check is the logic output of the IC. I'm planning to use SPDT switches to make the output go alternate (e.g. forward and reverse) and see their waveform outputs.

The problem is that the only available switch is the voltage controlled switch.

How can I make my own SPDT switch ?

  • 1
    \$\begingroup\$ An SPDT switch is just two SPST switches in series. So you could put your two voltage controlled switches in series and use a voltage controlled voltage source to invert the control signal to one of them. \$\endgroup\$ Commented May 4, 2018 at 6:07
  • 1
    \$\begingroup\$ @LosFrijoles Make that an answer. Images might help a bit more, too. \$\endgroup\$ Commented May 4, 2018 at 6:15
  • \$\begingroup\$ There are lots of SPDT switch designs , what is the exact problem? Bridge voltage? bridge current? bridge RdsOn? Logic level control? Protection? transition frequency? power dissipation? Shoot thru? Dead time control? Any SPDT switch needs these specifications before you can start any selection or design! Checking logic polarity is pretty simple with a comparator or Schmitt trigger for level. \$\endgroup\$ Commented May 4, 2018 at 6:46
  • \$\begingroup\$ @TonyStewartEEsince1975 I think the OP wants to run the simulation in the time domain and watch the behavior of the IC "as if" a switch were done in the middle of operation. An idealized switch is probably adequate, since this is just a control input for the IC that decides which way the h-bridge goes. The switch model isn't critical. It's the rest of the circuit, I suspect. \$\endgroup\$
    – jonk
    Commented May 4, 2018 at 6:48
  • \$\begingroup\$ All switches are analog. Even logic, so I would think the analog parameters need better specs before trying to make a switch,. \$\endgroup\$ Commented May 4, 2018 at 6:51

1 Answer 1


Basic Overview

It's very simple to construct your own parts in LTspice. The existing voltage controlled switch is an excellent example. If you just grab the "sw" part and drop it onto a schematic, you can CTRL Right-click the symbol and get a dialog box. In the upper-left corner you should see a button called "Open Symbol." Use it. This will call up a display that looks like the left side below. Use the "copy" feature and select the area you see surrounded by the black rectangle showing on the right side:

enter image description here enter image description here

Now, you have a copy. Paste it into the image somewhere, as shown on the left side below. Now use the "move" feature and move things around until it looks like the image on the right side:

enter image description here enter image description here

You are very close. Now, use the Edit/Attributes/Edit Attributes menu to get the dialog box showing on the left. Change the \$\text{<Prefix>}\$ attribute from S to X. (You need that because you will make a SUBCKT model. And SUBCKT models must be marked as X, not S.) Also change the \$\text{<Value>}\$ attribute from "SW" to "SPDT". Then hit the OK button. The result should look like what's on the right side, before you hit the OK button.

enter image description here enter image description here

You now have to set up all the netlist nodes, properly. To do that, you right-click on each of the blue squares (should see five of these.) Change them one at a time, so that the results look like the following:

enter image description here

Please note the ordering of each netlist node number, as shown above. Also note the labeling, too. (The names aren't that important. But they should be distinct.) Name the labels differently, if you like.

Now do a Save As... and save it under a new name. For example, as "SPDT.ASY" for example. But that's your call.

Now you have a nice SPDT symbol. You don't have a Spice model yet. But you do have the symbol.

Now, start a new schematic and hit F2 to get the list of parts. You should now see SPDT showing in the list. Grab it and put it down on the schematic. Now hit the "S" key to call up a Spice dialog box where you can enter in a model, now. Put in the following text into that box:

.model MYSW1 SW(Ron=.01 Roff=1000Meg Vh=.25 Vt=.5)
.model MYSW2 SW(Ron=.01 Roff=1000Meg Vh=.25 Vt=-.5)

Paste that into your schematic anywhere you want.

Here is what I did:

enter image description here

I think you can see that it works. Take a careful look at the switch models I used in the SUBCKT. Make sure you understand what I did there.

You will be able to make anything you like now. It's easy, really.

Later, when you get better at this kind of thing, you can save those SUBCKT models, too. Just stick them into the .\lib\sub directory and go back to the symbol editing and modify the \$\text{<ModelFile>}\$ attribute using the Edit/Attribute/Edit Attributes menu option and enter in the file name where you've saved this text. That way, LTspice will automatically find the model in the disk file and you don't need to place it on the schematic, anymore. In fact, if you place LOTS of various SUBCKT models in that file (you are allowed to add as many as you want), then you can set up different model behaviors and select from any of them when you place the symbol down. (LTspice will notice that there is more than one model in the file. So you can change SPDT to something else, like SPDT1, and get a different behavior.)


The above discussion gets the job done for one-off circumstances. You've created a symbol that is more readable on a schematic and contains the associated Spice subcircuit (.SUBCKT) behavior. However, the .SUBCKT behavior is pasted right onto the schematic, itself. So, even though you may have saved the symbol for later use, the .SUBCKT behavior isn't yet available for general use on other schematics. You'd have to copy and paste the .SUBCKT text into each and every schematic. For useful symbols you create, where you are likely to use them elsewhere, it's a lot of unnecessary pain that can be avoided.

If you look back above, you can see the \$\text{<ModelFile>}\$ attribute in the "Symbol Attribute Editor" (which was above left blank.) If, instead, you copy and paste the .SUBCKT text into Notepad or Notepad++ (or whatever editor you like to use for things like this) and then save it into a file, then you can fill out this \$\text{<ModelFile>}\$ attribute with the saved filename while using the "Symbol Attribute Editor." Adding an entry here lets LTspice know where to look for the Spice behavior when it loads and uses this symbol you've created. That permits the symbol to be used in new schematics without having to paste the .SUBCKT into the schematic every time you use it.

A full pathname in the \$\text{<ModelFile>}\$ attribute is fine. But, often, you may wish that all this is saved in a relative directory or else in the LTspice installation directories. If you save the .ASY symbol file in LTspice's .\lib\sym directory, then your new part symbol will appear in LTspice's "Select Component Symbol" dialog box and that makes it very easy to get and use. But it can also clutter up the dialog, if you add too many. You can create subdirectory folders, if you like, in order to help better organize things and LTspice will work fine with that, as well. Similarly, the .MOD or .LIB files can be saved in LTspice's .\lib\sym directory and this allows LTspice to automatically find the referenced .SUBCKT model file you saved, if you save the file there and also use only the .MOD or .LIB filename without the full pathname portion in the \$\text{<ModelFile>}\$ attribute. (Just use the simple name, instead.) And, of course, you can similarly use subdirectory folders, there, too. But then your \$\text{<ModelFile>}\$ attribute also needs to include that subdirectory reference.

LTspice also provides a Tools/Control Panel menu option that pops a dialog. There, find the tab called "Sym. & Lib. Search Paths" to see two boxes where you can enter additional directories that LTspice will use automatically when searching for a symbols (.ASY files) and models (.MOD or .LIB files.) You then don't have to store your .ASY, .MOD, and .LIB files underneath LTspice's installation directory, but can instead keep your own separate set of folders and subfolders isolated away from LTspice.

LTspice keeps it's own special files in .\lib\cmp: standard.bjt for BJT models, standard.dio for DIODE models, standard.jft for JFETs, and standard.mos for FETs. You can feel free to edit these files and append your own models into these files. When LTspice re-installs (updates) itself, it is smart enough to realize that you've inserted additional models and, during installation, it will read them up and re-merge them back into any newly installed versions. This keeps your added models intact. Good thing. And it now expands the menus for each of these parts to allow easy access to a larger set of models.

Even More Advanced

It's possible to make your own symbol that represents a host of part numbers and where LTspice will automatically provide a drop-down menu allowing you to select among the models you supplied. When you create a symbol in LTspice and you set its \$\text{<Prefix>}\$ attribute to "X" (.SUBCKT), LTspice automatically supplies a Spice card for that symbol. The Spice card will include the prefix as the first letter of the Spice card, followed immediately by the modified attribute, followed by a space and the list of pin nodes, and then a space followed by whatever remaining attributes it sees in the symbol. These include the following attributes: \$\text{<SpiceModel>}\$, \$\text{<Value>}\$, \$\text{<Value2>}\$, \$\text{<SpiceLine>}\$, \$\text{<SpiceLine2>}\$.

A .SUBCKT Spice card includes the following fields:

Xxxxxxxx P1 P2 ... Pn A1 A2 ... Am

Where the 'xxxxxxx' part is the modified \$\text{<InstName>}\$ (for X devices, usually starting with the letter U), and P1...Pn are space-separated node names associated with the .ASY pins, listed by \$\text{<PINATTR SpiceOrder>}\$ (more on that, below.) The remaining A1..Am are space-separated values taken from the symbol on the schematic, itself, and correspond to whatever is found in the \$\text{<SpiceModel>}\$, \$\text{<Value>}\$, \$\text{<Value2>}\$, \$\text{<SpiceLine>}\$, and \$\text{<SpiceLine2>}\$ attributes, respectively.

Note that when drawing out a symbol in LTspice, you are allowed to place these above attributes onto the image. If you add them to the .ASY, then they will appear in the location you've set for them and be displayed. If you don't include them, then they may still be set to various values but those values won't be displayed on the schematic. So you are always able to set various attribute values, after placing a symbol into your schematic. But you may not always be able to see those values on the schematic, unless you explicitly set up the .ASY to display them.

For example, I wanted to design a PUJT symbol. Here's my .ASY file:

Version 4
SymbolType CELL
LINE Normal 0 44 32 44
LINE Normal 0 20 32 20
LINE Normal 32 20 16 44
LINE Normal 0 20 16 44
LINE Normal 16 0 16 20
LINE Normal 16 44 16 64
LINE Normal -16 0 0 0
LINE Normal 0 0 8 20
WINDOW 0 44 11 Left 2
WINDOW 38 44 50 Left 2
SYMATTR SpiceModel 2N6028
SYMATTR Description Programmable UJT
PIN 16 0 NONE 0
PINATTR SpiceOrder 1
PIN -16 0 NONE 0
PINATTR SpiceOrder 2
PIN 16 64 NONE 0
PINATTR SpiceOrder 3

The first few lines are about drawing out the symbol picture. That's just vector graphics stuff. But take note of the \$\text{<PIN>}\$ and associated \$\text{<PINATTR>}\$ lines; and also the \$\text{<SYMATTR>}\$ lines. These are key to understanding what a symbol is and how LTspice applies it when generating the Spice deck.

There are three pins to the device and you can easily see the \$\text{<PIN>}\$ line, followed by one or more \$\text{<PINATTR>}\$ lines. The most important \$\text{<PINATTR>}\$ line is \$\text{<PINATTR SpiceOrder>}\$. This determines the position on the Spice card associated with that pin. (The P1...Pn arrangement.) The fact that this symbol requires three pins means that when generating the Spice card for this symbol, LTspice will reserve three positions after the the first Xxxxxx part of the card for these pin nodes. After that, the various values in A1..Am are added.

In the above .ASY, this means that the card will look like:

XU1 A G K <SpiceModel> <Value> <Value2> <SpiceLine> <SpiceLine2>

Note that the \$\text{<ModelFile>}\$ attribute of the .ASY is only there to specify to LTspice how to find the file containing appropriate .SUBCKT or .MODEL descriptions. It's not added to the Spice deck card illustrated above.

Now here is something important. If you place your default device type (the .SUBCKT you'd like to default to) into the \$\text{<SpiceModel>}\$ attribute and if you specify a \$\text{<ModelFile>}\$ attribute that references a file containing many different models that are appropriate for your .ASY (in my case, three pins) then you can right-click the symbol on your schematic and then double-click the \$\text{<SpiceModel>}\$ attribute and it will automatically present you with a list of .SUBCKT models contained in your \$\text{<ModelFile>}\$ attribute's file. Even if there are dozens of them!

This is really nice.

So, for example, here's a picture after I've right-clicked and then double-clicked my PUJT symbol:

enter image description here

Note that both of my models show up for easy selection.

Related Posts

  • \$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. \$\endgroup\$
    – Dave Tweed
    Commented May 5, 2018 at 0:01
  • 1
    \$\begingroup\$ @jonk, thanks for the detailed explanation. If you don't mind, could you please explain how you chose Vh and Vt for the two .model commands? The pulsed signal is always above -0.5, so shouldn't the second model always be above threshold? And why are you using hysteresis? Lastly, how does LTspice know what MYSW1 and MYSW2 are referring to? \$\endgroup\$ Commented Jun 14, 2018 at 1:10
  • \$\begingroup\$ @VivekSubramanian I chose Vh and Vt at the time by pulling up the LTspice help file and reading it. I don't recall, today, exactly what made me make the choices I selected here. I'd have to go back and re-read the help to know that, but it made sense to me at the time. Have you looked over it, yet? And the models are specified in the S1 and S2 lines of the SUBCKT. So spice looks for them, given that. \$\endgroup\$
    – jonk
    Commented Jun 14, 2018 at 1:30
  • \$\begingroup\$ EE.SE should bring up your results first when searching for anything. I may be smiling, but I'm not joking. :-) \$\endgroup\$ Commented May 14, 2020 at 7:39
  • \$\begingroup\$ @aconcernedcitizen I can only aspire towards, but never be worthy of such a kind comment. But thanks, anyway. ;) \$\endgroup\$
    – jonk
    Commented May 14, 2020 at 22:13

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.