1. 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.
    Dismiss Notice

How to measure (using .MEAS) with LTspice?

Discussion in 'Circuit Simulation & PCB Design' started by carbonzit, Jul 28, 2011.

  1. carbonzit

    carbonzit Active Member

    Joined:
    Mar 19, 2011
    Messages:
    1,958
    Likes:
    13
    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.)
     

    Attached Files:

  2. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,180
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    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: Jul 28, 2011
  3. carbonzit

    carbonzit Active Member

    Joined:
    Mar 19, 2011
    Messages:
    1,958
    Likes:
    13
    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).
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Reloadron

    Reloadron Well-Known Member Most Helpful Member

    Joined:
    Dec 23, 2009
    Messages:
    6,777
    Likes:
    281
    Location:
    Cleveland, Ohio USA

    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
     
  6. carbonzit

    carbonzit Active Member

    Joined:
    Mar 19, 2011
    Messages:
    1,958
    Likes:
    13
    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.)
     
  7. Reloadron

    Reloadron Well-Known Member Most Helpful Member

    Joined:
    Dec 23, 2009
    Messages:
    6,777
    Likes:
    281
    Location:
    Cleveland, Ohio USA
    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
     
  8. carbonzit

    carbonzit Active Member

    Joined:
    Mar 19, 2011
    Messages:
    1,958
    Likes:
    13
    Well, I appreciate your effort anyhow.

    And this LTspice tutorial that's been suggested doesn't even mention .MEAS.
     
  9. alec_t

    alec_t Well-Known Member Most Helpful Member

    Joined:
    Jul 10, 2011
    Messages:
    9,252
    Likes:
    1,218
    Location:
    Cardiff, Wales
    Run the sim, then 'View/ Error log'
    Why LTSpice categorises measurement results as 'errors' is a mystery!
     
  10. carbonzit

    carbonzit Active Member

    Joined:
    Mar 19, 2011
    Messages:
    1,958
    Likes:
    13
    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.)
     
  11. alec_t

    alec_t Well-Known Member Most Helpful Member

    Joined:
    Jul 10, 2011
    Messages:
    9,252
    Likes:
    1,218
    Location:
    Cardiff, Wales
    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).
     
  12. carbonzit

    carbonzit Active Member

    Joined:
    Mar 19, 2011
    Messages:
    1,958
    Likes:
    13
    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.
     

    Attached Files:

    Last edited: Jul 28, 2011
  13. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,180
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    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
     

    Attached Files:

  14. carbonzit

    carbonzit Active Member

    Joined:
    Mar 19, 2011
    Messages:
    1,958
    Likes:
    13
    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.
     
  15. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,180
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    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'
     

    Attached Files:

  16. alec_t

    alec_t Well-Known Member Most Helpful Member

    Joined:
    Jul 10, 2011
    Messages:
    9,252
    Likes:
    1,218
    Location:
    Cardiff, Wales
    '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: Jul 29, 2011
  17. carbonzit

    carbonzit Active Member

    Joined:
    Mar 19, 2011
    Messages:
    1,958
    Likes:
    13
    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: Jul 29, 2011
  18. alec_t

    alec_t Well-Known Member Most Helpful Member

    Joined:
    Jul 10, 2011
    Messages:
    9,252
    Likes:
    1,218
    Location:
    Cardiff, Wales
    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)
     
  19. carbonzit

    carbonzit Active Member

    Joined:
    Mar 19, 2011
    Messages:
    1,958
    Likes:
    13
    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: Jul 29, 2011
  20. alec_t

    alec_t Well-Known Member Most Helpful Member

    Joined:
    Jul 10, 2011
    Messages:
    9,252
    Likes:
    1,218
    Location:
    Cardiff, Wales
    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
     
  21. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,180
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    cz,
    These labels are documented in the LTS Help files.
     

Share This Page