The comparator is a circuit that compares one analog signal with another analog signal or a reference voltage and outputs a binary signal based on the comparison. The comparator is basically a 1-bit analog-to-digital converter
Figure below shows a typical configuration for a comparator that does not use hysteresis. This configuration uses a voltage divider (Rx and Ry) to set up the threshold voltage. The comparator will compare the input signal (Vin) to the threshold voltage (Vth). The comparator input signal is applied to the inverting input, so the output will have an inverted polarity. When the Vin > Vth the output will drive to the negative supply (GND or logic low in this example). When Vin < Vth the output will drive to the positive supply (Vcc = 5V or logic high in this case). This simple method can be used to determine if a real world signal such as temperature is above some critical value. However, this method has a shortcoming. Noise on the input signal can cause the input to transition above and below the threshold causing an erratic output.
The following shows the output of a comparator without hysteresis with a noisy input signal. As the input signal approaches the threshold (Vth = 2.5V), it transitions above and below the threshold multiple times. Consequently, the output transitions multiple times. In practical systems, the multiple transitions can create problems. For example, consider the input signal to be temperature and the output to be a critical monitor which is interpreted by a microcontroller. The multiple output transitions do not provide a consistent message to the microcontroller (e.g. whether temperature at a critical level or not). Furthermore, consider that the comparator output could be used to control a motor or valve. This erratic transitioning near the threshold would cause the valve or motor to be turned on and off multiple times during the critical transition.
The following illustrates the output of a comparator with hysteresis with a noisy input signal. The input must transition above the upper threshold (VH = 2.7V) for the output to transition to logic low (0V). The input must also transition below the lower threshold for the output to transition to logic high (5V). The noise in this example is ignored because of the hysteresis. However, if the noise were larger than the hysteresis range (2.7V - 2.3V) it would generate additional transitions. Thus, the hysteresis range must be wide enough to reject the noise in your application. Section 2.1 provides a method for selecting components to set the thresholds according to your application requirements.