I want to measure the CMRR in a amplifier. In order to automatize the measurement, I would like to use two AC analysis and alter statemets to change the AC values in the sources, and then collect the measurements to calculate Adiff/Acm.
Thanks for the document.
Actually my āamplifierā is a multi-stage opamp amplifier with one or more internal feedback. So I have decided to follow the most generic way to measure CMRR. Iām using the setup in the Figure, first I measure differential gain adding +0.5/-0.5 AC Voltage in the voltage sources VINP and VINM. Then I zeroed those voltage sources and add 1 AC Voltage in VCM voltage source. The last setup gives me the CM gain. Finally, my CMRR will be Adiff/Acm. Iām thinking in use alter parameter to execute two secuencial AC analysis.
I guess that your procedure cannot be done with the ngspice embedded into Eeschema. The Eeschema/ngspice interface is too limited. The main point is that you can run only one simulation at a time. Altering something, running it in addition and watching and comparing the results is not possible.
You may create the ngspice netlist by Eeschema. If your circuit in Eeschema is ready for simulation, run the first ac simulation and create a netlist. Then do the changes (to your voltage sources ?), run again Eeschema and create a second netlist. And now you may compare what has to be changed from first to second netlist and find a way to do it automatically by adding a .control script. Depending on what you want to change, commands āalterā or āalterparamā may be chosen. In the script you also may do calculations using both results, or plotting. Finally you may add the script to Eeschema for running your sequence automatically by the Tools->Generate Netlist Fileā¦->Spice->Run Simulator procedure.
You may start with the KiCad\share\kicad\demos\simulation\sallen_key\sallen_key.sch example on how to run an ac simulation, and then move on. An example how to use external ngspice is given here: http://ngspice.sourceforge.net/ngspice-eeschema.html#external. And of course you may publish your intermediate results here, if there are more questions.
What if you made two copies of the circuit, one for Diff and one for CM, and then divide each of the two unique OUT nodes? Two separate instances of the same opamp subckt in SPICE behave exactly the same. Or does this not work out for what you want to do?
Basically it is a good idea to run both circuits at the same time! However we have been talking about ac simulation so far. I am not aware of a means which allows to do a division (by a circuit), when running ac. In ac simulation the whole circuit is linearized, division is non-linear. I even do not know what will happen to a divide-by circuit made with a B-Source if it is linearized during the ac simulation. One also should check what happens if you run an ac simulation with multiple voltage sources having the ac flag, maybe by some well-known test circuits.
So your idea might be good if one adds a small script inside of Eeschema/ngspice that deals (divides etc.) with Vout and Vout1. But how to plot its results?
Oh, whups. In another thread he was asking about the .meas command so I thought he was just using that in some form. Yeah, I guess we have no idea what his intended way of viewing the data/result is. I shouldnāt have assumed that.