Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

How to measure (using .MEAS) with LTspice?

Status
Not open for further replies.

carbonzit

Active Member
I'm trying to use LTspice to measure some aspects of a simple circuit (attached below) using the .MEAS[URE] command, but I don't know how to get results from it.

As you can see from the simulation, I have the .MEAS command on the circuit. But how do I view the results?

What I want to do is measure the gain of the amplifier (Vout P-P / Vin P-P). .MEAS looks like the way to do this, since it can be set up to give peak-to-peak measurements.

I don't think this can be done by displaying waveforms, as the results are only given as RMS and average values for voltages and currents.

I see that under the File menu there's a choice marked "Execute .MEAS Script" (although this seems to appear and disappear sort of randomly), but it asks for a file to read from.

Help! I have no idea how this command works. The online help is really of no help. Oh, it does explain in great detail the syntax of the statement; however, it doesn't explain how to use the statement. (They seem to assume that the user somehow automatically knows this.)
 

Attachments

  • 3-transistor headphone amp.asc
    2.3 KB · Views: 1,270
hi cz,
I will look thru your circuit, let you know.
Try this for quick way.
Run the sim first
Place the cursor red test probe on the junction of V2 and R6....press and hold down the keyboard 'CTRL' key [ a new black probe will appear] move it to the junction of C2 and RL and the release the CTRL key.... a plot should appear on the Sim.
The plot is the difference between the input and output signals...OK
 
Last edited:
Well, that works, kinda sorta.

Problem is it gives a new trace, which isn't exactly what I want: I want the value (over time) of Vout-Vin, P-P. With a trace, as I said, you can only see the average and RMS values (using CTRL-click).

What I'd really like, as I've been asking for all along, is a decent explanation of these things in a document somewhere, which I haven't yet found (and yes, I have and have looked at that tutorial you sent before: I already had that, and it does not answer a lot of these questions).
 
Have you looked at this document? .MEASURE -- Evaluate User-Defined Electrical Quantities starts on about page 73 of over 200 pages for your reading pleasure. :)

Anyway, downloading the .pdf may help you out.

Ron
 
Have you looked at this document? .MEASURE -- Evaluate User-Defined Electrical Quantities starts on about page 73 of over 200 pages for your reading pleasure. :)

That does not help at all.

Why do people keep suggesting that, linking to that, and insisting that the answers to all my questions lie in that document?

Have you actually looked at that document?

All it is is a PDF of the LTspice on-line help. Nothing more. (And thanks, but I already downloaded that a long time ago.)
 
Well hell, sorry. I was at work so tossed it out there. Yes, I looked at it briefly. Again, sorry it is of no help.

Ron
 
I have the .MEAS command on the circuit. But how do I view the results?
Run the sim, then 'View/ Error log'
Why LTSpice categorises measurement results as 'errors' is a mystery!
 
Run the sim, then 'View/ Error log'
Why LTSpice categorises measurement results as 'errors' is a mystery!

I suspected that might be the case.

