Electronic – LTSpice: Pass/Fail in Error Log if Voltage < Constant Reference

ltspicetransmission line

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.

Best Answer

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
.backanno
.end

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