Mechanical switch in LTspice

Thread Starter

cmartinez

Joined Jan 17, 2007
8,749
I'd like to use LTspice to simulate how a mechanical switch produces a spike in voltage when it is opened while driving an inductive load.
Can it be done?
 

OBW0549

Joined Mar 2, 2015
3,566
I'd like to use LTspice to simulate how a mechanical switch produces a spike in voltage when it is opened while driving an inductive load.
Can it be done?
I haven't used it myself, but you might try the sw (voltage-controlled switch) component, driven by a PWL or PULSE voltage source.
 

crutschow

Joined Mar 14, 2008
38,430
LTspice has a voltage controlled switch model (sw) that will certainly generate a spike with an inductive load.
You need the sw model discription for the switch to work (look up "sw" in the help file).
You add it as a Spice directive (hit the S key while in the schematic window) .
 

Thread Starter

cmartinez

Joined Jan 17, 2007
8,749
Very, very interesting. Thank you both.

I just found the Vswitch.asc example included in LTspice and am finding it quite useful.
My only issue with it is that it's a voltage controlled switch... is there no other kind of switch that could be timed during the simulation? But maybe that's not important since I can always configure a voltage source to drive it.

Thanks again!
 

MikeML

Joined Oct 2, 2009
5,444
...
My only issue with it is that it's a voltage controlled switch... is there no other kind of switch that could be timed during the simulation? But maybe that's not important since I can always configure a voltage source to drive it.
It is easy to make the switch state a function of time, a voltage, a current, etc...
 

Thread Starter

cmartinez

Joined Jan 17, 2007
8,749
It is easy to make the switch state a function of time, a voltage, a current, etc...
Would you please share with me your definition of easy? I'm a neophyte in most LTspice-related things... need to find an example of making a switch a function of time... or maybe I just need more experience with the spice-directive instruction.
 

MikeML

Joined Oct 2, 2009
5,444
The sim I just posted makes the switch state a function of time because the controlling voltage V(pulse) is a function of time. By default, the switch is closed when the input voltage is >0V, and is off if the input control voltage is <=0V. If you prefer it to have a different Threshold voltage, you can set it in the .model SW statement. You can model a switch with hysteresis, too.
 

Thread Starter

cmartinez

Joined Jan 17, 2007
8,749
The sim I just posted makes the switch state a function of time because the controlling voltage is a function of time. By default, the switch is closed when the input voltage is >0V, and is off if the input control voltage is <=0V. If you prefer it to have a different Threshold voltage, you can set it in the .model SW statement. You can model a switch with hysteresis, too.
Yeah... that's more or less what I meant on post #5 ... but you've given me even more information now, thanks.
 

Thread Starter

cmartinez

Joined Jan 17, 2007
8,749
Hello all... I just found the time function in LTspice, and I'm using it to change resistor or pot values (or any value for that matter) during the simulation. In the case of a resistor, for instance, one only has to change its value to:

R=if(time<10m, 5, 15)

Alternative:
R=table(time,0,5, 10m,5,10.01m,15, 20m,15, 20.01m,25)

You can make nested if() of course.
R=if(time<10m, 5, if(time<20m,15, 25))

EDIT: will next try it with the switch
 

letoppina

Joined Dec 11, 2017
28
I'd like to use LTspice to simulate how a mechanical switch produces a spike in voltage when it is opened while driving an inductive load.
Can it be done?
Hi cmartinez,

I'm trying to make the same thing with LTSpice, could you please tell me how you did it? Or even better, could you send me the .asc file? It would help me a lot!
 

Thread Starter

cmartinez

Joined Jan 17, 2007
8,749
Hi cmartinez,

I'm trying to make the same thing with LTSpice, could you please tell me how you did it? Or even better, could you send me the .asc file? It would help me a lot!
I'm afraid this thread is quite old, and I can't remember if I solved this problem or not. Besides I can't find an asc file in my small collection related to this subject.

But I know a bit more about LTSpice by now. There are several ways of approaching this problem. One would be to use a standard voltage controlled switch, which is already a part of the LTSpice library of components.

upload_2017-12-13_10-42-10.png

And I'd use a voltage source to control that switch, with its state defined through values in a time table. Another method would be to use an ordinary resistor, with its value defined as a function of time (as explained in post #11), using an extremely low value (like 0.01 ohms) when it's closed, and a very large one (like 100 mega ohms) when it's open.
 

Veracohr

Joined Jan 3, 2011
783
I use the volt controlled switch in LTspice all the time for mechanical switches. I usually set the model something like
Code:
.model switch SW(Ron=10m Roff=1G Vt=0.5)
That gives 10mΩ contact resistance, 1GΩ isolation resistance, and a voltage trip point of 0.5V. Then for the voltage control I use the PWL type of voltage source to go from 0 to 1 at whatever time I want to switch it, like
Code:
PWL(0 0 1m 0 1.001m 1)
That's a transition from 0V to 1V over 1μs, switching at 1ms of simulation time. If I want to simulate switch bounce, I either use a multi-transition PWL voltage source (for psuedo-random bouncing), or you can use a pulse voltage source with the delay set to the time you want it to come on and a finite number of cycles. If your mechanical switch has bounce time specified, you can set the frequency and number of cycles from that. Sometimes they're not specified, so I set it somewhere around 5-8 bounces in a 5ms time, based on specs I've seen before for specific switches.
 
Top