Electronic – How to make an ideal comparator in LTspice

ltspice

For fast simulations I sometimes need an ideal comparator.
I guess it is not a built-in component.
How can it be implemented by ideal sources or VCVS ect.?

Best Answer

First create a B-source

Then set the value of the B-source to an expression like below:

enter image description here

Now B1 is the comparator with 1V/0V output.

Another example function can be something like:

V{if(V(Vref)>0.2, cos(12*time),cos(36*time))}

I don't know how it can be done by using VCVS.