Electronic – How to i do a current dependent resistor on LTSpice

ltspiceresistors

I'm trying to do a current controlled resistor, but I dont know how to use .param, .subckt or .func to make it.

Illustration image, just to help undestanding

How can i do a current dependent resistor on LTSpice?

ps.: This is what shows up about the error
enter image description here]2
ps2.: the new netlist
enter image description here

Best Answer

Voltage Spike's answer will solve your problem if, as vangelo hints, there is no instantaneous feedback (quote from the help, under LTspice > Circuit Elements > B. Arbitrary Behavioral Voltage or Current Sources, emphasis mine):

it is assumed that the circuit element current is varying quasi-statically, that is, there is no instantaneous feedback between the current through the referenced device and the behavioral source output.

Otherwise -- and since I doubt you'll add more details -- there is a way that allows direct feedback. It looks complicated but it's not, it's very fast, but it does come at a cost:

alt

The actual circuit is formed by:

  • Vi = current sensor
  • S1 = the variable resistance
  • H1, G2, C1, S2, I1 = the control circuit

V1 and L1 make a random circuit. Despite the fact that it has 7 elements, it performs very fast, because it's linearized.

I1 generates a 1 A DC current through S2, which means the voltage across it, V(R), is 1:1 proportional to its resistance. Vi takes the current through S1 and compares it with V(R), then feeds it through the PI filter made of G2 and C1. The resulting difference (the error voltage V(ctl)), will be such that V(R) follows I(Vi), which means using V(ctl) on S1 will make S1 have a resistance 1:1 proportional to the current through it. The plots show I(Vi) and V(R), side by sude, and they are a match. One advantage is that if you need other resistors to vary just like S1, all you need is to add one VCSW for each resistor needed.

But, it's not perfect:

  • The VCSW needs a .model card which defines its ON and OFF resistances, whose values are the direct limits of how low or high it can vary. You may be tempted to use Ron=1f and Roff=1T, but if the ratio between them is greater than 1012, that's a recipe for disaster. Ron=1u Roff=1meg should be the highest range used; anything else means you're on your own. Even so, a resistance that varies between 1 μΩ and 1 MΩ should suffice in most cases.
  • The PI filter has a limited bandwidth, which is directly proportional to the error. In this case, V1 generates a 1 Hz signal which, compared to the 1 nF and 1 Ω values for the loop filter, means the errors are very low. But the errors are inveresely proportional to the ratio between these values and the maximum frequency the resistor is supposed to work with. Here is how the differences between V(i) (voltage representing I(Vi), 1:1) and V(R) look like when the values for C1 are 10 μF (black), 100 μF (blue), and 1 mF (red):

diff

Therefore, try to keep the bandwidth at least 1...10 thousand times more than the maximum frequency of interest (i.e. if fmax = 1 kHz then keep C1 below 100...10 nF). If you want to play with it, below is the source of the schematic. Save it as .asc, but not .asc.txt:

Version 4
SHEET 1 880 680
WIRE -32 80 -96 80
WIRE 128 80 48 80
WIRE 240 80 208 80
WIRE 272 80 240 80
WIRE -96 128 -96 80
WIRE 272 144 272 80
WIRE 368 160 320 160
WIRE -96 224 -96 208
WIRE 240 368 176 368
WIRE 304 368 240 368
WIRE 368 368 368 160
WIRE 368 368 304 368
WIRE 480 368 416 368
WIRE 496 368 480 368
WIRE 560 368 496 368
WIRE 80 384 32 384
WIRE 128 384 80 384
WIRE 240 384 240 368
WIRE 368 384 368 368
WIRE 128 544 128 432
WIRE 496 544 496 368
WIRE 496 544 128 544
FLAG -96 224 0
FLAG 176 448 0
FLAG 32 464 0
FLAG 240 80 x
FLAG 272 224 0
FLAG 320 208 0
FLAG 240 448 0
FLAG 416 448 0
FLAG 368 432 0
FLAG 560 448 0
FLAG 480 368 R
FLAG 304 368 ctl
FLAG 80 384 i
SYMBOL voltage -96 112 R0
WINDOW 0 40 71 Left 2
WINDOW 3 17 95 Left 2
SYMATTR InstName V1
SYMATTR Value sin 2 1 {f} 0 {f/3}
SYMBOL g2 176 352 R0
WINDOW 0 18 94 Left 2
WINDOW 3 18 123 Left 2
SYMATTR InstName G2
SYMATTR Value 1
SYMBOL voltage 112 80 R270
WINDOW 0 32 56 VTop 2
WINDOW 3 -32 56 VBottom 2
SYMATTR InstName Vi
SYMATTR Value ""
SYMBOL h 32 368 R0
WINDOW 0 40 73 Left 2
SYMATTR InstName H1
SYMATTR Value Vi 1
SYMBOL sw 272 240 R180
SYMATTR InstName S1
SYMBOL cap 224 384 R0
WINDOW 0 33 12 Left 2
WINDOW 3 30 52 Left 2
WINDOW 123 30 74 Left 2
WINDOW 39 30 96 Left 2
WINDOW 40 30 118 Left 2
SYMATTR InstName C1
SYMATTR Value {k/f}
SYMATTR Value2 Rser=1
SYMATTR SpiceLine Rpar=1g
SYMBOL sw 416 464 M180
WINDOW 3 27 85 Left 2
SYMATTR InstName S2
SYMBOL current 560 448 M180
WINDOW 0 24 80 Left 2
WINDOW 3 24 0 Left 2
SYMATTR InstName I1
SYMATTR Value 1
SYMBOL ind -48 96 R270
WINDOW 0 32 56 VTop 2
WINDOW 3 5 56 VBottom 2
SYMATTR InstName L1
SYMATTR Value {1/f}
TEXT 408 40 Left 2 !.tran {5/f}
TEXT -8 -24 Left 2 !.model sw sw ron=1m roff=1k vt=0 vh=-1 level=2
TEXT -136 328 Left 2 ;control
TEXT 440 264 Left 2 ;actual resistance
TEXT -144 264 Left 2 ;random circuit
TEXT 408 80 Left 2 ;.opt plotwinsize=0
TEXT 408 120 Left 2 !.parma f=1 k=1u
TEXT -8 -56 Left 2 ;.step param k list 10u 100u 1m
RECTANGLE Normal 640 576 -160 304 2
RECTANGLE Normal 640 288 112 16 2
RECTANGLE Normal 96 288 -160 16 2
Related Topic