Electronic – Add a trace from a directive in LTSpice

ltspicespice

I have a circuit in LTSpice in which I want to measure some differential voltages, currently I'm manually adding the traces using the "Add Trace" menu in the plot view and writing its expressions.

I would like to know if there's a way to do this using a directive so that every time I run the simulations those traces are automatically added.

Best Answer

One method would be to plot the quantity you need, be it a single trace or a mathematical combination of more (maybe also plot whatever other traces you need), then click on the waveform viewer to activate it (if you haven't already) and then click on the Save icon in the toolbar (or in the File menu). This will save the .plt file with the plot settings @Fizz was talking about. This way, whenever you first open up the schematic and run it, or click on the Add trace, the plot window will open up with the saved traces already selected and plotted. The downside is that, once you plot/delete traces, the waveforms will change and, if you need to replot some saved ones, you'll have to manually add them. The minor upside to this is that, if you don't care about the recently added traces, you can close the waveform viewer and click on Add trace, which will, again, open up the previously saved traces and plot them, at the cost of losing the recently plotted ones.

A similar method is to modify the default, global .plt file, but it might not be such a great idea. Still, if you want to, activate the waveform window and then go to the menu in Plot Settings > Edit plot defs file.

Another method is to use behavioural sources, but these, as versatile as they are, come at a cost in that they get slower as the dynamic range gets higher (both frequency-, or time-wise, and value-wise). But, if you have more involved quantities to plot (some bogus example: (V(A)*V(C)+V(B)*V(D))/(I(R1)-I(R2))*sqrt(3)/2), and this doesn't go above hundreds or thousands, in value, or it doesn't have very high frequency components compared to the simulation window, it's safe to use. Then, plotting the formula is as easy as plotting the voltage of the behavioural source.