# LTspice dependent voltage sources circuit

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,

• See Arbitrary Behavioral Voltage Source in help. It's trivial to use. – jonk Nov 11 '17 at 0:41
• I added an answer that describes how to do it. – jonk Nov 11 '17 at 6:56

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

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.

• 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 7:52
• @aconcernedcitizen That is true. So you won't get any argument from me on that score. – jonk Nov 11 '17 at 8: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 7:42

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.

• Yes, It worked :) – ifrah Nov 11 '17 at 5: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 6:50
• @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 7:57
• @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

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.

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.
• 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 0: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 0:31