Comparator with hysteresis

Thread Starter

Ian0

Joined Aug 7, 2020
9,667
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,177
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.
 

Thread Starter

Ian0

Joined Aug 7, 2020
9,667
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
21,157
@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:

Thread Starter

Ian0

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

Papabravo

Joined Feb 24, 2006
21,157
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

1639338192651.png

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.
 

Papabravo

Joined Feb 24, 2006
21,157
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,280
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?
 

Thread Starter

Ian0

Joined Aug 7, 2020
9,667
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
21,157
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:
Top