How to Add a Voltage-Controlled Switch in LTspice

Abstract

This article details the steps required to add a voltage-controlled switch to an LTspice® schematic. Examples are included to highlight the usage of a voltage-controlled switch in transient simulations.

Introduction

A voltage-controlled switch is one of the basic circuit elements in LTspice. It’s useful as a simple way to add open-/short-circuit behavior in a circuit that can be changed in the middle of a simulation. While a designer may need to eventually incorporate a more accurate FET or switch model as the schematic is refined, a simpler switch element can be used to get started.

Required Steps Before Getting Started

This article assumes a basic understanding of how to use LTspice. To learn the basics of using LTspice, refer to the Getting Started Guide and the LTspice Basics video series.

Step 1: Place a Switch Symbol

Open the schematic you want to add a switch to. Or select File → New Schematic to create a new schematic.

Select Edit → Component (or press P), and select sw from the component library. The orientation of the switch symbol can be fine-tuned by using the Rotate (CTRL+R) and Mirror (CTRL+E) commands. Click Place and click on the schematic to place the new switch. See Figure 1.

Figure 1. Selecting a switch from the Component dialog.

Step 2: Add a Model Statement

Select Edit → SPICE directive (or press .), and add a model directive for the switch. Start with this example:

.model MYSW SW()

where MYSW is the name assigned to this model directive and SW() indicates that this is a model for a switch, using the default parameter values (Figure 2). Click OK, and then click on the schematic to place the .model directive. See the LTspice help topic for the switch model directive by selecting Help → LTspice Help, and searching for the Voltage Controlled Switch help on voltage controlled switches as the associated SW() model directive.

Figure 2. Adding a .model directive to the schematic.

Step 3: Point the New Switch to the Corresponding Model Statement

Once a .model directive is added to the schematic, ensure that the new switch symbol is linked to the model correctly by right clicking on the switch value, which defaulted to SW when the switch was placed. Change SW to MYSW to properly link this switch to your newly created MYSW model. See Figure 3.

Figure 3. Changing the value of the switch component to match name in .model directive.

Step 4: Add a Control Voltage Source

Add a voltage source to control the on/off state of the new switch. To add a voltage source, select Edit → Component, select a voltage component from the dialog, and click Place (or, press V). Click on the schematic to place the voltage source.

Right click on the V value, and enter the PULSE command below to create a triangle wave (also illustrated in Figure 4).

PULSE(-1 1 0 .5m .5m 0 1m)

Figure 4. Adding a control voltage to the switch control pins.

The default threshold parameter for a voltage-controlled switch is 0 V—so this example triangle wave will turn this default switch model on and off with a 50% duty cycle.

A Simple Example

Experiment with the simple example provided here, or by selecting File → Open Examples → Educational → Vswitch.asc. See Figure 5.

Figure 5. Vswitch.asc example schematic.

For the purposes of simplifying the plot results and showing the impact of changing Vh and Vt values, change the V2 voltage to 1 by right clicking on the 3.3 value and changing the value to 1.

Run the simulation by selecting Simulate → Run. See Figure 6.

Figure 6. Simulation results after changing V2 to 1 V.

Setting Behavior of Control Hysteresis

Behavior with Vh = 0

Make some changes to the Vswitch.asc example to explore the behavior of this switch as we change Vh.

Right click on the .model directive, change the Vh value to Vh = 0, and then rerun the simulation. Notice that the switch behaves in an ideal manner, transitioning between fully on and fully off at the Vt value. Vt in this example is 0.5 V. See Figure 7.

Figure 7. Switch behaving ideally with Vh = 0.

The behavior of the switch vs. the input voltage can also be plotted. Delete the V(in) trace, and then change the x-axis from time to V(in) by right clicking on the x-axis. See Figure 8 and Figure 9.

Figure 8. Set the horizontal axis to V(in).
Figure 9. Plotting V(out) vs. V(in).

Behavior with Positive Vh

Positive values of Vh will add hysteresis to the switch. Changing Vh to 0.2 V in the Vswitch.asc example will illustrate the added hysteresis. See Figure 10.

Figure 10. Adding hysteresis using positive Vh value.

Behavior with Negative Vh

Negative values of Vh will add a smoother transition between on and off states (the transition region is set by the negative Vh value). Note that negative Vh only applies a smooth transition period, and does not apply any hysteresis. See Figure 11.

Figure 11. Adding smoother transition with negative Vh value.

Example: Op Amp with Variable Gain

A second example was inspired by the electrics lab posted here. A simple version of this circuit can be simulated using ideal op amp and switch models. This example schematic is named Variable_Gain_Amplifier_Example.asc and is available for download here.

Observe how the gain of the amplifier circuit changes as the current path through R3 cycles between open and shorted. See Figure 12.

Figure 12. Variable gain implemented with switch.

FET, Switch, and Mux Macromodels in LTspice

If the circuit being created requires more realistic devices to replace the idealized voltage-controlled switch, the LTspice component library provides easy access to more realistic models—including transistors, ADI switches, and multiplexer devices.

Conclusion

See the LTspice recommended reading list to learn more LTspice tips and tricks.

Author

Anne Mahaffey

Anne Mahaffey

Anne Mahaffey joined Analog Devices in 2003 as a test engineer supporting direct digital synthesis products after receiving her B.S.E.E. from the Georgia Institute of Technology and her M.S.E.E. from North Carolina State University. She spent over 10 years architecting and supporting design tools in the Precision Studio tool suite and now supports LTspice® as a principal applications engineer.