Electronic – How to change an LTspice .model parameter during transient simulation

boostltspice

I'm trying to make an idealised boost converter using current feedback. I want to simulate changes in duty cycle, which is controlled by the Vt and Vh of the switch.

I managed to use .step to see the effect of various settings, but I can't figure out how to change it during simulation. I tried to define a voltage source and do things like Vt={V(thr)}, but could not get it to work. How can I do this?

circuit

plot

Best Answer

You've chosen a sensible limit to the values of on/off resistances for both the switch and the diode, congratulations. You can also add Vfwd=0.45 epsilon=50m revepsilon=10m to the diode for even less worries about convergence. However, the Vt and Vh might not do what you expect them to do.

What your schematic shows is some self-oscillating(?) boost converter, but it will not work. If you want to see the effects of duty cycle, then it doesn't matter whether it's voltage- or current-mode, you're simply driving the switch with a user controlled duty cycle irrespective of feedback. See the right side of the schematic. If you want to make it with a loop, then it's the left side.

boost

On the left side, F1 collects the current through L1, with a negative sign, and sums up with the reference I1, then, together with C2 form a rudimentary PI controller, feeding the comparator with the ramp, then the switch. On the right side, the duty cycle is fixed throughout the simulation. If you need it variable during the simulation, you can set up a PWL source, instead of a PULSE. For example, PWL 1m 0.25 1.1m 0.5 2m 0.5 2.1m 0.75, which will start with 0.25 until 1ms, then goes up to 0.5 over 0.1ms, continues until 2ms, then goes up to 0.75 over 0.1ms, and stays until the end (3ms in this case).


Ah, so it is intended to be self-oscillating. Then you could use a variable hysteresis through x, while keeping the threshold intact, fix, but you might need to add a small capacitor:

tweak

The explanation is that, as you probably know, in SPICE, sharp changes, discontinuities, and such are the enemy of convergence. The switch, in LTspice, as per the manual, has the option to have sharp changes of value by specifying a positive hysteresis, and smoother (level=1, default), to tanh smooth transitions (level=2), if negative hysteresis is specified. If you try to modify your schematic with negative hysteresis, it will not oscillate due to the nature of smoothing which probably adds a nonlinear delay.

As you have it, it does switch, but at the cost of possible convergence issues, which can arise if you set up vt to be different than vh. So, a minor solution is to add a small enough capacitor in parallel with R1, which smooths up the sharp edges just long enough for the engine to catch up with the derivative, while also not perturbing the rest of the schematic. Additionally, to avoid a parallel RC, you could make a small RC lowpass with small enough values for the filter to not influence the current, while also providing the necessary convergence aid.

As it is now, you can see a fixed value for vt=10m and a .step for x, from 1m to 9m, step 2m.


After less than 20 years, I realize I missed the point in OP's question. Must be my Alzheimer.

Unfortunately, the VCSW doesn't allow for an external hysteresis control, but so what, neither do the Schmitt triggers. You could use a comparator with a variable resistor, and that would even work in real-life. Fortunately -- and seeing that your attempt is more on the theoretical side -- there are behavioural sources, but even better, there's the .mach command. Here's a reworked version that allows for a dynamic hysteresis control:

mach

C2 has the same role as before, but now V2 controls the hysteresis voltage, while in the top right there's the relevant .mach command that implements a Schmitt trigger with external hysteresis. As per the manual:

The .output statements implement current sources that require external devices to readout the current. As shown in the examples below, 1K ground-referenced resistors are normally used, but you might want to add some parallel capacitance to ground to slow transitions.

...which is what I did with C3. V2 first starts with a fixed voltage, to give time for the circuit to catch up. Also, the upper threshold is held fixed and the lower one made variable, to allow for a variable output voltage.