4

I am trying to add dependent voltage sources in LTSpice, but I need to make a voltage dependent source whose voltage depends on the average of two voltages. How can I build that in LTspice?

The circuit is like in image, enter image description here

ifrah
  • 41
  • 1
  • 2
  • 3

3 Answers3

12

Oh, cripes. I can't believe the answers.

Here.

enter image description here

Hit F2, find "bv", drop it on the schematic, fill out the formula, hook it up somewhere. Done. Doesn't even have to be grounded. You can stick it anywhere. Simple formula, too. Couldn't be easier.

Of course, this assumes you've labeled your two sources as indicated. If they are unlabeled and just node numbers, then use the node names instead.


Per other discussion in comments, I may as well memorialize them here:

The B source is a type of nonlinear controlled source that was added to open the door to pretty much any function you might want, covering pretty much all possible cases. Starting with Spice3, they allowed a V= (for voltage) or an I= (for current.) Most elementary math functions are allowed and you can use node voltages and terminal currents in the expression. The expression is assumed by Spice to be mathematically continuous.

These pretty much had to be added to make it more convenient to create behavioral functions needed for specialized ICs or IC subfunctions, like VCOs. LTSpice has also created (for itself) a number of very much faster internal capabilities that they use to model their own ICs, so that simulating their ICs is faster and better than simulating the ICs of other manufacturers, even if you have the behavioral models for them (because using the standard behavioral B sources in your models does make them slower than if you write specialized computer code to handle your own needs.)

An E source can also be used to duplicate your function, using the "value=" syntax. But as the help in LTSpice says, "This is an alternative syntax of the behavioral source, arbitrary behavioral voltage source, B."

Different Spice implementations are faster or slower handling these, as there are optimizations that can be applied and may be, by some developers. But the B source is generally slowish (but not necessarily noticeably so.) E sources with "value=" aren't much different (obviously.) From the LTSpice help on the E source, "It is better to use a G source shunted with a resistance to approximate an E source than to use an E source. A voltage controlled current source shunted with a resistance will compute faster and cause fewer convergence problems than a voltage controlled voltage source. Also, the resultant nonzero output impedance is more representative of a practical circuit."

In general, using Spice well as a designer tool takes training and time and experience. There is, however, more than one goal in using it. If you are a developer of models for ICs working for an IC manufacturer, you probably need to know Spice extremely well to do the job well. If you are using it more as an end user of ICs and electronic parts, then your needs may be more about verifying that you didn't forget something important (Spice will often "kick you in the head," by offering you surprising results.) You often can avoid knowing too much about using Spice, unless you encounter a very slow convergence or a cryptic error message. Then you are forced to learn something more.

I'm not worried about using a B source like the OP requires. It will almost certainly converge easily. But this does depend (of course) on the rest of the circuit and the referenced nodes' behaviors. So nothing is for sure about this. But it's probably safe for the OP and probably fast enough for their needs. But if there is a problem, there is almost always a way to address it.

jonk
  • 77,059
  • 6
  • 73
  • 185
  • Behavioural sources are very versatile, but they suffer from sluggishness as higher numbers come into play. OTOH, `E` or `G` sources are as fast as they can be. You can verify this with something very simple, like this: `V(a)=pwl 0 0 1 1` + `V(b)=pwl 0 1 1 2`, vs `V(a)=pwl 0 0 1 1k` + `V(b)=pwl 0 1k 1 2k`. – a concerned citizen Nov 11 '17 at 07:52
  • @aconcernedcitizen That is true. So you won't get any argument from me on that score. – jonk Nov 11 '17 at 08:05
  • Agreed with your edits. About the `F=`, I was surprised and I tried it, but it complains. Did you mean `R=`, instead (for behabiourla resistance)? – a concerned citizen Nov 11 '17 at 19:20
  • @aconcernedcitizen Nah. That's me being dumb. I need to fix that. When you first drop down a "bv" from LTSpice on the schematic, it shows things as "V=F(...)". I forgot about that and my memory of the "F" you see there was misplaced. I'll fix my discussion. Thanks!! – jonk Nov 11 '17 at 20:33
  • There is a bit that just struck me: "The expression is assumed by Spice to be mathematically continuous". This may not be entirely true. If you use `if()`, for example, the discontinuity is there, and the engine will try to lower the step in that area so that the derivative will not shout "Timestep too small" (or similar). Which means the continuity is only apparent. The fix for this can be as simple as a few `pF`, or less, capacitor across the offending node, to trick the abrupt change into thinking it needs a bit more time to rise, thus relaxing the dynamic step. Sorry for the many words. – a concerned citizen Nov 12 '17 at 07:42
  • @aconcernedcitizen I added those specific words after checking with Andrei Vladimirescu's "The Spice Book", on page 214. But he is discussing this in the context of the Spice algorithms themselves, where discontinuous functions can cause convergence problems. He doesn't say you can't use them. Just that they are problematic. So I was speaking elliptically to an audience here who isn't likely to be nearly as skilled as you are with Spice. And I did so only after advisement from an expert on the topic. I probably should have phrased it differently, though. – jonk Nov 12 '17 at 08:28
  • I've been promoted! Either that or the "skilled" part can be safely omitted, all the more so as, most likely, my English is too often to blame for any misunderstandings, or misinterpretations. :-) – a concerned citizen Nov 12 '17 at 20:37
  • @aconcernedcitizen Actually, I think you were very, very good at picking out the right things to point up in my own writing. Not a single thing you said was misguided, so far as I can tell. Quite the opposite, really. You are very thoughtful and skilled, I suspect. I'm sure I'd consider you very much a valued friend if we knew each other. – jonk Nov 12 '17 at 20:49
  • I hope I don't prove to be unnecessarily "picky". From my tiny bit of exploring this SE, I noticed your answers to be very detailed and to the point. When that happens, sometimes I get stuck up in details, myself. – a concerned citizen Nov 13 '17 at 09:15
