I am looking for a way to have LTSpice report a "Pass" or "Fail" ("1" or "0") in the error log if a measured voltage drops below a preset constant reference value.

I have a model I made of a transmission line and I would like LTSpice to be able to identify when the amplitude of the signal being transmitted over the simulated cable drops below the receiver's detection threshold. Is there a method to do this in LTSpice, perhaps using the CROSS command? I have been trying to solve this for some time but have not had any success as of yet.

EDIT: To clarify, I would like to have a variable labeled "test_result" that would be set to "1" if the signal does not drop below the threshold, and would be set to "0" if it does, and the value of "test_result" should be shown in the LTSpice error log.


I did this with 1 bsource and an SR-latch. The results are shown below, the first source is just a sine wave with increasing amplitude. The second b-source detects whether the threshold is above 7mV (vout2 node) and the latch triggers the first time vout2 goes high and then stays high. Then measure it at the end of the file.

This is not the same logic that you want but the functionality is the same. I don't see a way to do this with only b-sources, my attempts by using a delay yielded results with NaN's (which I didn't even know LT spice could produce until now).

* C:\Draft7.asc
B1 Vout 0 V=time*0.01*sin(2*pi*time*10)
B2 Vout2 0 V=if(V(vout)<0.007,0,1)
A1 Vout2 0 0 0 0 0 Vout3 0 SRFLOP
.tran 1

If you wanted to you could use the netlist below to generate a part so it you could include it in other files and containerize it.

B2 Vinternal 0 V=if(V(Vin)<V(condition),0,1)
A1 Vinternal 0 0 0 0 0 test_result 0 SRFLOP

You cannot do what you describe with a .meas statment (which is why I posted the first example):

The only option with a .meas statement is to have a conditional

.meas TRAN x FIND time WHEN V(vout)=0.007 CROSS=1

or rise would work as well (which measures the time of the rising edge)

.meas TRAN x FIND time WHEN V(vout)=0.007 RISE=1

from the above example this prints out the time of the first crossing of vout, that isn't what you want, you want a pass/fail.

So you run the cross

.meas TRAN xx FIND if(time<1,0,1) WHEN V(vout2)=0.007 CROSS=1

This is the output of the simulator not exactly what you want but it does have a conditional

xx: if(time<1,0,1)=0 at 0.721136

However what happens if there isn't a crossing? If we change cross to 8 (there are only six crossings) it does not meet the condition.

.meas TRAN x FIND time WHEN V(vout)=0.007 CROSS=8

This is what the simulator outputs:

Measurement "x" FAIL'ed

There isn't a way to measure when a CROSS or a RISE fails because when the .meas statement does not find the condition it fails the whole condition so there is only a way to find if a condition is met by using .meas statements. If the condition fails, you don't know why it failed only that it did fail.

enter image description here

  • \$\begingroup\$ Thank you, though this is not really what I'm looking for. I'm looking for a .meas command that will give me a 1 or 0 depending on whether or not the voltage drops below a certain level. The circuit itself is fixed, I cannot add to it. \$\endgroup\$ – DerStrom8 Oct 24 '17 at 22:09
  • \$\begingroup\$ I was very clear in what I was asking for, both in the title and in the body. You gave me a circuit implementation when I stated clearly that I needed a command that would report to the error log. \$\endgroup\$ – DerStrom8 Oct 25 '17 at 10:51
  • \$\begingroup\$ The reason why I posted the answer I did is because what you want is unavailable with .meas statments. See edit \$\endgroup\$ – Voltage Spike Oct 25 '17 at 17:50
  • \$\begingroup\$ Thank you for the edit, that's more like what I was looking for. I currently have a statement that behaves similarly (if the value does not cross the threshold then the measurement fails, but if it does it returns the voltage of the waveform the moment it crosses, which is equal to the threshold itself). I appreciate your effort and your suggestions. \$\endgroup\$ – DerStrom8 Oct 25 '17 at 19:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.