# Comparator with hysteresis

#### Ian0

Joined Aug 7, 2020
8,947
I'm trying to simulate a comparator in LTSpice. I'm actually trying to simulate the comparator in an LPC15xx microcontroller. It has programmable hysteresis of 5mV, 10mV or 20mV.
Obviously, I could make the hysteresis by a feedback resistor from output to non-inverting input, but the amount of hysteresis then changes when I vary any of the other resistor values.
I'm thinking that I could put a SPICE Voltage source in series with one of the inputs, then use the state of the output to toggle the value of the voltage source between two different values, but I don't know how to do that. Could someone please help me out?

#### Bordodynov

Joined May 20, 2015
3,117
LTspice has a built-in hysteresis element. Take three such elements with hysteresis values of 5 mV, 10 mV and 20 mV. Use the logic circuit (using the two control signals) to select the desired comparator output.
It's not a real scheme, but it's easier that way.

#### Alec_t

Joined Sep 17, 2013
14,009
Here's an example:

Edit: Note that parameter h is half the hysteresis value.

Last edited:

#### Ian0

Joined Aug 7, 2020
8,947
Where did you find that comparator? I typed in "comp" to the search box, and didn't find one like that!

#### Papabravo

Joined Feb 24, 2006
20,609
@Alec_t How is it that your threshold value, vt is set to 0, but in the waveform plots it looks like it is 2.5 Volts? I know that vt will be (vhigh-vlow)/2 if they are not the default of 1 and 0, but I guess that selection of vhigh and vlow overrides any value that you assign to vt. It might be better to do nothing at all with vt in that case.

Last edited:

#### Papabravo

Joined Feb 24, 2006
20,609
Where did you find that comparator? I typed in "comp" to the search box, and didn't find one like that!
Digital

The help page is in the index under: A. Special Functions

#### Ian0

Joined Aug 7, 2020
8,947
OK. Getting somewhere now.
It's called my comparator A1, where do I put the "vhigh=15 vlow=0 vt=0 vh=20m" ?

#### ericgibbs

Joined Jan 29, 2010
18,236
Hi Ian,
This video is a good tutorial on Digital logic.
E

#### ericgibbs

Joined Jan 29, 2010
18,236
hi,
A basic example.
E

#### Attachments

• 662 bytes Views: 8
Last edited:

#### Papabravo

Joined Feb 24, 2006
20,609
OK. Getting somewhere now.
It's called my comparator A1, where do I put the "vhigh=15 vlow=0 vt=0 vh=20m" ?
Right-click on the component and add the parameters to one or two of the empty fields <Value> or <Value2>. You do this by right clicking on the field, which allows you to enter text. Check the Vis box by hovering over it and right clicking

You could also use the <SpiceLine> and <SpiceLine2> fields since they all get concatenated together in the final netlist. Which you can "view" via the menu option "View" | "SPICE Netlist" menu command.

#### Alec_t

Joined Sep 17, 2013
14,009
Where did you find that comparator?
It's just the default differential Schmitt trigger, in the 'Digital' folder.

#### Papabravo

Joined Feb 24, 2006
20,609
It's just the default differential Schmitt trigger, in the 'Digital' folder.
Yeah. Like everybody knows where that is except the folks that don't.

#### Alec_t

Joined Sep 17, 2013
14,009
How is it that your threshold value, vt is set to 0, but in the waveform plots it looks like it is 2.5 Volts?
vt is the transition point for the difference between the two inputs of the diffSchmitt trigger.

Last edited:

#### Alec_t

Joined Sep 17, 2013
14,009
where do I put the "vhigh=15 vlow=0 vt=0 vh=20m" ?
Right click on the diffschmitt symbol to edit the values.

Edit: Papa beat me to it!

Last edited:

#### Ian0

Joined Aug 7, 2020
8,947
Hi Ian,
This video is a good tutorial on Digital logic.
E
Thanks. I'll have a look when I've finished listening to Sounds of the Sixties. I don't think our internet connection will manage radio and a video both at once.

#### Papabravo

Joined Feb 24, 2006
20,609
vt is the transition point for the difference between the two inputs of the Schmitt trigger.
That is funny because that is not the way the help file reads:

A. Special functions.
The Schmitt trigger devices have similar output characteristics as the gates. Their trip points are specified with instance parameters Vt and Vh. The low trip point is Vt-Vh and the high trip point is Vt+Vh.

Also for the single input SCHMITT device, which netlists the same as the differential SCHMITT, what exactly is the difference between the two inputs, one of which does not exist?

I thought that Vt was the threshold voltage for the logic devices, with the default value I mentioned in an earlier post, but that may be incorrect. It seems that parameter is called "Ref".

It may be that the single input SCHMITT and the differential input SCHMITT treat the parameter differently. Investigation is warranted.

Last edited:

#### Alec_t

Joined Sep 17, 2013
14,009
It may be that the single input SCHMITT and the differential input SCHMITT treat the parameter differently.
I believe they do. Intuitively, I initially tried vt=2.5 and the output stayed at 0, despite the ramped + input going both below and above the - input by more than the hysteresis amount.
I wonder if the single input Schmitt is treated as a diffSchmitt with an invisible - input at 0V?

#### Ian0

Joined Aug 7, 2020
8,947
Marvellous! Got all the parameters in the right place, and now it's been sat there doing N-R iterations and fill-ins for the last half hour.

#### Papabravo

Joined Feb 24, 2006
20,609
I believe they do. Intuitively, I initially tried vt=2.5 and the output stayed at 0, despite the ramped + input going both below and above the - input by more than the hysteresis amount.
I wonder if the single input Schmitt is treated as a diffSchmitt with an invisible - input at 0V?
The input is not actually invisible from the point of view of the netlist. The implementation of both devices is with an 8-Input one output construct. If you look at a netlist rendering you will see how that is a reasonable hypothesis. There are additional rules about how unconnected inputs or inputs connected to Global Node 0 aka GROUND are handled, which would be consistent with that interpretation. I had to read the Help pages VERY carefully to see the difference between Vt and Ref. I believe that the Vt parameter does not apply to the non-SCHMITT devices and no error is ever thrown if you put on a device that does not use it.

Last edited: