Electronic – LTSpice: How to vary resistances in a simulation depending on the value of a voltage


I am trying to implement the Hodgkin-Huxley model for simulating neurons using LTSpice. One feature of this model is that the resistances at any given time actually depend on the transmembrane voltage at that time. Is there a way, in LTSpice, to change the values of resistors dynamically in a simulation?

I can find answers on how to vary the value of a resistor in pre-defined increments during a simulation. However, this approach will not work in this case, because I don't know these increments before the simulation starts. Rather, they must be recalculated dynamically from a particular voltage. Does LTSpice (or any other version of Spice, for that matter) have this capability?

EDIT: To be more specific about what the Hodgkin-Huxley model entails, the simulation code I need basically boils down to this schematic, where the g's represent the conductances, the E's are all constant voltages, gL is constant, and the other conductances all update according to these equations:

where m, n, and h are state variables, and Vm is the transmembrane voltage (the voltage between Istim+ and Istim- in the above schematic). The alpha's and beta's are known functions of the transmembrane voltage.

In particular, I need to be able to keep track of the "current values" of the m, n, and h parameters during the simulation because the next value of these variables will depend on them.

Best Answer

I haven't spent much time considering a method for this. But it sounds as though you may have an arbitrary function that computes \$R\$ based upon an applied voltage \$V\$.

You might use LTSpice's .FUNC to do something like this:


(That's just a random function to illustrate the idea.)

Then you could just drop down a resistor, which will default to a value of "R". Now, right-click on the "R" there and get a prompt to allow you to change it. The dialog box should be titled "Enter a new value for Rx". Enter "R={MYFUNC(V(N005,N006))}" or something like that (if you know the node names, use those.) That should allow you to make up an arbitrary function based upon some formula you concoct.

You don't have to use .FUNC, by the way. You can just enter the formula directly into the "R={...}" expression there.

However, the above method has at least one problem. The node names will have to be hard-coded. So this can be a problem as you move forward in a circuit and want the "resistor" to have its value depend solely on a complex function of the impressed voltage on it, regardless of the global circuit node names. For that, I'd go with a .SUBCKT approach.

Here, you'd just drop down an new R like you always do. Then ctrl-right-click the R symbol. Edit the "Prefix" to "X", modify "InstName" to specify "X1" or "X2" or something like that, get rid of the "Value" entry (edit it and delete it), and modify the "SpiceLine" entry to specify a subcircuit name of your choice. Now you have a nice subcircuit symbol that looks like a resistor, but LTSpice now thinks it is a subcircuit.

Now just add a subcircuit. Hit "S" and get the Spice directive dialog box to pop up. Now enter something like this (I'm using the subcircuit name of "XYZ" here):

GRES 1 2 VALUE={1.0/(10k*V(1,2))}

What I've done above is just use a "G" device. This device can now look at its own terminals, get the voltage from them, and then compute some current based on that. In the above formula, I decided I wanted to mimic a resistor whose resistance magnitude is, ignoring dimensional analysis for now, \$R=V^2\cdot 10\:\textrm{k}\Omega\$. (I squared the voltage to make sure the result is always positive or zero. Allowing zero probably isn't the greatest idea. So just be aware.) Given that, you can work out that the current should be \$\frac{V}{V^2\cdot 10\:\textrm{k}\Omega}=\frac{1}{V\cdot 10\:\textrm{k}\Omega}\$. So that's how I got the equation to use there.

You can do combinations. You can create separate .FUNC functions and use those inside of your subcircuit. You can make the subcircuit as complicated as you want, too.