LTspice – using a simple switch

The LTspice tool is a very powerful tool with an extensive library of elements. It allows you to simulate both simple and complex circuits. But sometimes we need simple elements. And one of such elements is a simple switch. Theoretically, it can be used to simulate transistors, but you need to select the appropriate operating point for them. The built-in “SW” element can be used for the mere simulation of the switching.

Let us assume that we want to simulate a simple circuit which will activate the 9 V power line by means of a PNP transistor and a switch.

To apply voltage to the circuit load, you must short the switch at the base of the transistor. Let’s simulate such a circuit in LTspice.

In order to simulate the switch, select the “sw” element. We connect the voltage source to its input.

But if we try to simulate such a circuit, we get an error. The switch model is missing. So let’s add it:

We also need to connect the model to our symbol. Therefore, we click the right mouse button on the switch symbol and change the value in the Value field from “SW” to the value we have given in the model (in my case it is “MYSWITCH”).

Now let’s describe what parameters our model consists of:

.model MYSWITCH SW (Ron=1 Roff=1MEG Vt=1 Vh=0.5)
  • .model -> the spice directive.
  • MYSWITCH -> our model name
  • SW -> name of the symbol to which the model applies
  • Ron=1 ->switch resistance when it is on.
  • Roff=1MEG ->switch resistance when it is off.
  • Vt=1 ->threshold voltage
  • Vh=0.5 ->hysteresis voltage

The switch trips at (Vt − Vh) and (Vt + Vh)

These are the basic parameters required for the proper operation of the switch. For more detailed information, it is best to go to the help file (F1 key):


So now let’s simulate the circuit.

As you can see in the simulation, our switch works fine.