* Z:\home\khalils\Downloads\files\data\raw_asc\27009afc9b0c_Comparator-with-hysteresis-window-shifted-from-origin.asc
* Generated by LTspice 26.0.1 for Windows.
* Assume Vcc = 10V, Vee=0 and rail to rail comparator.\n \nWorkings:\n1) When Vout is HIGH, then Vout = 10V, Rh and Rx are in parallel and\nVa = Ry/(Ry + Rx//Rh) Vcc = 13.3k/21.71k* 10 = 7V.\n2) If Vout > 7V, then Vout goes LOW and Vout =0V. Now Ry and Rh are in parallel and\nVa = (Ry//Rh)/(Rx + Ry//Rh) Vcc = 6.65k/16.65k * 10 = 4V.\n3) If Vout < 4V, then Vout goes HIGH again and the cycle repeats\n \nNotes:\n1) Hysteresis window width is 3V.\n2) Hysteresis window is shifted to the right of the orgin. Useful for light sensors.\n3) Hysteresis window is [4, 7] V.\n \nVin = Signal\nVh = Upper threshold of hysteresis cylce. When Vin > Vh, U1 goes low\nVL = Lower threshold of hysteresis cylce. When Vin < VL, U1 goes high\nRh = Hysteresis level resistor\n \nHow to design:\n1. Select Vcc, VL, Vh.\n2. Set Rx. Rx = user set (arbitrarily)\n3. Find Rh from Rh/Rx = VL/(Vh-VL)\n4. Find Ry from Ry/Rx = VL/(Vcc-Vh)\n \nIn the example:\n1. Vcc = 10V, VL = 4V, Vh=7V.\n2. Rx = 10k.\n3. Rh = 1.33 Rx\n4. Ry = 1.33 Rx
* Comparator with hysteresis: shifted hysteresis window.
* A
* Library below included based on ModelFile attribute of instance XU1 (C:\users\khalils\AppData\Local\LTspice\lib\sym\Comparators\LT1018.asy)
V3 Vcc 0 10
Rx N002 Vcc 10k
V1 Vin 0 SINE(0 10 1)
XU1 N002 Vin Vcc 0 N001 LT1018 ;pnba In+)In-)V+)V-)OUT
Ry N002 0 13.3k
Rh N001 N002 13.3k
.tran 1
.lib LT1018.sub
.backanno
.end

* LTspice schematic (.asc):
Version 4
SHEET 1 1716 804
WIRE -304 -32 -304 -64
WIRE -304 64 -304 48
WIRE 160 112 160 80
WIRE 128 128 -304 128
WIRE 320 144 192 144
WIRE 128 160 80 160
WIRE -304 176 -304 128
WIRE 160 224 160 176
WIRE -304 288 -304 256
WIRE -64 304 -112 304
WIRE 80 304 80 160
WIRE 80 304 16 304
WIRE 192 304 80 304
WIRE 320 304 320 144
WIRE 320 304 272 304
WIRE 80 336 80 304
WIRE 80 448 80 416
SYMBOL Comparators\\LT1018 160 144 R0
SYMATTR InstName U1
SYMBOL res 64 320 R0
SYMATTR InstName Ry
SYMATTR Value 13.3k
SYMBOL res 32 288 R90
WINDOW 0 0 56 VBottom 2
WINDOW 3 32 56 VTop 2
SYMATTR InstName Rx
SYMATTR Value 10k
SYMBOL res 288 288 R90
WINDOW 0 0 56 VBottom 2
WINDOW 3 32 56 VTop 2
SYMATTR InstName Rh
SYMATTR Value 13.3k
SYMBOL voltage -304 160 R0
WINDOW 123 0 0 Left 0
WINDOW 39 0 0 Left 0
SYMATTR InstName V1
SYMATTR Value SINE(0 10 1)
SYMBOL voltage -304 -48 R0
WINDOW 123 0 0 Left 0
WINDOW 39 0 0 Left 0
SYMATTR InstName V3
SYMATTR Value 10
FLAG -304 64 0
FLAG -304 -64 Vcc
FLAG 160 80 Vcc
FLAG -304 288 0
FLAG 80 448 0
FLAG -112 304 Vcc
FLAG 160 224 0
FLAG -304 128 Vin
TEXT -200 -96 Left 2 !.tran 1
TEXT 464 -24 Left 2 ;Assume Vcc = 10V, Vee=0 and rail to rail comparator.\n \nWorkings:\n1) When Vout is HIGH, then Vout = 10V, Rh and Rx are in parallel and\nVa = Ry/(Ry + Rx//Rh) Vcc = 13.3k/21.71k* 10 = 7V.\n2) If Vout > 7V, then Vout goes LOW and Vout =0V. Now Ry and Rh are in parallel and\nVa = (Ry//Rh)/(Rx + Ry//Rh) Vcc = 6.65k/16.65k * 10 = 4V.\n3) If Vout < 4V, then Vout goes HIGH again and the cycle repeats\n \nNotes:\n1) Hysteresis window width is 3V.\n2) Hysteresis window is shifted to the right of the orgin. Useful for light sensors.\n3) Hysteresis window is [4, 7] V.\n \nVin = Signal\nVh = Upper threshold of hysteresis cylce. When Vin > Vh, U1 goes low\nVL = Lower threshold of hysteresis cylce. When Vin < VL, U1 goes high\nRh = Hysteresis level resistor\n \nHow to design:\n1. Select Vcc, VL, Vh.\n2. Set Rx. Rx = user set (arbitrarily)\n3. Find Rh from Rh/Rx = VL/(Vh-VL)\n4. Find Ry from Ry/Rx = VL/(Vcc-Vh)\n \nIn the example:\n1. Vcc = 10V, VL = 4V, Vh=7V.\n2. Rx = 10k.\n3. Rh = 1.33 Rx\n4. Ry = 1.33 Rx
TEXT -344 -168 Left 4 ;Comparator with hysteresis: shifted hysteresis window.
TEXT 56 280 Left 2 ;A