2

The average of \$V_1\$ and \$V_2\$ is $$\frac{V_1 + V_2}{2},$$

so make two VCVS's, each with gain 1/2. Connect the input of one to \$V_1\$ and the other to \$V_2\$, and put their outputs in series.

enter image description here

The Photon
  • 126,425
  • 3
  • 159
  • 304
  • Yes, It worked :) – ifrah Nov 11 '17 at 05:11
  • Ah. One Arb source could do that too. Less clutter and the formula looks exactly like the OP wanted, so probably clearer. – jonk Nov 11 '17 at 06:50
  • 1
    @ThePhoton Depending on the schematic (more complicated, not this one) you may want to use two `G` source and one `R` (or `C` with parallel resistor), which not only will count as one node, only (but three elements), in the matrix solver, but it will be more convergence-friendly (as per the manual). – a concerned citizen Nov 11 '17 at 07:57
  • 1
    @jonk I don't know how well optimized the arb source is. Will LTSpice recognize you've given a linear equation and just fill in some matrix entries, or will it still treat it as potentially non-linear and have to re-compile and re-linearize the source at each solution step? – The Photon Nov 11 '17 at 15:51
  • @aconcernedcitizen, in that case the behavior when the output is loaded would be different from OP's circuit they're trying to model. – The Photon Nov 11 '17 at 15:52
  • @ThePhoton Different Spice implementations do better or worse on this, but the B source was added to open the door to pretty much any function you might want and it is slow. E sources aren't much different. From the LTSpice help, "It is better to use a G source shunted with a resistance to approximate an E source than to use an E source. A voltage controlled current source shunted with a resistance will compute faster and cause fewer convergence problems than a voltage controlled voltage source. Also, the resultant nonzero output impedance is more representative of a practical circuit." – jonk Nov 11 '17 at 17:52
  • @ThePhoton But since the OP wasn't caring about speed and just "wanted something," and I had no idea if the OP would only use 1 or 10 of them, I felt it was completely fair (and probably better, actually) to suggest the use of the B source. For this purpose as asked, it's just too easy to use and I have no reason to believe that all-out speed was the goal. Besides, in this context there is no reason at all to suggest that LTSpice will have any convergence problems with this formula. I'm sure it will just work fine for the OP. – jonk Nov 11 '17 at 17:55
  • 1
    @ThePhoton True, even if one could use a smaller resistor (and a higher value for `G`), but it will be influenced. – a concerned citizen Nov 11 '17 at 19:12
0

How can I build that in LTspice?

The same way you would in real life. Use a non-inverting summing amplifier with a gain of one.

schematic

simulate this circuit – Schematic created using CircuitLab

Figure 1. The non-inverting summing amplifier can be made into an averaging amplifier by setting the gain to one.

How it works:

  • The voltage at the non-inverting input will be the average of R1 and R2.
  • The op-amp is configured as a unity gain follower.
  • The opamp output needs to be able to swing to the maximum and minimum average voltage. That means you need to look at the maximum output swing of the chosen amplifier and set the power supply voltage(s) accordingly.
Transistor
  • 168,990
  • 12
  • 186
  • 385
  • Thanks alot. But is there not any other way of doing this? May be by using E2 source of LTspice? – ifrah Nov 11 '17 at 00:01
  • @ifrah Of course you can do it with LTSpice sources. You don't have to use opamps and resistors and all that this entails -- such as limited compliance current and everything else. You can make the source you want. They don't call them Arbitrary Behavioral Voltage Sources for nothing. – jonk Nov 11 '17 at 00:31