Can I use the VSWITCH with a voltage threshold?

282 views
Skip to first unread message

xyce-users

unread,
May 31, 2020, 1:02:26 PM5/31/20
to xyce-users
I was looking through the reference guide and I'm unclear about using if-else or control expressions with the VSWITCH. 
I have this switches defined in LTSpice
.model SW1 VSWITCH (RON=.001 ROFF=1e9 VT=.5)
.model SW2 VSWITCH(RON=1e9 ROFF=.01 VT=.5)
S5 Anode P001 N001 N002 SW2
S6 N003 Anode N001 N002 SW1

I want to use the same in XYCE. I tried this below but I think it's not working
.MODEL SW1 VSWITCH (ON=0.001 ROFF=1e9)
.MODEL SW2 VSWITCH (ROFF=0.001 RON=1e9)
S5 Anode P001 SW1 OFF CONTROL={V(N001)-V(N002)}
S6 P002 Anode SW2 OFF CONTROL={V(N001)-V(N002)}

Also, the below commands are to be commented out when we use the LTSpice netlist into XYCE right?
*.lib UniversalOpamps2.sub
*.backanno

Thank you. 

xyce-users

unread,
May 31, 2020, 1:35:25 PM5/31/20
to xyce-users
Xyce is not netlist compatible with LTSpice, and does not try to be.  In order to port a netlist from LTSpice to Xyce you will have to carefully match up what the original is trying to do and reimplement it in Xyce syntax.  LTSpice has added many features to really basic devices like capacitors and inductors, and almost none of those extensions are in Xyce (notably, almost every device in LTSpice can have parasitic lead resistors, capacitors, and inductors and the OpAmp you posted earlier makes use of that feature).  You will  not be able to take an unmodified LTSpice netlist and us it in Xyce.  The Xyce team will be unable to give you concrete advice on how to translate your netlist other than to point you at the reference guide, which generally documents everything that Xyce can do.

The most general switch device in Xyce is the S device, which may be either voltage-controlled or the "generic" device.  The manual is incorrect when it says that the "generic" device is accessed by the "SW" device --- that is outdated and will need to be fixed.

The Xyce regression suite has examples of each in the VSWITCH, ISWITCH, and GSWITCH test directories.

A voltage controlled switch that turns on when the control voltage is 1 V is given by:


S1 1 0 3 0 SW
.MODEL SW VSWITCH(RON=1 ROFF=1MEG VON=1 VOFF=0)


This switch turns on when V(3,0) is 1V.  When on, it has a resistance of 1ohm, when off a resistance of 1MEG.

A switch that turns on when the controlling current is 10mA would be:
S1 1 2 SW OFF CONTROL={I(VMON)}
.MODEL SW ISWITCH (ION=10mA IOFF=0mA RON=1 ROFF=1E6)


This turns on when I(VMON) is 10mA and off when it's 0mA.  The on/off resistances are the same.

This same switch may be modeled as a "W" device:
W1 1 2 VMON SW OFF
.MODEL SW ISWITCH (ION=10mA IOFF=0mA RON=1 ROFF=1E6)



Finally, this "generic" switch turns on when its control expression is above the ON setting and off when its control expression is the OFF setting or below.  The control expression may be any expression that the expression library recognizes, but be aware that making very discontinuous expressions may cause convergence problems.  This switch turns on when the control expression is 1, and the control expression is explicitly time dependent --- so this switch turns on at t=2us:
SW1 1 2 SW OFF CONTROL={if(time>2u,1,0)}
.MODEL SW SWITCH (ON=1 OFF=0 RON=1 ROFF=1E6)


None of them are strictly compatible with SPICE (LTSpice, ngspice, spice3f5).  There is no "vt" threshold voltage in Xyce's switch, you have only on/off values.  You can set on and off to numbers that are close together, straddling the threshold, to get something that is close to what the SPICE device does.  Xyce's switch smooths the transition between on and off for improved convergence, which the SPICE switch does not do.

xyce-users

unread,
May 31, 2020, 2:04:54 PM5/31/20
to xyce-users
Thank you so much for explaining in detail. The code works now. It makes sense. Yes, that SW in the reference guide I was confused about.
I just simulated my circuit. It works in the transient simulations though doesn't give the desired output
But, it gives the following warning in the DC simulations 

        Step size reached minimum step size bound

        Step size reached minimum step size bound

        Step size reached minimum step size bound

        Step size reached minimum step size bound

        Step size reached minimum step size bound

        Step size reached minimum step size bound

        Step size reached minimum step size bound

        Step size reached minimum step size bound

        Step size reached minimum step size bound

        Step size reached minimum step size bound

I think this is because there is some ambiguous condition that the threshold switch produces and XYCE tries to find the exact voltage/current value at a given time with precision. But any way around this issue?
I use the below simple command for either transient or DC analysis
.tran 0 10e-3 9e-3 500E-9
.print tran v(Vosc1) v(N005)

*.dc V14 0 40 0.001
*.print dc v(Anode) i(V14)
Do I need to take care of step size somewhere in these commands? I tried varying the 0.001 step size of V14 but nothing happens. Also, the transient analysis doesn't show the correct time-varying waveform. It should work because it works in LTSpice. But there might be differences in LTSice and XYCE analysis because of the OPAMP model and the VSWITCH model, but I don't know where the problem lies.
Thanks again!
I have also attached my 2 files. 
Synapse_model_v2.cir
op27g.cir

Bill Ballard

unread,
May 31, 2020, 5:39:12 PM5/31/20
to xyce-users
I downloaded your Synapse_model_v2.cir file and it ran no problem in Xyce. I assume you have a 64 bit computer? I made no changes at all to the Synapse_model_v2.cir file.
Synapse_model_v2.log
Synapse_model_v2.prn

Bill Ballard

unread,
May 31, 2020, 5:47:01 PM5/31/20
to xyce-users
That said, all I got was two constant voltages on the nodes being logged, which is not what I expect you wanted to see.

xyce-users

unread,
May 31, 2020, 11:05:27 PM5/31/20
to xyce-users
Yes, I get the same too. But there is something problematic I think because of which I'm getting 2 constant voltage columns. The DC simulation does not give any output. The DC simulation file is attached below. It gives this bug 
Step size reached minimum step size bound
Is there any way to get around this step size issue? If I can get a DC simulation then I can trust the results of the circuit too. The circuit's response in other simulators (Like LTSpice) is as shown below. It is a switching device that switches from high resistance to a low resistance state. 
Synapse_model_v2.cir

xyce-users

unread,
May 31, 2020, 11:17:20 PM5/31/20
to xyce-users
I think I somewhat know now why the DC simulations were not working. I was shorting two nodes with this command 
Rg Vosc1 0 0
Which doesn't seem to work correctly
Rg Vosc1 0 0.1
At least some data out from the simulations. The manual doesn't mention about any 'WIRE' commands that can be used to easily short multiple nodes. I wonder if there is one. 
Reply all
Reply to author
Forward
0 new messages