How can I link a component's current to variable resistor value in LTSPice?

Sure. Just type this instead of the value:

R=I(D1)*1000

1000 would be the scaling factor and is often needed because currents are usually in the milli-range while resistors are usually in the kilo-range. You can put more advanced expressions instead of a simple constant factor. Make sure you don't end up with negative resistances and such, it can be difficult to build such a circuit.

To display the resistance as a trace after a transient response simulation you can use Ohm's law: R=U/I. You have to know the name of the voltage nodes on each side of the resistor you want to "measure", then edit the trace name to (V(node1)-V(node2))/I(R1). It will give you a unit of Ohms.


For this specific span, the following should work for a linear span from 160k to 10k from 0 to 20mA:

160k-(I(D1)*7.5MEG) - I used the dialogue box to enter that directly. This yields a linear span across your range. Make sure your current does not exceed 21.33mA (or use other functions available to prevent the value becoming negative).

Using max(160k-(I(D1)*7.5MEG), 1k) should do it; take the highest of the calculated resistance or 1k.

For a 1Meg to 10k span, we simply change the span control: You are starting at \$1M\Omega\$ and to get to 10k; therefore we need to reduce by 990k, so \$\frac {990k\Omega} {20mA} \$ = \$4.95*10^{7}\$ yielding:

REFDES = max(1MEG-(I(D1)*49.5MEG), 1k)

You could, alternatively, use PARAM statements but that is not as elegant.

Tags:

Ltspice