SPICE switch

Thread Starter

Ian0

Joined Aug 7, 2020
1,121
I have a SPICE simulation of a power amplifier. What I'd like it to do is put two plots on the same graph, one with the P-channel current source using J1 and one with the N-channel current source using J2.
I tried using the .step command with a list of two voltages and two voltage-controlled switches , but all I can get is a variety of error messages concerning the switch. It seems as though the switch built into LT SPICE is a shell and needs some "model" detail. What am I missing? Or is there a better way?
 

Attachments

Papabravo

Joined Feb 24, 2006
14,847
Yes. A .model statement will do the trick. Check out help page for the "S. Voltage Controlled Switch" component. there are several parameters that you can specify. Ron, the on resistance of the switch is the most useful of the parameters. Any parameters you don't specify will have default values. Give it a shot and re-post here if you have problems; I'll dig up an example or two for you.
 

Thread Starter

Ian0

Joined Aug 7, 2020
1,121
I added ".model MySwitch SW(Ron=.1 Roff=1Meg Vt=0 Vh=-.5)"
and edited the switch as shown (not sure I have "MySwitch" in the correct field).
The error is "Unknown subcircuit called in: xs1 n009 n012 0 n005 myswitch sw"
 

Attachments

Papabravo

Joined Feb 24, 2006
14,847
I added ".model MySwitch SW(Ron=.1 Roff=1Meg Vt=0 Vh=-.5)"
and edited the switch as shown (not sure I have "MySwitch" in the correct field).
The error is "Unknown subcircuit called in: xs1 n009 n012 0 n005 myswitch sw"
Here is an example of using a switch to model a switch mode power supply from the book by Basso. The switch should not be a subcircuit with the prefix "X".

SwitchModeControl_1.png

PSWAttributes.png
 

Attachments

Last edited:

crutschow

Joined Mar 14, 2008
25,991
".model MySwitch SW(Ron=.1 Roff=1Meg Vt=0 Vh=-.5)
Try using sw in place of Myswitch.
That parameter is the name of the switch (default is SW) which is confusing, as SW is also used for the switch model definition.

I usually use .model sw SW(Ron=0.001 Roff=100Meg Vt=0.5 Vh=.01.
That will change states at a control voltage of 0.5V±10mV (switch closed above that voltage and open below it).
 

Papabravo

Joined Feb 24, 2006
14,847
Try using sw in place of Myswitch.

I usually use .model sw SW(Ron=0.001 Roff=100Meg Vt=0.5 Vh=.01.
That will change states at a control voltage of 0.5V±10mV.
The actual name of the switch instance is irrelevant. It is only used to relate an instance of the symbol to the .model card. The real problem is the use of the "X" prefix as if it was a subcircuit. The switch component is NOT a subcircuit. See post #3 and post #4 (amended)
 

eetech00

Joined Jun 8, 2013
2,183
I added ".model MySwitch SW(Ron=.1 Roff=1Meg Vt=0 Vh=-.5)"
and edited the switch as shown (not sure I have "MySwitch" in the correct field).
The error is "Unknown subcircuit called in: xs1 n009 n012 0 n005 myswitch sw"
Place the .model statement on the schematic. Be sure it is a "directive" and not "text"

Attribute values:

Prefix: S
InstName: S1 <----this value is auto generated
Value: MySwitch

Those are the only values you need to specifiy in each symbol.
 

Papabravo

Joined Feb 24, 2006
14,847
The Myswitch name is certainly relevant.
It must be the same as the name on the switch instance which defaults to SW when you place a switch from the parts file.
Isn't that what I said? It can be MySwitch, but it doesn't have to be -- it can be any name as long as there is a correspondence between the name on the symbol and the .model card.
 

Papabravo

Joined Feb 24, 2006
14,847
Well that doesn't seem "irrelevant" to me. :rolleyes:
Well the irrelevant part, for those perhaps a bit slow on the uptake, is the actual choice of the characters "MySwitch". In fact as you yourself pointed out it could be SW, or Sw, sw, or as in my example "PSW1". Consistency demands that the same name appear on both the symbol and the .model card. In fact you can have switches with different characteristics on the same schematic, but they need to have different names.
 

crutschow

Joined Mar 14, 2008
25,991
Well the irrelevant part, for those perhaps a bit slow on the uptake, is the actual choice of the characters "MySwitch".
No need to be snarky.

If the the choice of characters can be anything but must be the same in both the switch instance and the model definition, then I think the correct word is arbitrary, not irrelevant (having no bearing on or connection with the subject at issue), even for those of us "a bit slow".
 

Papabravo

Joined Feb 24, 2006
14,847
No need to be snarky.

If the the choice of characters can be anything but must be the same in both the switch instance and the model definition, then I think the correct word is arbitrary, not irrelevant (having no bearing on or connection with the subject at issue), even for those of us "a bit slow".
Snarky...no, That was the mildest of nudges. I still think the actual choice of a name for the switch is not relevant to the proper functioning of a simulation. It may be arbitrary as well. I think it is possible that the words we apply to this situation are not required to be unique. We are of course both entitled to our opinions.
 

Thread Starter

Ian0

Joined Aug 7, 2020
1,121
Here is an example of using a switch to model a switch mode power supply from the book by Basso. The switch should not be a subcircuit with the prefix "X".

View attachment 226774

View attachment 226776
X was the problem in the component attribute editor.
I called it ISW - my view on the choice of name is that it should be something that isn't easily confused with names SPICE uses already - just using SW will lead to confusion, and PSW, MySwitch, ISW won't.
It worked as soon as I had spotted the misconnection between V4 and R5. As you can see it makes little difference! The biggest difference is that I have a J113 in stock and I'd have to order a J177.
ampfrontend4.png
Alternative methods:
Stepping the resistors values (drawing 1) is neat. It saves a lot of clutter on the diagram, and would have prevented the annoying misconnection between V4 and R5. But what's going on in drawing 2 with the arrowhead things?ampfrontend5.png
 

ericgibbs

Joined Jan 29, 2010
11,577
Morning Ian,
The pesky arrow heads are Alex's switches, SW1 & SW2
.step param i 1 2 1
E

Please post a asc file if you have a LTS problem.;)
 

Thread Starter

Ian0

Joined Aug 7, 2020
1,121
So the "eq" thing is important? Closed when x=y and open otherwise? Is that a funny sort of switch that the rest of us don't have?
 

Bordodynov

Joined May 20, 2015
2,732
I made a SWeq element so that it would be possible to analyze the noise of several different circuits simultaneously. Noises of all analyzed circuits are obtained on one diagram, which is convenient.
 

Attachments

Top