Author Topic: Generic Comparator in LTSpice  (Read 3255 times)

0 Members and 1 Guest are viewing this topic.

Offline Zero999Topic starter

  • Super Contributor
  • ***
  • Posts: 19533
  • Country: gb
  • 0999
Generic Comparator in LTSpice
« on: March 27, 2023, 10:10:06 pm »
Someone asked me about a generic comparator in SPICE, so I thought I would make a thread about it.

The most obvious way is to use the generic op-amp as a comparator. If the output voltage is to be limited to the supply rails, then the level2 model is required, otherwise the output will swing to extreme voltages, as the model is deigned to be used with negative feedback, which will inherently limit the voltage.

A less obvious solution is to use the diffschmtbuf model, which is in the [Digital] section. It enables the high and low resistances and voltages to be configured to simulate an open-collector, or  push-pull output. It also has adjustable hysteresis, which is handy, as many real comparators have a fixed hysteresis.

I did include the simplest open-collector I can think of, which is simply a behavioural resistor, which changes its value from 1T Ohm, to 1 Ohm, when the voltage on the non-inverting input is below the inverting input.
1 = NON-INVERTING INPUT
2 = INVERTING INPUT
3 = POSITIVE POWER, which isn't used.
4 = NEGATIVE POWER, the point one side of the behavioural resistor is connected to.
5 = OPEN COLLECTOR OUTPUT, the other side of the resistor.

.SUBCKT Comparator  1 2 3 4 5
 RComp 4 5 R = {if(V(1)<V(2),1,1T)} ;Behavioural resistor.
.ends Comparator

I know there are more accurate ways  to model a comparator. I just posted the simplest one, as it was for an LTSpice beginner.

It also demonstrates how to use a net list to put voltages in a schematic, without drawing them.

For example the following line creates a voltage source called psu, which is connected between 0V and +V and has a DC voltage of 5V.
Vpsu +V 0 5V

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf