Comparator with hysteresis – part 2

This is the circuit:


How it works?

Voltage Uin is going up, but still lower than our trigger level (Uh), then transistor is on, conducts, meaning that  R1 is shorted to ground.

Voltage Uin still going up, and when the trigger level is reached, transistor is going off, and voltage on inverting input of comparator is going higher, which increases the speed of of voltage dropping in the output of comparator.
When Uin  > Uhigh (Uh) then Uout = „0”
When Uin < Ulow (Ul) to Uout = „1” almost Uin
R1 is for setting the lower voltage of comparator switching. Upper voltage is set  by potentiometer P1.
How to calculate R1?
Let’s split P1 on two parts, upper: R3 and lower R2.
R2 – you can calculate when you know Uh and the value of potentiometer P1.
R1 you can calculate when you know Ul, and the values of R2 and R3:
R1=[(Uref*P)-(R2*Ul)] / (Ul-Uref)
When  you don’t know Ul but you know R1 then:
Ul=Uref*(R1+P) / (R1+R2)
You can see that in tables below:

Uh= 14,44 Uh= 14,44
Ul= 13,80 R1= 1 000
Uref= 2,5 Uref= 2,5
P= 100 000 P= 100 000
R3= 82686,98 R3= 82686,98
R2= 17313,02 R2= 17313,02
R1= 980,5604 Ul= 13,788

This is the easiest histeresis to calculate in the whole world.
It is important that:
20V> Uin >5V
20V > Uh > Ul > 5V.
Why? When Uin is higher than 5V then LM393 works properly and the MOSFET transistor also works properly.
Lower than 20V, because if you give more than 20V on the gate of the MOSFET – you can destroy it.
Transistor for histeresis: practically any kind of N-MOSFET. I am using IRF640.