Making Switches in LTSpice : Circuit Configurations

I advise anyone to read the following post/posts beforehand: Switch Circuits and Functions for context on the types of switches and how they function. If anyone does not have experience with the program, please refer to my first post and/or my sub-circuit post.

There are four main types of mechanical switch types: SPST, SPDT, DPDT, and DPST. Two of these switch types have different default forms: The SPST can either be SPST-NC or SPST-NO where NC is normally closed and NO is normally open. The DPST switches also have the same type of forms (DPST-NO; DPST-NC). SPDT and DPDT do not typically call this out because of how they are designed. LTSpice has the capability of modeling these switches using something called a “Voltage Controlled Switch”. This one of the software’s implementations of a basic switch because one cannot physically “press” a switch in this software. Click the component symbol and search for “switch”.
voltSw
This device is almost equivalent to a very simple relay where a voltage source controls whether the switch is open or closed. These built-in switches require a spice command to operate. First, I recommend naming the switch by right-clicking the text “SW” and giving it a unique name. I have a set of preferences when setting up switches for experimenting that work well. Press the “S” key and type the following:
“.model yourModelName SW(Roff=1G Ron=25u Vt=0.1 Vh=0.1)” These values represent the resistance seen by the circuit when off, when on, trigger voltage for activating the switch, and some hysteresis on the trigger voltage (basically tolerance on that voltage). The default values can be used if one types “.model yourModelName SW()” in the SPICE command box instead. The default values can be found if Help is clicked (or F1) and search for “switch”.
helpSw
Double click Voltage Controlled Switch to get some information on using the part as well as the default values.

SPST-NC

Let’s start with the normally closed version of the SPST switch (default is comparable to a normally open version). I wanted to make the switches consistent with how the default SPST switch is set up, here is the circuit:


The item connected to the + pin is the logic inverter that comes pre-installed, click the components symbol and search for “inv”. The default logic gates in LTSpice are set to 1V instead of 5 or 3.3, I set up the inverters to 5V by right-clicking the part:
invertChangeVal
The “Value” will be blank the first time, I set the value to td=10n and Vhigh=5. Td is the rise time for the logic inverter while Vhigh is the voltage at which it will trigger/output. 5V is common for many integrated circuits. This post will have a few inverters in the design of the switches (use the same settings) and will all have the base switch: use “.model yourModelName SW(Roff=1G Ron=25u Vt=0.1 Vh=0.1)” for each switch model when I have them in a circuit. Click “Hierarchy” and Create a New Symbol. Make something similar to this:

For the block method, remember that the pin names need to be the same, but do not require netlist order. Pressing “L” will draw lines, pressing “C” will draw circles, and pressing “P” will draw pins. Remember that text placement for pins kind of behaves opposite in direction (left appears to the right and right appears to the left, this is because it assumes one is making an IC chip). Finally, remember to name the schematic and the symbol the same. The schematic will have a “.asc” extension while a symbol will have a “.asy” extension. The sub-circuit will not work if they do not have the same name and are not in the same working directory.

SPDT

The next model with a single-pole is an SPDT type switch. This type of switch consists of one connection point on one side and two separate connection points on the other. This usually provides a way to control two separate circuits by toggling between the two. Here is the circuit diagram:


Save the schematic and name it. Then, make the associated symbol:

To get different line styles like the dotted line, click the “Draw” menu next to “Hierarchy” and click “Line Style”. There are a few options to pick in the dropdown.
lineStyle
Remember to change this back if solid lines or other styles are wanted. It will keep the last style used until changed manually. I used a dotted line to represent the alternate switch position since there is no animation between states. The schematic is set up so that the default position has a connection between 1 and 2 when no source voltage is present on “+”.

DPDT

The DPDT switch contains two SPDT switches that are both activated at the same time. I used a shortcut to make this schematic:


You can use your own sub-circuits in a sub-circuit design due to the hierarchy design. The diagram is a little confusing because there are multiple references to “1”, “2”, “3” and “+”, “-”. When we use the SPDT model we made earlier, LTSpice only makes a reference of what pins 1, 2, 3, +, and - connect to in the sub-circuit of that component. Placing connection points with the same name in the new schematic makes new references that only apply to anything being connected in that schematic. Here is the symbol I made:

I used regular dashes to represent the alternate paths for the switch while a dash with two dots represents the mechanical connection between the two SPDT switches.

DPST-NO

DPST-NO switches are simply SPST-NO switches that are mechanically connected to turn on and off at the same time. So the schematic equivalent would be to connect the plus ports of two SPST switches.


Here is the symbol:

DPST-NC

Finally, a DPST-NC is just the inverse of a DPST-NO. I used the DPST schematic in this new schematic and added an inverter on the “+” port.


Here is the symbol:

1 Like

Much appreciated. Amazing that LTspice (XVII, now) doesn’t have built-in behavioral models for these fundamental switching functions - good old Electronics Workbench/Multisim provided those readily, and you could observe their effects interactively in real time. Could you help speed things up and provide your files for the above examples? Thanks in advance.

Thank you for the feedback @mikehoopes ! Here is a zipped file of all the switch model drawings and schematics: SwitchesLTSP.zip (3.7 KB); please know these are not library (sub-circuit) versions, but rather hierarchy parts so they must be installed in a folder that your LTSpice XVII has access to (the same thing goes for anyone that downloads it), do not have other circuits in the folder with the same names.

I found your post from a year ago. It is very helpful to me now.

Thanks!

1 Like

Am I mistaken, or should this line read “.model yourModelName SW(Roff=1G Ron=25u Vt=0.1 Vh=0.1)”,
rather than “.model SW yourModelName (Roff=1G Ron=25u Vt=0.1 Vh=0.1)” ?
The line you presented causes a run time error, but my suggested one does not.

@CaptainSimion Good catch! I’ll fix the instances in my post that say the wrong thing, the “SW” should be the model name being edited on the diagram, and “SW()” part makes sure LTSpice is pointing to the base SW model built-in.

Thanks for fixing this. I’m just getting restarted after a long absence and am trying to make my models a bit more sophisticated.

Still valid and appreciated - Thanks!

1 Like