Circuit VR: Measuring with LTSpice


Usually, with Circuit VR we look at some circuit in detail with simulation — usually LTSpice. This one will be a little meta because I wanted to look at a capability in LTSpice which ironically is very useful, but not often used. Along the way, though, we’ll look at why you get maximum power transfer when your source impedance matches your load impedance. This is something you probably already know about, but it is interesting to look at in simulation if you know how to coax LTSpice — no pun intended — into showing you a meaningful graph.

The circuit is super simple. An AC source and a 50-ohm resistor stand-in for a 40-meter ham transmitter. With 100 volts into a 50-ohm load. So far, so good.

If you look at the peak output voltage and current, you’ll see the load sees 50V (half of the source) and, of course, with a 50-ohm load, 1A of current for a total of 50 watts. If you compute the RMS voltage you can easily find the RMS power, as well (25 watts). Spice will even plot power for you if you use Alt+Click on the schematic — that requires some reconfiguration on some Linux setups where Alt+Click does something else. You can also plot an expression like:


The bad part is the plots that result have a pretty fixed format: some parameter versus time. Sure, you can do math on the Y-axis, but you are always plotting against time. That’s not bad when you have just a single simulation, but what if you want to look at antenna loads ranging between different values?

Comparing Simulations

It is easy to set up Spice to do multiple simulations for comparison. Just change RL’s value from 50 to {R} and add the following line as a Spice directive somewhere on your schematic (you can press S to do that or pick it from the edit menu or the toolbar) :

.STEP PARAM R 1 200 10

This tells Spice to vary R from 1 to 200 in steps of 10 ohms. Now the plot is a mess, even zoomed in.

in LTSpice you can right click on the plot and select one or more steps to go through but when you have a lot, that’s a nightmare. Besides, this is an easy trend to spot, but it would be nice to have a plot of power versus RL.

The answer is the .MEAS or .MEASURE statement (you can shorten it if you like, but you can also use the whole word). There are actually two forms of the .MEAS command. The first one computes a single value. If you use a simulation value it will just pull the latest one, but since there’s only one value that might not be what you want. In our case, though, I’d like to know what the SWR is and the .MEAS command is just right for that.

SWR: Standing Wave Ratio

The reflection coefficient takes this command:

.MEAS Reflect param (R-50)/(R+50)

This works because R doesn’t change during one simulation run and the param keyword tells Spice to look for that kind of variable. Reflect is like a variable name. It could have been anything.

Then computing VSWR (voltage standing wave ratio) is easy:

.MEAS VSWR param (1+abs(Reflect))/(1-abs(Reflect))

The data for these measurements (Reflect and VSWR) will show up in the Spice error log even though they aren’t errors. You can view it from the View menu or just press Control+L.

You can see there is a single value for each step of R. That isn’t a very handy format, but we’ll do better in a minute.

Spice Power

To compare power, we’ll get the RMS power for each run. That’s the second form of .MEAS. You can put certain operations in to look at all the simulation data from a run and do a calculation on it, again collapsing it to a single number. In our case, we’ll use RMS:

.MEAS Vrms RMS(V(Out))

.MEAS Pout param Vrms*Vrms/R

Note you can enter these both at one time using the Spice directive command. Just press Control+Enter to start a new line for each directive. Or you can enter them one at a time if you prefer. Also, don’t forget after you set the text you still have to place it on the schematic. Now if you run the simulation, you’ll have a table of data for Vrms and Pout, as well as the Reflect and VSWR.

The Plot Thickens

Now what you really want is to get a plot of power out and VSWR vs the resistance. To do this, you have to pull up the error log (Control+L). Then right click in the log. If you have .MEAS statements, a menu item will be available that says “Plot .step’ed .meas data.” Opening that will give you a blank plot window.

You can right click to add traces and you’ll see the data there: Reflect, VSWR, Pout, and Vrms. You can add them like you would any other plot and do the usual things with them. But the X-axis will be the step value, just like we wanted. Here’s a plot split into two panes showing the VSWR and power. As you’d expect, at 50 ohms you get a VSWR of 1 (which indicates 1:1) and that’s where you get your peak power, as well.

There is one caveat. Unlike a normal plot, one you produce this way will not update when you rerun the simulation. You’ll have to recreate the plot by hand if you rerun the simulation. Incidentally, if you are just trying to get .MEAS data and you are doing a lot of steps, you can reduce the amount of time you are waiting by not saving all the data. It also helps if you clear the normal plot pane so you don’t spend a lot of time redrawing.

Here’s the final schematic. You can download the files, as usual, from GitHub:

And Then…

There’s plenty more about the .MEAS command. You can have it pick a value when a certain condition hits or pick out a range of values. In addition to RMS, you can get the average, minimum, maximum, and peak to peak value. You can also print out single values which can be useful if you want a value when some condition hits. You can also make the measurement only valid for a certain kind of analysis (like a DC or a TRANS). You can read all the details on the help page. But I find I don’t use much of those features since everything gets plotted on the screen now, anyway.

We’ve talked some about impedance matching before, by the way. In this case, the result wasn’t as interesting as the way to get LTSpice to create the right plot. We looked at basically the same circuit before (at DC and without the nice graphs) and discussed Thevenin equivalence (which this is an example of) quite some time ago.


Source link

Leave a Reply

Your email address will not be published. Required fields are marked *