EmbeddedRelated.com

Hysteresis

Category: Electrical

Hysteresis is the property of a system in which the output depends not only on the current input value but also on the history of that input — specifically, the direction from which the threshold was approached. In electrical contexts, it most commonly refers to a deliberate difference between the turn-on and turn-off thresholds of a comparator, Schmitt trigger, or power-supply supervisor, so that noise near the threshold does not cause rapid, repeated switching.

In practice

A fundamental application in embedded hardware is the Schmitt-trigger input buffer, which is built into the GPIO input cells of many MCUs (for example, many STM32 and AVR pins can be configured to use Schmitt-trigger inputs, though exact availability varies by part number, pin type, and configuration mode). Without hysteresis, a slowly-changing or noisy signal crossing a single threshold can toggle the input many times in a short window, depending on the noise amplitude and signal rate of change. With hysteresis, there is a defined upper threshold (V_T+) and a lower threshold (V_T-); the input only asserts high once V_T+ is crossed and only returns low once the signal falls below V_T-. The separation between the two thresholds is called the hysteresis window or hysteresis band.

Hysteresis is also deliberately added around comparator circuits in firmware or analog hardware for debouncing analog signals -- for instance, a battery voltage monitor that triggers a low-battery warning at 3.2 V but does not clear that warning until voltage recovers to 3.4 V. This prevents the warning from toggling rapidly when the battery voltage hovers near a single threshold, a behavior that would otherwise produce erratic system responses or repeated log entries.

In power electronics and switching regulators, hysteretic control uses the inductor current or output voltage ripple itself as the switching signal. A hysteretic buck controller turns the high-side switch on when the output falls below V_REF - (band/2) and off when it rises above V_REF + (band/2). This approach has very fast transient response but produces a switching frequency that varies with load and component values.

A common firmware pitfall is implementing a threshold comparison in software without any hysteresis, then being surprised by chattering output. The fix is straightforward: apply separate rising and falling thresholds in the comparison logic. The amount of hysteresis must be chosen relative to the expected noise amplitude; too little provides no benefit, and too much causes sluggish response or a system that never transitions back across the lower threshold under legitimate conditions. Tolerance analysis of the threshold components -- resistor dividers, reference voltages -- is important to ensure the hysteresis band behaves as intended across manufacturing variation.

Frequently asked

How do I add hysteresis to a comparator circuit in hardware?
The standard technique is positive feedback: connect a resistor from the comparator output back to its non-inverting input. The ratio of this feedback resistor to the input resistor network sets the hysteresis window, though the exact band depends on the full threshold configuration of the circuit. Many dedicated comparator ICs (such as the LM393 or STLM2903) support this topology directly. Some power-supervisor ICs (like the TPS3837 family) include a built-in hysteresis pin or integrated resistor network.
What is the difference between a Schmitt trigger and a plain comparator?
Both compare an input voltage to a threshold and produce a digital output, but a Schmitt trigger has built-in hysteresis with fixed V_T+ and V_T- thresholds defined by the device. A plain comparator, in its basic external-feedback use case, has a single threshold and relies on external positive feedback to add hysteresis; note that some comparator ICs do include built-in hysteresis and do not require external components for this purpose. In MCU datasheets, 'Schmitt trigger input' on a GPIO pin means the pin has a built-in hysteresis window whose width is device-specific and should be confirmed in the relevant datasheet.
Can hysteresis be implemented in firmware instead of hardware?
Yes. For slowly-changing signals read by an ADC, firmware hysteresis is straightforward: maintain a state variable and apply a higher threshold to transition from low to high and a lower threshold to transition from high to low. This works well for signals where the ADC sampling rate is much faster than the signal rate of change. It is not suitable for fast digital signals directly entering a GPIO pin, where hardware-level Schmitt-trigger hysteresis is needed before the signal is latched.
Why does too little hysteresis cause problems even after I add it?
If the hysteresis window is narrower than the peak-to-peak noise on the signal, the input can still cross both thresholds within a single noise burst and produce multiple transitions. The hysteresis band must exceed the expected noise amplitude by a comfortable margin. Quantifying that margin requires knowing the noise sources -- switching transients, ground bounce, coupled interference -- which in practice means measuring the signal with an oscilloscope under realistic operating conditions, not just at a bench with clean supplies.
What is magnetic hysteresis and is it relevant to embedded systems?
Magnetic hysteresis refers to the lag between applied magnetic field and induced flux density in ferromagnetic core materials, as described by a B-H curve. It is relevant to embedded systems in the context of transformer and inductor core losses: energy is dissipated each switching cycle in proportion to the area of the B-H loop. This affects efficiency and thermal design in switching power supplies and gate drive transformers. It is a separate physical phenomenon from electrical threshold hysteresis, though the underlying concept -- path-dependent behavior -- is the same.

Differentiators vs similar concepts

Hysteresis is sometimes conflated with debouncing, but they are not the same thing. Debouncing (hardware RC filters or firmware timers) suppresses transitions by ignoring the input for a fixed time window after the first edge. Hysteresis suppresses transitions by requiring the signal to move a defined distance in the opposite direction before a new edge is recognized. Debouncing introduces latency proportional to the blanking time; hysteresis introduces no fixed time delay but does require the signal to recover by the full hysteresis band. In practice, mechanical switch debouncing typically uses time-based filtering, while analog signal conditioning typically uses hysteresis.