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?
Oh, cripes. I can't believe the answers.
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.
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.
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.