LTspice - analyze current with varying resistance

I would like to graph current from V1 over varying resistance instead of voltage. Is there a way to do this?

• Try to use .op analysis instead of transient. – G36 May 15 '19 at 19:42
• Perfect, thank you! – SamR May 15 '19 at 19:47
• OK kinda worked. If I use -V(n002) to plot I get the graph I want, but not the units. – SamR May 15 '19 at 23:09

The are (at least) four fundamental methods for varying a load in LTSpice. For your application I think method 3 is going to be the winner, but let me outline them so you can evaluate:

Method 1: .step

As in your question, simple but no time domain control.

Method 2: Switch Model

Good for time-domain control of step-wise resistor changes. The presence of the switch model in the current path can complicate things, and gets cumbersome if there are lots of step-wise changes.

Method 3: Variable Parameters

Set your resistor's resistance to an expression involving V(netname), and then drive that net with a variable voltage of your choice.

Very simple to include in circuit and very powerful to control because you can use any voltage source circuit.

Method 4: Behavioural Sources

Similar to Method 3, but use a behavioural source (bi or bv) instead of a passive component.

Adds the extra feature of controlling a source rather than a sink.

• Thanks! Let me work on this and see. Back later with update. – SamR May 15 '19 at 23:07
• BTW what is the link to that reference material? – SamR May 16 '19 at 0:57
• I'm not sure what reference material you're referring, but I draw most of my inspiration from the surprisingly excellent built-in manual. – Heath Raftery May 16 '19 at 2:27

If you want to vary resistance in a transient simulation the best way to do this is with a node that has a source with the values for resistance and change that node.

Resistors can be set to the same value as a voltage node (so you could have resistors that vary with a sine/square or anything a voltage source can produce). Below is shown how to do this with a PWL source. The amplitude of the voltage source will be the same resistor values. The resistor must be set to the same node name with a V() function to only get the voltage of that net/node.

It seems the default Save Device Current was turned off in Control Panel. After correcting that issue and using DC Operating Point (.op) I got what I was trying to plot.

This is just an addendum to @HeathRaftery's answer, the part with the switch. By using a negative threshold voltage, both the level 1 and level 2 switches have a smooth, nonlinear transition from ON to OFF resistances, so by solving for the conductance/resistance and applying that voltage to the switch, it is possible to precisely control the variation of the resistance.

For the level 2, the formula is given in the manual:

$$\g(V_c)=\exp(A\arctan(\frac{V_c-V_t}{|V_h|})+B)\$$
$$\A=\frac{1}{\pi}\log(\frac{R_{off}}{R_{on}}), B=\frac12\log(\frac{1}{R_{on}R_{off}})\$$

Solving for the resistance, you get:

$$\V_c=V_t-\tan(\frac{R+B}{A})|V_h|\$$

where $$\R\$$ is the varying resistance. This formula can be used with a behavioural source. If the variation needs to be linear, it could look like this:

V=Vt-tan( (log( R(time) ) + B)/A )*abs(Vh)


with

.func R(x) {x/simulation*(Roff-Ron)+Ron}
.param simulation=3 Roff=1k Ron=1 A=log(Roff/Ron)/pi B=log(1/Roff/Ron)/2


where simulation represents the total simulation time (e.g. tran {simulation}; optional, for better control). Here's a quick example:

where the parameters for the PWL source have been defined as Vmin=Vt-abs(Vh) Vmax=Vt+abs(Vh). You can see plotted V(l2) vs V(test), which are the normal variation of the resistance for the level 2 switch when a linear ramp between Vmin and Vmax is applied, compared to its direct, behavioural expression, and V(ctl), where it's desired that the resistance varies linearly, defined as in the example above.

For the level 1 switch, there is no formula in the LTspice manual, but there is in the PSpice manual. Search for PSPCREF.PDF on the Internet and at page 222 you'll find what you're looking for, but you'll see that it's actually a 3rd order polynomial, which means solving for the controlling voltage will result in a fairly involved formula. Despite the $$\\tan()\$$ in the level 2 switch, it's more readable. The choice belongs to you.