However, when I view the error log, I can't find anything that seems to pertain to my .MEAS statement. Perhaps I've made an mistake in that statement? (To try to get the P-P value of my output, I used .meas ac x pp v(n004). However, I'm not sure what the correct usage of the name ("x") is in this statement.)
 
Just delete the 'ac' from your statement so that it reads .meas x pp v(n004) ('cos you're running a .tran analysis, not an ac analysis).
 
Just delete the 'ac' from your statement so that it reads .meas x pp v(n004) ('cos you're running a .tran analysis, not an ac analysis).

OK, that works "a treat" as y'all over on that side of the pond say.

Now, how can I display the gain (i.e., Vout(P-P)/Vin(P-P))? In other words, how do you display expressions that are derived?

============================================
OK, so I have the following statements:

.meas x pp v(input)
.meas y pp v(output)
.meas pp y/x


The first two I understand. Not sure how to display y/x. No matter what I do, the last statement always displays 0.2.

What is the function of the "name" in this statement?

Why don't they explain what the damn statement does in the documentation???

==================================

Updated .asc file is attached with .meas statements. The first two work; the last one doesn't.
 

Attachments

  • 3-transistor headphone amp.asc
    2.5 KB · Views: 659
Last edited:
hi cz,
Look at this image.
Also two asc files that use measure.

I guess you know that with that amp theVoltage gain will not be very meaningful.? because of the different impedances of the source and load.
You should really aim for Power gain
 

Attachments

  • AAesp01.gif
    AAesp01.gif
    50.2 KB · Views: 2,064
  • Measure_vi.asc
    2.3 KB · Views: 848
  • MeasureBW.asc
    2.7 KB · Views: 697
I guess you know that with that amp theVoltage gain will not be very meaningful.? because of the different impedances of the source and load.
You should really aim for Power gain

Yes. Should I use RMS or average values to compute power gain? ((Vout * Iout) / (Vin * Iin).

Regarding the .measure statements you used, I'm a little confused by your use of "avg" to compute the (voltage) gain. I thought that once you obtained the input and output P-P voltage measurements (your tmp1 & tmp2) that these quantities were then both scalars that could simply be divided to obtain the ratio, but it looks like you're taking the average of the ratio, which is ... sorta confusing.
 
Yes. Should I use RMS or average values to compute power gain? ((Vout * Iout) / (Vin * Iin).

Regarding the .measure statements you used, I'm a little confused by your use of "avg" to compute the (voltage) gain. I thought that once you obtained the input and output P-P voltage measurements (your tmp1 & tmp2) that these quantities were then both scalars that could simply be divided to obtain the ratio, but it looks like you're taking the average of the ratio, which is ... sorta confusing.

hi,
You didnt give the y/x a Label name or a 'value' to compute [ie AVG , RMS etc] for the .measure.... I used .measure 'gain' AVG y/x

If you take the pp of two numerical values you will get 0.

Try to avoid the early part of the plot being used in the calculations as it will give misleading results, use the .tran 'time to start saving'
 

Attachments

  • AAesp02.gif
    AAesp02.gif
    42.6 KB · Views: 1,464
  • AAesp03.gif
    AAesp03.gif
    44.5 KB · Views: 1,199
What is the function of the "name" in this statement?
'name' is just an arbitrary (but meaningful) label you choose for the variable you're measuring. In your first statement the name is 'x'.
Once you have some named measurement variables you can define further named variables in terms of the existing ones. So your third statement could read, for example, .meas gain y/x (it doesn't need the 'pp' because your first and second statements have already measured the pp values).
But see Eric's post re not using the initial part of the .tran analysis. As it stands, your first and second statements will cause the pp value to be measured over the whole of the simulation period. Better tostart the measurement at, say, 0.05 secs.
 
Last edited:
So your third statement could read, for example, .meas gain y/x (it doesn't need the 'pp' because your first and second statements have already measured the pp values).

But that doesn't work; it simply gets set to ... something (0.05, which (not so) coincidentally is my time interval in mS). So apparently you can't just put in raw naked variables like that.

And yes, I'd meant to exclude the startup part of the simulation, before things settle down. That certainly helps.

Still trying to figure out how to compute power gain ...
 
Last edited:
Oops! That directive should have read .meas gain param y/x
However, if you want to measure RMS power gain then I'd suggest:- label the node at the R6 input as 'in', label the top of RL as 'out' (using labels is more convenient than trying to remember node numbers) and use these directives:-
.meas pwrin rms V(in)*I(R6)
.meas pwrout rms V(out)*I(RL)
.meas gain param pwrout/pwrin

Edit the simulation command so as to start measurements at, say, 0.1 then run the sim. If you start at 0.1 then that becomes your new effective time origin (time 0 in the waveform plots and measurement results)
 
OK, that seems to work (it reports a power gain of about 111, which seem reasonable).

So "param" is the, what? tag? operator? that allows you to do calculations (i.e., arithmetic) with other variables in a .meas statement?

Gee, wouldn't it be nice if these things were, oh, I don't know, documented somewhere? How are we supposed to find this stuff out? by osmosis?
 
Last edited:
I'm still a beginner with LTSpice and, like you cz, I've struggled with the minimal documentation. As the software has been made freely available I suppose we shouldn't complain (well, not too loudly anyway)!
'param' means 'what follows is/are/involves one or more defined variables'. For example, if you want to run simulations with different values for R1, you can specify the value of R1 as a variable {R} (note the curly brackets) on the schematic and use a directive .param R=68k to set the value of R.

HTH
 
OK, that seems to work (it reports a power gain of about 111, which seem reasonable).

So "param" is the, what? tag? operator? that allows you to do calculations (i.e., arithmetic) with other variables in a .meas statement?

Gee, wouldn't it be nice if these things were, oh, I don't know, documented somewhere? How are we supposed to find this stuff out? by osmosis?

cz,
These labels are documented in the LTS Help files.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top