When using a pulse, you need to specify the rise/fall times, otherwise LTspice will use 10%
of the ON
time for the zero edges. This will make your Ton
larger. This doesn't mean that you should exaggerate by making Trise/Tfall=1p
, or similar, you can simply stay within sensible limits. For example: Trise=Tfall=Ton/1000
is a good enough choice. Don't forget that, if you need precise timings, (Trise+Tfall)/2
should be subtracted from Ton
. For your case, suppose you need Trise=0.1u
and Tfall=0.5u
, => Ton=12-(0.1+0.5)/2=11.7u
.
For your SW
, you're better off using LTspice's native notation, that is Vt
and Vh
, it makes it much clear where's the threshold and how much hysteresis there is. For your case, and counting the minor example with the timings for the source, above,, it's best to use Vt=2.5 Vh=-2.5
. Negative hysteresis means it will not switch abruptly between states, but smoothly, thus reducing the risk of discontinuities ("Time too small" erros & co).
Your diode could also use a more detailed setup. If you want to keep the idealized version, then add this to your schematic: .model d d ron=1m roff=1meg vfwd=0.4 vrev=1k epsilon=50m revepsilon=10m
. Or you can simply add .model d d is=1f
to make LTspice use the Berkeley SPICE generic model.
Lastly, to improve convergence and make the circuit act more like a quasi-real approximation, you could add Rser=1m
to your supply source (this will make LTspice convert it, internally, into a current source, thus improved convergence over voltage sources), you could add some parasitics to your L
s and C
s. For example Rser=10m
for C
(to limit switching currents, thus keeping values within reasonable limits), and some large-ish Rpar=100k
for L
(which would add some damping for unwanted oscillations). Note that Rser
defaults to 1m
for L
, if not specified and/or used with coupling.