Ttol in SW element not working?

Hi All,

I am wondering if the input SW element should have the behavior of an ideal comparator or not?

My reasoning is that since SW has ttol parameter and also two differential input, thus it should be able to perform a comparator function and force the solver to solve the discontinuity event. However, when I tried it does not work.

Or perhaps the ttol here is implemented with different purpose compared to comparator or logic circuit?

SW as comparator.qsch (4.9 KB)

Hope if @Engelhardt or @KSKelvin can shed some wisdom here.

note: my reason on trying to do this is to (a) implement a deadtime logic and (b) implement a simpler comparator circuit.


This is an interesting situation. You are using -VH, which mean the switch smoothly transitions between on and off.

Negative VH
For negative VH, the switch is operated in continuous and ttol is not triggered (just my guess). If you reduce timestep and plot V(out) vs ctrl voltage, you are getting a smooth transition line. In this case, there is no discrete event to trigger ttol. I am not completely sure, but from this case, may be switch doesn’t offer ttol in negative VH.

Positive VH
By changing VH=-1 to VH=0 (or positive number), you can observe ttol is in effect.
The switch is operated in a discrete behavior and ttol is in effect.

Is your intention to force the switch to smoothly transition? If the switch is smoothly transit, may be limiting maxstep is a more reasonable approach? If you need hysteresis, VH should be positive number.

1 Like

Oh I see, Thanks a lot Kelvin

My intention is to use the switch as an ideal on/off switch. Again to make a simpler comparator with accurate switching time.

I tried your suggestion for Vh = 0 and now it works.

I believe I previously misunderstood the meaning of “smoothly transition”, thus all of my simulation all my switch model always use vh=-1. however, all of those the gating signal is provided by an ideal 0/1 source and thus I never see this issue.

@Engelhardt What will be the reasonable use case for a smooth transition on a switch?
anyway, is that a sigmoid function?

Just give you some background. But it will expose I am much older than you.

In Qspice HELP, S. Voltage Controlled Switch section.
(Vt, -Vh) is compatible to (Von,Voff) in Qspice.

(Von, Voff) is parameters in Pspice style switch (smoothly transit), and below picture is quoted from Pspice manual.
I still remember in that time, I had to use PSIM for power electronic circuit simulation because it handle discrete switches (but it is not a general purpose spice program).

LTspice possibly the first general purpose spice program can handle analog simulation with discontinuities (and free to use), that may be the major reason why it is most widely distributed simulator. Mike said that Qspice is way better than LTspice, and this is the reason I spending so much time in it since it launched.

In short, smoothly transition switch is the ancestor in spice. negative vh offers backward compatibility.

Thanks a lot for your background knowledge on how Pspice handle it… And You are not that much older, just maybe I was right to call you 大哥…haha

Same here… I was a long time PSIM user,

But, since 2 year ago… I was at loss without PSIM to simulate controller in C… Where I ended up in NL5 and now with Qspice

Anyway, I just check the switch resistance during switching and it is indeed switch slowly when Vh<0 is used.

Anyway, just a quick test

For a simple comparator only case, that circuit is about the same speed as using scmitt comparator

Hope some difference may be more noticeable on more complex circuit

But we have to wait and see if also in the long term @Engelhardt and the qvoro team (@Jeff_Strang) will further support qspice, If they will make regullary updates, and very importantly if they will be here among the users giving explanations and support.

I want to vouch for @KSKelvin to get paid as application engineer for Qspice…

1 Like

Mike works on Qspice everyday. Community can help make thing better.
I only navigate through forum to spot for bug and report that. :rofl:

In SPICE, it is desirable to have IV curves that are continuous in value and slope. That means the SW smoothly turns on and off. For example, in PSpice, only the smoothly transitioning switch is supported.

But of course it is desirable to have a SW turn on and off abruptly, even with hysteresis. Berkeley SPICE tried to introduce such a switch, but got it wrong. It confuses Newton iteration with time step iteration.

QSPICE is the first SPICE that correctly handles the hysteretic switch. It is the very core of the time step control of the mixed mode simulator.



And this time step control can be done via TTOL parameter only? Or there are more ways to do this?

And this thing that we can control time step of simulation with ttol parameter within the components (therefore beeing a benefit when digital and analog + digital simulations are run together, right?), it’s the core advantage over other simulators? Or?

In the C++ interface, there are two functions that address analog/digital handshake.


@Engelhardt for two functions that address analog/digital handshake, are you referring to Trunc() [TTOL] and MaxExtStepSize() [MaxStep]? Or something else?

1 Like

And in verilog, there are functions that address handshake between analog and digital?

We appreciate everything you do for the QSPICE community, Kelvin. Thank you!