LM339 Comparator Tutorial

#lm339 #comparator #voltage comparison #hysteresis #noise immunity #output stage #circuit design #analog circuits #signal conditioning #internal circuitry

1. Key Features and Specifications

Key Features and Specifications

Electrical Characteristics

The LM339 is a quad differential comparator with a wide single-supply voltage range of 2V to 36V or dual supplies of ±1V to ±18V. Its input bias current is typically 25 nA, while the input offset current is 5 nA, making it suitable for precision applications. The device exhibits a low input offset voltage of 2 mV (max) and a high voltage gain of 200 V/mV, ensuring accurate comparisons even for small differential signals.

$$ V_{out} = \begin{cases} V_{CC} & \text{if } V_+ > V_- \\ 0 & \text{if } V_+ < V_- \end{cases} $$

Propagation Delay and Response Time

The propagation delay of the LM339 is 1.3 μs (typical) for a 5 mV overdrive, which is critical for high-speed switching applications. The response time varies with the overdrive voltage, as described by:

$$ t_{resp} = \frac{C_L \cdot \Delta V}{I_{sink}} $$

where CL is the load capacitance, ΔV is the output voltage swing, and Isink is the output sink current (typically 6 mA).

Input Common-Mode Range

The LM339 supports an input common-mode range that includes ground (0V), even when operating from a single supply. This allows direct comparison of signals near ground potential, a feature not available in many op-amp-based comparators. The range extends to VCC - 1.5V, enabling flexibility in industrial and automotive systems.

Open-Collector Output

The open-collector output configuration permits wired-OR connections and interfacing with higher-voltage systems (up to 36V independent of the supply voltage). This is particularly useful in:

Temperature Stability

The LM339 operates across a -25°C to +85°C industrial temperature range, with key parameters like input offset voltage drifting by only 7 μV/°C (typical). This stability is achieved through on-chip trimming and a balanced differential input stage.

Power Consumption

With a quiescent current of 0.8 mA per comparator (typical at 5V), the LM339 achieves low-power operation. The current remains relatively constant across the supply range due to the absence of a constant-gm bias circuit, making it ideal for battery-powered systems.

Key Specifications Summary

Parameter Min Typ Max Unit
Supply Voltage 2 - 36 V
Input Offset Voltage - 1 5 mV
Input Bias Current - 25 100 nA
Response Time (5mV overdrive) - 1.3 3 μs

Pin Configuration and Functional Diagram

The LM339 is a quad differential comparator with an open-collector output stage, allowing flexible interfacing with various logic families and loads. Its pinout and internal structure are critical for proper integration into analog and mixed-signal circuits.

Pinout Description

The 14-pin DIP package follows this configuration:

Internal Functional Diagram

The device contains four independent comparators sharing common power rails. Each comparator consists of:

  1. Differential input stage with PNP transistors (Q1-Q2) providing wide common-mode range
  2. Current mirror load (Q3-Q4) converting differential to single-ended signal
  3. Output stage with NPN pull-down transistor (Q5) and open collector

The input stage's PNP configuration allows the LM339 to handle input voltages down to 0.3V below ground (VEE), while the output can swing up to 36V independent of VCC.

Key Electrical Characteristics

$$ V_{ICR} = (V_{EE} - 0.3V) \text{ to } (V_{CC} - 1.5V) $$

Where VICR is the input common-mode range. The output saturation voltage follows:

$$ V_{OL} = I_{OL} \times R_{ON} $$

With typical RON ≈ 16Ω for the output transistor when sinking 6mA.

Package Variants

Beyond the standard 14-pin DIP, the LM339 is available in:

All variants maintain identical pin numbering and functional characteristics, with thermal considerations being the primary differentiator in package selection.

Pin Configuration and Functional Diagram in LM339 Comparator Tutorial
Diagram Description: The diagram would physically show the 14-pin DIP package layout with labeled pins and the internal functional blocks of the four comparators with their shared power rails.

Typical Applications and Use Cases

Voltage Level Detection

The LM339 excels in voltage monitoring applications where precise threshold detection is required. When configured as an open-collector comparator, the output transitions low when the input voltage crosses a predefined reference. A common implementation involves a resistive divider to set the reference voltage (VREF):

$$ V_{REF} = V_{CC} \cdot \frac{R_2}{R_1 + R_2} $$

For instance, in battery-powered systems, an LM339 can trigger a low-battery warning when the supply voltage drops below 3.0V. Hysteresis is often added via positive feedback to prevent oscillation near the threshold:

$$ V_{HYST} = \frac{R_3}{R_4} \cdot (V_{OH} - V_{OL}) $$

Window Comparators

Dual or quad LM339 packages enable window comparator circuits that detect whether a signal lies within a specified voltage range. Two comparators are configured with different thresholds (VL and VH), and their outputs are logically combined. This is particularly useful in industrial control systems for out-of-range alarm generation.

Input Signal VL VH

Zero-Crossing Detectors

In AC signal processing, the LM339's fast response time (typically 1.3μs) makes it suitable for zero-crossing detection. The inverting input is grounded, while the non-inverting input receives the AC signal through a current-limiting resistor. The output generates a clean square wave synchronized with the AC waveform's zero crossings, essential for phase-controlled rectifiers and dimmers.

Relay and MOSFET Drivers

The open-collector output can directly drive small relays or MOSFET gates when paired with a pull-up resistor. A flyback diode is critical when driving inductive loads to protect the comparator from voltage spikes:


* LM339 Relay Driver Example
VCC 1 0 DC 12
R1 1 2 10K
R2 2 0 10K
U1 3 2 4 LM339
D1 4 5 1N4007
RLY 5 0 RELAY
.model RELAY SW(Ron=0.1 Roff=1Meg Vt=5 Vh=2)
    

Analog-to-Digital Conversion

Multiple LM339 comparators can construct flash ADCs by comparing an input against a resistor ladder reference network. For a 2-bit ADC, three comparators generate thermometer code at speeds unattainable by successive-approximation ADCs. The propagation delay mismatch between comparators (typically ±2ns) must be accounted for in high-speed designs.

Oscillators and Pulse Generators

When configured with RC timing networks, the LM339 can generate square waves or pulses. The oscillation frequency is determined by:

$$ f = \frac{1}{2RC \ln\left(\frac{V_{CC} - V_{TL}}{V_{CC} - V_{TH}}\right)} $$

where VTH and VTL are the upper and lower hysteresis thresholds. This configuration is widely used in switch-mode power supply controllers.

Typical Applications and Use Cases in LM339 Comparator Tutorial
Diagram Description: The window comparator section describes a voltage range detection concept that inherently requires visual representation of thresholds (V_L and V_H) relative to an input signal.

2. Internal Circuitry and Operation

Internal Circuitry and Operation

Differential Input Stage

The LM339 comparator consists of a differential input stage, followed by a gain stage and an output stage. The input stage employs a long-tailed pair configuration, where two NPN transistors (Q1 and Q2) share a common emitter resistor. This stage is responsible for amplifying the voltage difference between the non-inverting (V+) and inverting (V-) inputs. The tail current is set by a current source, typically implemented using a current mirror to ensure stability over temperature variations.

$$ V_{diff} = V_+ - V_- $$

When V+ exceeds V-, Q1 conducts more current than Q2, steering the tail current asymmetrically. Conversely, when V- is higher, Q2 dominates. The output of this stage is a differential current proportional to the input voltage difference.

Gain Stage and Frequency Compensation

The amplified signal from the input stage feeds into a high-gain common-emitter amplifier (Q3), which provides the bulk of the voltage gain. A Miller capacitor (typically 1–5 pF) is often incorporated for frequency compensation, ensuring stability by rolling off the gain at higher frequencies. The transfer function of this stage can be modeled as:

$$ A_v(s) = \frac{g_m R_C}{1 + s C_M R_C} $$

where gm is the transconductance of Q3, RC is the collector load resistor, and CM is the Miller capacitance.

Output Stage

The LM339 features an open-collector output, allowing for flexible interfacing with various logic families or higher-voltage loads. The output transistor (Q4) saturates when the comparator's internal voltage exceeds its base-emitter threshold, pulling the output low. When the input differential reverses, Q4 turns off, leaving the output in a high-impedance state. An external pull-up resistor is required for proper operation.

Q1 Gain Q4

Key Parameters and Practical Considerations

In precision applications, the input bias current (typically 25 nA) must be accounted for, as it flows through external resistors and creates offset voltages. The LM339's input common-mode range extends from 0 V to VCC - 1.5 V, allowing ground-referenced sensing.

Internal Circuitry and Operation in LM339 Comparator Tutorial
Diagram Description: The diagram would physically show the internal stages (differential input, gain, output) with transistor-level connections and signal flow paths.

2.2 Voltage Comparison Mechanism

Differential Input Stage

The LM339 comparator operates by comparing two input voltages, V+ (non-inverting) and V (inverting), using a differential input stage. The internal circuitry amplifies the voltage difference ΔV = V+ − V with high gain, typically exceeding 100 dB. When ΔV > 0, the output saturates to the positive rail; when ΔV < 0, it pulls to ground (open-collector configuration).

$$ V_{out} = \begin{cases} V_{CC} & \text{if } V_{+} > V_{-} + V_{os} \\ 0 & \text{if } V_{+} < V_{-} + V_{os} \end{cases} $$

Here, Vos represents the input offset voltage (typically 2–5 mV), a critical parameter for precision applications.

Hysteresis and Noise Immunity

Without hysteresis, rapid input noise near the threshold can cause output oscillation. The LM339’s open-loop design requires external hysteresis, often implemented via positive feedback. For a resistor network R1 and R2 between output and non-inverting input:

$$ V_{th} = \pm \frac{R_1}{R_1 + R_2} \cdot V_{CC} $$

This creates two distinct thresholds, Vth+ and Vth−, improving noise immunity. For example, with VCC = 5V, R1 = 10kΩ, and R2 = 100kΩ, hysteresis spans ≈45 mV.

Propagation Delay and Slew Rate

The LM339’s response time depends on overdrive (|ΔV|) and load capacitance. Propagation delay (tpd) decreases with higher overdrive:

$$ t_{pd} \approx \frac{C_L \cdot \Delta V}{I_{sink}} $$

For CL = 50pF and Isink = 6mA, a 10 mV overdrive yields ≈80 ns delay. Slew rate is limited by internal compensation (~0.5 V/µs).

Practical Considerations

Voltage Comparison Mechanism in LM339 Comparator Tutorial
Diagram Description: The section involves voltage waveforms (hysteresis thresholds) and a feedback resistor network, which are inherently spatial relationships.

2.3 Output Stage Characteristics

Open-Collector Configuration

The LM339 features an open-collector output stage, a design choice that provides flexibility in interfacing with different voltage levels. The output transistor acts as a switch, sinking current when active but leaving the output floating when inactive. This allows the output to be pulled up to a voltage higher than the LM339's supply voltage (up to the transistor's breakdown limit, typically 36V). The absence of an internal pull-up resistor necessitates an external one, whose value affects rise time and power dissipation.

Sink Current Capability

The output can sink up to 16mA (per comparator), with a saturation voltage (VOL) specified at 0.7V max at 4mA. For higher currents, the saturation voltage increases linearly due to the finite output impedance of the NPN transistor. The sink current is limited by:

$$ I_{sink} = \frac{V_{pullup} - V_{OL}}{R_{pullup}} $$

where Vpullup is the external pull-up voltage and Rpullup must be chosen to avoid exceeding the LM339's power dissipation limits.

Propagation Delay and Switching Speed

The output stage contributes to the comparator's propagation delay, which ranges from 1.3μs (typical) to 3μs (max) for a 5mV overdrive. The delay is influenced by:

Phase Reversal and Latch-Up Prevention

Unlike some comparators, the LM339 is immune to phase reversal—a condition where the output polarity inverts if the input exceeds the common-mode range. Its output stage is also designed to avoid latch-up, even when the input pins are driven beyond the supply rails. This robustness makes it suitable for harsh environments where input signals may be noisy or poorly regulated.

Interfacing with Logic Families

The open-collector output allows direct interfacing with:

Thermal Considerations

When sinking high currents, the output transistor's power dissipation (P = VOL × Isink) must be accounted for in thermal calculations. For multi-comparator ICs (e.g., LM339 has four comparators), ensure the total package dissipation does not exceed the rated PD (e.g., 570mW for DIP-14 at 25°C).

Output Stage Characteristics in LM339 Comparator Tutorial
Diagram Description: A diagram would visually demonstrate the open-collector output configuration and its interaction with pull-up resistors and external voltage levels.

3. Basic Comparator Circuit Setup

3.1 Basic Comparator Circuit Setup

Operating Principle

The LM339 is an open-collector comparator, meaning its output stage consists of an NPN transistor with an uncommitted collector. When the non-inverting input (V+) exceeds the inverting input (V-), the internal transistor turns off, leaving the output floating. When V- > V+, the transistor saturates, pulling the output to ground.

$$ V_{OUT} = \begin{cases} \text{High impedance (open)} & \text{if } V_+ > V_- \\ 0\,\text{V (GND)} & \text{if } V_- > V_+ \end{cases} $$

Minimal Circuit Configuration

A functional LM339 circuit requires:

LM339 V+ V- VCC Output

Hysteresis Implementation

To prevent oscillation near the threshold, add positive feedback via a resistor (Rhyst) between the output and V+. The hysteresis window (ΔV) is calculated as:

$$ \Delta V = \frac{R_2}{R_1 + R_2} \cdot V_{CC} $$

where R1 is the pull-up resistor and R2 is the feedback resistor.

Practical Considerations

3.2 Hysteresis and Noise Immunity

Hysteresis in a comparator circuit introduces intentional positive feedback to prevent rapid toggling due to noise or slow-moving input signals near the threshold voltage. The LM339, being an open-collector output comparator, requires external hysteresis implementation through resistor networks.

Mathematical Derivation of Hysteresis

For a non-inverting comparator configuration with hysteresis, the upper (VTH) and lower (VTL) threshold voltages are determined by the feedback resistor RF and the reference voltage divider network. Assume the reference voltage at the inverting input is VREF:

$$ V_{TH} = V_{REF} \left(1 + \frac{R_1}{R_2}\right) - \frac{V_{OL} \cdot R_1}{R_2} $$
$$ V_{TL} = V_{REF} \left(1 + \frac{R_1}{R_2}\right) - \frac{V_{OH} \cdot R_1}{R_2} $$

where VOH is the output high voltage (pulled up to VCC via external resistor) and VOL is the output low voltage (near ground). The hysteresis window (VHYST) is:

$$ V_{HYST} = V_{TH} - V_{TL} = \frac{(V_{OH} - V_{OL}) \cdot R_1}{R_2} $$

Noise Immunity Considerations

Hysteresis provides noise immunity by creating a deadband where transient signals below the hysteresis window do not trigger false output transitions. The required hysteresis window should exceed the peak-to-peak noise voltage:

$$ V_{HYST} > V_{noise(p-p)} $$

For optimal noise rejection:

  • Place the feedback resistor RF close to the comparator to minimize parasitic coupling.
  • Use a bypass capacitor (typically 0.1 µF) near the power supply pins.
  • Route sensitive traces away from high-frequency or high-current paths.

Practical Implementation Example

A typical LM339 hysteresis circuit uses R1 = 100 kΩ and R2 = 1 MΩ with VCC = 5V. Assuming VOL ≈ 0V and VOH ≈ 5V, the hysteresis window is:

$$ V_{HYST} = \frac{5 \cdot 100k}{1M} = 0.5V $$

This ensures immunity against noise spikes smaller than 0.5V. For industrial environments with higher noise levels, the hysteresis can be increased by reducing R2 or increasing R1.

Input Signal Output with Hysteresis V_TH V_TL
Hysteresis and Noise Immunity in LM339 Comparator Tutorial
Diagram Description: The section explains hysteresis thresholds and noise immunity with mathematical relationships, which would benefit from a visual representation of input/output waveforms and threshold markers.

3.3 Driving Different Load Types

The LM339's open-collector output allows it to interface with a variety of loads, but proper design considerations must be made to ensure reliable operation. The output stage consists of an NPN transistor capable of sinking up to 16 mA, but external components are often required to drive higher currents or voltage levels beyond the chip's supply rail.

Resistive Loads

When driving resistive loads, the primary limitation is the comparator's sink current capability. The output voltage (VOL) depends on the load resistance (RL) and the current (IOL):

$$ V_{OL} = I_{OL} \cdot R_L $$

For reliable operation, ensure that IOL does not exceed the LM339's maximum sink current (16 mA). A pull-up resistor (RL) to the desired logic voltage rail sets the output high level when the comparator's internal transistor is off. The resistor value is calculated as:

$$ R_L = \frac{V_{CC} - V_{OL}}{I_{OL}} $$

where VCC is the pull-up supply voltage. For example, driving a 5 V logic input with IOL = 8 mA requires:

$$ R_L = \frac{5\,V - 0.4\,V}{8\,mA} = 575\,\Omega $$

A standard 560 Ω resistor would suffice in this case.

Inductive Loads (Relays, Solenoids)

Inductive loads require special attention due to back-EMF generated when the output transistor turns off. A flyback diode is essential to protect the LM339 from voltage spikes. The diode should be placed in reverse bias across the load:

LM339 Flyback Diode

The diode's reverse voltage rating must exceed the supply voltage, and its forward current rating should match the load current. Schottky diodes are preferred for fast switching applications.

Capacitive Loads

Capacitive loads can cause stability issues due to the LM339's limited slew rate. A small series resistor (RS) between the output and the capacitor helps dampen oscillations:

$$ R_S = \sqrt{\frac{L}{C}} $$

where L is the parasitic inductance of the traces and C is the load capacitance. Typical values range from 10 Ω to 100 Ω.

LED Driving

When driving LEDs directly, the current-limiting resistor (RLED) is calculated as:

$$ R_{LED} = \frac{V_{CC} - V_{LED}}{I_{LED}} $$

For example, driving a red LED (VLED ≈ 1.8 V) at 10 mA with a 5 V supply:

$$ R_{LED} = \frac{5\,V - 1.8\,V}{10\,mA} = 320\,\Omega $$

A 330 Ω resistor would be appropriate. Note that the LM339's output transistor must sink the LED current.

MOSFET and Transistor Buffering

For higher current or voltage switching, an external NPN transistor or N-channel MOSFET can be used. The base/gate resistor (RB) is chosen to ensure saturation:

$$ R_B = \frac{V_{OH} - V_{BE}}{I_B} $$

where VOH is the LM339's output high voltage (near VCC), VBE is the transistor's base-emitter voltage (≈0.7 V), and IB is the base current required for the desired collector current (IC):

$$ I_B = \frac{I_C}{\beta} $$

where β is the transistor's current gain. For a MOSFET, ensure the gate-source voltage (VGS) exceeds the threshold voltage for full enhancement.

4. Window Comparator Circuits

4.1 Window Comparator Circuits

A window comparator circuit determines whether an input voltage lies within a predefined voltage range, or "window." The LM339, with its four independent comparators, is particularly well-suited for this application due to its open-collector outputs, which allow flexible logic-level interfacing.

Basic Operation

The window comparator uses two reference voltages, VREF1 (lower threshold) and VREF2 (upper threshold). The input voltage VIN is compared against both thresholds simultaneously:

  • If VIN < VREF1, the lower comparator output is active (low).
  • If VIN > VREF2, the upper comparator output is active (low).
  • If VREF1VINVREF2, neither output is active (both high).
$$ \text{Output} = \begin{cases} \text{Low (0)} & \text{if } V_{IN} < V_{REF1} \text{ or } V_{IN} > V_{REF2} \\ \text{High (1)} & \text{if } V_{REF1} \leq V_{IN} \leq V_{REF2} \end{cases} $$

Circuit Implementation

The standard LM339 window comparator configuration consists of:

  • Two comparators (e.g., IC1A and IC1B in a quad package).
  • A voltage divider network to set VREF1 and VREF2.
  • Pull-up resistors on the open-collector outputs.
  • Optional logic gates (e.g., AND/NAND) to combine outputs if a single decision signal is required.
LM339 V_REF1 V_REF2 V_IN

Hysteresis Considerations

To prevent output oscillation near threshold boundaries, hysteresis can be added via positive feedback resistors. For a window comparator, hysteresis must be applied symmetrically to both thresholds:

$$ V_{HYST} = \frac{R_F}{R_{IN}} \cdot (V_{REF2} - V_{REF1}) $$

where RF is the feedback resistor and RIN is the input resistor value.

Practical Applications

Window comparators are widely used in:

  • Battery monitoring systems to detect over-voltage and under-voltage conditions.
  • Environmental sensors for threshold-based alarms (temperature, humidity).
  • Industrial control systems for process parameter validation.
  • Signal conditioning in data acquisition systems.

Design Example

For a 5V system monitoring a 2.5V–3.5V window:

  1. Set VREF1 = 2.5V using a voltage divider with 1% tolerance resistors.
  2. Set VREF2 = 3.5V with a second divider network.
  3. Choose 10kΩ pull-up resistors for the outputs.
  4. Add 100kΩ feedback resistors for ≈50mV hysteresis.
$$ R_{DIV} = \frac{V_{CC} - V_{REF}}{I_{DIV}} $$

where IDIV is typically kept below 1mA to minimize power consumption.

Window Comparator Circuits in LM339 Comparator Tutorial
Diagram Description: The diagram would physically show the connections between the LM339 comparators, voltage divider networks, and pull-up resistors in the window comparator circuit.

4.2 Using LM339 as a Relaxation Oscillator

The LM339 comparator can be configured as a relaxation oscillator by leveraging its inherent hysteresis and an RC timing network. The resulting circuit generates a square wave output whose frequency is determined by the charging and discharging cycles of the capacitor. This configuration is widely used in applications requiring clock signals, pulse-width modulation (PWM), or tone generation.

Circuit Configuration

The basic relaxation oscillator circuit consists of the LM339, a resistor-capacitor (RC) network, and a feedback resistor to introduce hysteresis. The non-inverting input is connected to a voltage divider, while the inverting input is tied to the capacitor. The output swings between the supply rails, charging and discharging the capacitor through the timing resistor.

LM339 R C

Mathematical Derivation of Oscillation Frequency

The oscillation frequency is derived from the RC time constant and the hysteresis window set by the feedback network. The capacitor charges and discharges between the upper and lower threshold voltages, defined by the voltage divider and the comparator's output swing.

$$ V_{th+} = V_{cc} \left( \frac{R_2}{R_1 + R_2} \right) $$
$$ V_{th-} = V_{cc} \left( \frac{R_2}{R_1 + R_2} \right) \left( \frac{R_3}{R_3 + R_4} \right) $$

The charging time (Tcharge) and discharging time (Tdischarge) are given by:

$$ T_{charge} = RC \ln \left( \frac{V_{cc} - V_{th-}}{V_{cc} - V_{th+}} \right) $$
$$ T_{discharge} = RC \ln \left( \frac{V_{th+}}{V_{th-}} \right) $$

The total period (T) and frequency (f) of oscillation are:

$$ T = T_{charge} + T_{discharge} $$
$$ f = \frac{1}{T} $$

Practical Considerations

For stable oscillation, the hysteresis window must be sufficiently large to overcome noise and comparator response time. The choice of R and C affects both frequency and power dissipation. Lower resistor values reduce sensitivity to leakage currents but increase power consumption. The LM339's open-collector output requires a pull-up resistor, which also influences the rise time of the output waveform.

Applications

This oscillator configuration is commonly used in:

  • Clock generation for digital systems where precise frequency stability is not critical.
  • PWM controllers for motor speed control or LED dimming.
  • Audio tone generation in simple alarm circuits or musical instruments.
Using LM339 as a Relaxation Oscillator in LM339 Comparator Tutorial
Diagram Description: The diagram would show the physical connections of the LM339 relaxation oscillator circuit, including the RC network and feedback path, which are spatial relationships difficult to visualize from text alone.

4.3 Level Shifting and Interface Circuits

The LM339's open-collector output architecture necessitates level-shifting circuits to interface with logic families operating at different voltage domains. This section explores practical methods to translate output levels while preserving signal integrity, with emphasis on noise immunity and transient response.

Voltage Translation Fundamentals

When driving CMOS or TTL inputs from an LM339, the output pull-up resistor (Rpull-up) must be sized to meet the target logic family's input current requirements while maintaining adequate switching speed. The rise time (tr) is governed by the RC time constant:

$$ t_r \approx 2.2 R_{pull-up} C_{load} $$

where Cload includes stray capacitance and the input capacitance of the driven stage. For 5V TTL interfaces, typical values range from 1kΩ to 10kΩ, trading speed for power dissipation.

Bidirectional Level Shifting

For mixed-voltage systems, MOSFET-based translators provide bidirectional capability. An N-channel MOSFET (e.g., BSS138) with pull-ups to both voltage domains creates a passive voltage clamp:

The MOSFET's threshold voltage (VGS(th)) must be lower than the LM339's minimum output high voltage (typically 1.5V below VCC). The transfer function becomes:

$$ V_{out} = \begin{cases} 0 & \text{if } V_{in} < V_{GS(th)} \\ V_{DD2} & \text{if } V_{in} \geq V_{GS(th)} \end{cases} $$

Interfacing with High-Voltage Loads

For industrial applications requiring >15V switching, a BJT or optocoupler interface provides isolation. The collector resistor (RC) in a BJT stage is calculated based on the load current (IL):

$$ R_C = \frac{V_{HV} - V_{CE(sat)}}{I_L} $$

where VHV is the high-side supply and VCE(sat) is the transistor's saturation voltage (typically 0.2V). Darlington configurations may be employed for currents exceeding 500mA.

Noise Mitigation Techniques

Schmitt-trigger inputs (e.g., 74HC14) should be used when processing LM339 outputs in noisy environments. The hysteresis window (VHYS) adds noise margin:

$$ V_{HYS} = V_{T+} - V_{T-} $$

where VT+ and VT- are the positive/negative-going thresholds. For CMOS Schmitt triggers, typical hysteresis ranges from 0.5V to 1.5V at 5V supply.

Case Study: 3.3V to 24V PLC Interface

A practical implementation for programmable logic controllers combines optoisolation and a BJT stage:

The optocoupler's current transfer ratio (CTR) dictates the base current:

$$ I_B = CTR \times I_F $$

where IF is the forward current through the LED (typically 5-10mA). This configuration achieves 2500V RMS isolation while handling 24V/2A loads.

Level Shifting and Interface Circuits in LM339 Comparator Tutorial
Diagram Description: The section describes a MOSFET-based bidirectional level shifter and an optocoupler/BJT interface circuit, both of which require visual representation of component connections and voltage domains.

5. Identifying and Fixing Oscillation Issues

5.1 Identifying and Fixing Oscillation Issues

Oscillation in the LM339 comparator often arises due to unintended positive feedback, parasitic capacitances, or insufficient hysteresis. When the input signal hovers near the comparator's threshold, noise or slow transitions can cause rapid toggling of the output, leading to instability. This section examines the root causes and mitigation strategies.

Root Causes of Oscillation

The primary mechanisms driving oscillation include:

  • Parasitic feedback paths: Stray capacitance or inductance in PCB traces can couple the output signal back to the input, creating unintended positive feedback.
  • Insufficient hysteresis: Without hysteresis, noise near the threshold voltage triggers multiple output transitions.
  • High-impedance inputs: Floating or weakly driven inputs amplify noise susceptibility.
  • Slow edge rates: Gradual input transitions prolong the time spent near the threshold, increasing sensitivity to noise.

Quantifying Oscillation Conditions

The Barkhausen stability criterion defines oscillation as occurring when the loop gain satisfies:

$$ \beta A_v \geq 1 $$

where β is the feedback factor and Av is the comparator's open-loop gain. For the LM339, Av typically exceeds 100 dB, making unintended feedback particularly problematic.

Mitigation Techniques

1. Adding Hysteresis

Introducing hysteresis creates two distinct threshold voltages, preventing noise-induced toggling. For a resistive feedback network:

$$ V_{TH+} = V_{REF} + \left( \frac{R_2}{R_1 + R_2} \right) V_{OH} $$ $$ V_{TH-} = V_{REF} - \left( \frac{R_2}{R_1 + R_2} \right) V_{OL} $$

where VOH and VOL are the output high and low voltages, respectively. A hysteresis width of 10–100 mV is often sufficient for noise immunity.

2. Reducing Parasitic Coupling

  • Minimize trace lengths between the comparator and feedback components.
  • Use ground planes to shield sensitive nodes.
  • Add a small capacitor (10–100 pF) across feedback resistors to suppress high-frequency oscillations.

3. Input Filtering

A low-pass RC filter at the input attenuates high-frequency noise:

$$ f_c = \frac{1}{2\pi RC} $$

Choose fc below the comparator's response frequency but above the signal bandwidth.

4. Output Load Management

Excessive capacitive loading can slow edge rates, exacerbating oscillation. Use a series resistor (47–100 Ω) to isolate the comparator output from large capacitive loads.

Case Study: Unstable Zero-Crossing Detector

A zero-crossing detector without hysteresis oscillates due to 60 Hz noise superimposed on the input. Adding 50 mV of hysteresis via a 1 MΩ feedback resistor and 100 kΩ divider eliminates false triggering while preserving accuracy.

Input Signal with Noise
Identifying and Fixing Oscillation Issues in LM339 Comparator Tutorial
Diagram Description: The section discusses oscillation mitigation techniques involving voltage thresholds and feedback paths, which are best visualized with labeled waveforms and circuit diagrams.

5.2 Dealing with Input Offset Voltage

Input offset voltage (VOS) is a critical parameter in precision comparator applications, arising from inherent mismatches in the internal differential pair transistors of the LM339. For advanced designs, minimizing its impact requires both theoretical understanding and practical mitigation techniques.

Mathematical Modeling of Offset Voltage

The input offset voltage can be modeled as an equivalent voltage source in series with one of the inputs. For a comparator with differential inputs, the effective input voltage (VIN,eff) becomes:

$$ V_{IN,eff} = V_{IN+} - V_{IN-} + V_{OS} $$

where VIN+ and VIN- are the non-inverting and inverting input voltages, respectively. The offset voltage introduces an error term that shifts the comparator's threshold point.

Statistical Distribution and Worst-Case Analysis

In production, VOS follows a Gaussian distribution with a standard deviation (σ). The datasheet typically specifies the maximum offset voltage (VOS,max), which represents the 3σ limit:

$$ V_{OS,max} = 3\sigma $$

For the LM339, VOS,max ranges from 2 mV to 5 mV depending on temperature and biasing conditions. In precision applications, this error must be accounted for in the design margin.

Compensation Techniques

External Nulling Circuit

A potentiometer-based nulling circuit can cancel VOS by injecting a compensating voltage. The adjustment range should cover the worst-case offset:

$$ R_{null} = \frac{V_{CC}}{I_{bias}} $$

where Ibias is the input bias current (typically 25 nA for the LM339). A 10 kΩ potentiometer with a 100 kΩ series resistor provides sufficient adjustment range while limiting current.

Auto-Zeroing with Capacitive Storage

In sampled systems, an auto-zeroing technique stores the offset voltage on a capacitor during a calibration phase. The stored voltage is then subtracted during normal operation. The required capacitor value is:

$$ C_{az} > \frac{I_{leakage} \cdot t_{hold}}{\Delta V_{OS}} $$

where Ileakage is the capacitor's leakage current, thold is the hold time, and ΔVOS is the tolerable drift.

Temperature Dependence

The input offset voltage exhibits a temperature coefficient (TCVOS) typically around 7 μV/°C for the LM339. The total offset over temperature range ΔT is:

$$ V_{OS}(T) = V_{OS}(25°C) + TCV_{OS} \cdot \Delta T $$

For industrial applications (-40°C to +85°C), this can add ±0.5 mV to the initial offset. Temperature-compensated designs may require a thermistor network or digital calibration.

Noise Considerations

At high gains, the input-referred noise voltage (en) becomes comparable to VOS. The total uncertainty in the switching point is the root-sum-square of these terms:

$$ V_{uncertainty} = \sqrt{V_{OS}^2 + e_{n}^2} $$

For the LM339, en ≈ 1 μV/√Hz at 1 kHz. In a 10 kHz bandwidth, this contributes 10 μV RMS noise, which is negligible compared to typical offset voltages.

Practical Implementation Example

A precision window comparator circuit demonstrates offset compensation. The design uses:

  • LM339 with VOS ≤ 3 mV
  • 10-turn 10 kΩ potentiometer for fine adjustment
  • 0.1 μF ceramic capacitor for high-frequency bypass
  • Guard rings on PCB to minimize thermocouple effects

The compensation voltage is injected through a 100 kΩ resistor to the inverting input, with the potentiometer connected between ±5 V supplies. This provides ±5 mV adjustment range with 0.5 mV resolution.

Dealing with Input Offset Voltage in LM339 Comparator Tutorial
Diagram Description: The section describes practical compensation techniques and mathematical models that would benefit from visual representation of the equivalent voltage source and nulling circuit.

5.3 Power Supply Considerations

The LM339's performance is highly dependent on its power supply configuration. Unlike op-amps, comparators like the LM339 are typically operated with a single-rail supply, but dual-rail configurations are also possible under specific conditions. The datasheet specifies a supply voltage range of 2V to 36V, but optimal operation requires careful consideration of noise, stability, and transient response.

Single vs. Dual Supply Operation

When powered from a single supply (VCC to GND), the LM339's output stage saturates near ground when the inverting input is higher than the non-inverting input. For dual-supply operation (±VCC), the output remains compatible with TTL/CMOS logic levels, but the negative rail must not exceed -0.3V to avoid substrate latch-up. The input common-mode range extends to VCC - 1.5V, meaning the inputs must stay within 1.5V of the positive rail.

$$ V_{CM} \in [GND, V_{CC} - 1.5V] $$

Power Supply Rejection Ratio (PSRR)

The LM339's PSRR is typically 65dB at DC but degrades with frequency due to internal compensation. High-frequency noise on the supply rail can couple into the comparator's output, leading to false triggering. A bypass capacitor (0.1μF ceramic in parallel with 1–10μF electrolytic) is mandatory near the VCC pin. For noisy environments, an LC filter (10Ω resistor + 10μF capacitor) further attenuates high-frequency interference.

Current Consumption and Load Effects

The LM339's quiescent current is supply-dependent, typically 0.8mA at 5V and 1.5mA at 36V. However, output sinking current (up to 16mA) can cause localized voltage drops if the ground path has high impedance. A star grounding topology is recommended to minimize ground bounce, especially in mixed-signal designs.

Transient Response and Decoupling

Fast output transitions (1.3μs typical) demand low-impedance supply paths to prevent ringing. A poorly decoupled supply can induce oscillations due to parasitic inductance in PCB traces. The following empirical formula estimates the maximum allowable trace inductance for stable operation:

$$ L_{max} = \frac{V_{CC} \cdot \Delta t}{\Delta I} $$

where ΔI is the transient current spike during switching. For a 5V supply with 10mA transients and 100ns edges, Lmax50nH, requiring traces shorter than 2cm for typical PCB geometries.

Thermal Considerations

At high supply voltages (>24V), power dissipation in the output stage becomes non-negligible. The maximum junction temperature (150°C) can be exceeded if multiple outputs sink current simultaneously. The power dissipation per comparator is given by:

$$ P_d = (V_{CC} - V_{OL}) \cdot I_{sink} + V_{CC} \cdot I_{Q} $$

where VOL is the saturation voltage (~0.5V). For four comparators sinking 5mA each at 30V, total Pd660mW, necessitating a heatsink or reduced load current.

Power Supply Considerations in LM339 Comparator Tutorial
Diagram Description: The section covers power supply configurations and transient response, which would benefit from a visual representation of single vs. dual supply setups and decoupling capacitor placement.

6. Datasheets and Manufacturer Resources

6.1 Datasheets and Manufacturer Resources

  • PDF LM339B, LM2901B, LM339, LM239, LM139, LM2901 Quad Differential Comparators — LM339B, LM2901B, LM339, LM239, LM139, LM2901 Quad Differential Comparators 1 Features • NEW LM339B and LM2901B ... LM339 and LM2901 comparator family. These next generation B-version comparators feature lower offset ... Some manufacturers transpose the names of channels 1 & 2. Electrically the pinouts are identical, just a difference in the ...
  • PDF Application Design Guidelines for LM339, LM393, TL331 Family ... — Dual comparator product list: LM193QML-SP, LM193QML, LM293A-EP, LM293-N, LM2904-EP, LM139AQML, and LM139JAN. Quad comparator product list: LM139-SP, LM139AQML-SP, LM139-MIL, LM139A-MIL, LM139AQM,L and LM139JAN. The qualifications and ratings of these devices are not covered in this application note. Please consult the individual device data sheets.
  • PDF LM339 - Single Supply Quad Comparators - onsemi — LM339/D 1 Single Supply Quad Comparators LM339, LM339E, LM239, LM2901, LM2901E, LM2901V, NCV2901, MC3302 These comparators are designed for use in level detection, low−level sensing and memory applications in consumer, automotive, and industrial electronic applications. Features • Single Supply Operation: 3.0 V to 36 V
  • LM139, 239, 339 Datasheet by STMicroelectronics | Digi-Key Electronics — View datasheets for LM139, 239, 339 Datasheet by STMicroelectronics and other related components here. LM139, 239, 339 Datasheet by STMicroelectronics ... - LM339, LM339A-55, +125-40, +105. 0, +70 °C Electrical charact eristics LM139, LM239, LM 339. ... the comparator will provide a proper outp u t state. The low input voltage state must not ...
  • LM339 data sheet, product information and support | TI.com — The LM339B and LM2901B devices are the next generation versions of the industry-standard LM339 and LM2901 comparator family. These next generation B-version comparators feature lower offset voltage, higher supply voltage capability, lower supply current, lower input bias current, lower propagation delay, and improved 2 kV ESD performance and input ruggedness through dedicated ESD clamps.
  • PDF Application Design Guidelines for LM339/LM393/TL331 Family Comparators — Application Design Guidelines for LM339 Family of Comparators 2 Input Considerations 2.1 Input Stage Schematic The simplified LM339 Family comparator internal schematic is shown in Figure 1. Minus a few devices in the biasing circuitry, the schematic is a fairly true representation of the actual internal circuit.
  • Comparators | LM339 - onsemi — Search through datasheets, application notes, and white papers to locate the relevant information. ... Comparators | LM339 Show side navigation. By Technology; Discrete & Power Modules. MOSFETs. ... tools and other useful resources related to LM339. CAD Model. Material Composition. Product Change Notification. Reliability Data.
  • PDF Low-power quad voltage comparators - STMicroelectronics — LM139, LM239, LM339 Low-power quad voltage comparators Datasheet -production data Features • Wide single supply voltage range or dual supplies for all devices: +2 to +36 V or ±1 V to ... the comparator will provide a proper output state. The low input voltage state must not be less than -0.3 V (or 0.3 V below the negative power supply, if ...
  • LM139, 239, 339 by STMicroelectronics Datasheet | DigiKey — Manufacturers. Back Brands A-Z; Featured Brands; Analog Devices Inc. Back ... LM139, LM239, LM339. Low-power quad voltage comp arators . ... common-mode range, the comparator will provide a proper outp u t state. The low input voltage state must not be less than-0.3 V (or 0.3 V below the negative power supply, if used). ...
  • LM339-N Datasheet | DigiKey - Digi-Key Electronics — View LM339-N datasheet for technical specifications, ... JEDEC document JEP155 states that 500-V HBM allows safe manufacturing with a standard ESD control process. ... The basic usage of a comparator is to indicate when a specific analog signal has exceeded some predefined. threshold. In this application, the negative input is tied to a ...

6.2 Recommended Books and Articles

  • PDF LM339B, LM2901B, LM339, LM239, LM139, LM2901 Quad Differential Comparators — 1 16 Output Output pin of the comparator 2 OUT2 (1) 2 15 Output Output pin of the comparator 1 V. CC. 3 1 — Positive supply IN2- (1) 4 5 Input Negative input pin of the comparator 1 IN2+ (1) 5 6 Input Positive input pin of the comparator 1 IN1- (1) 6 2 Input Negative input pin of the comparator 2 IN1+ (1) 7 4 Input Positive input pin of ...
  • PDF INTRODUCTION TO CMOS OP-AMPS AND COMPARATORS - Wiley — 5 COMPARATORS 175 5.1 Circuit Modeling of a Comparator / 175 5.2 Single-Ended Auto-Zeroing Comparators / 177 5.3 Differential Comparators / 182 5.4 Regenerative Comparators (Schmitt Triggers) / 192 5.5 Fully Differential Comparators / 198 5.6 Latches / 205 Problems / 212 References / 213 6 DIGITAL-TO-ANALOG CONVERTERS 214
  • PDF Application Design Guidelines for LM339, LM393, TL331 Family ... — Application Design Guidelines for LM339, LM393, TL331 Family Comparators Including the New B-versions Paul Grohe ABSTRACT The TL331, LM339, LM393, and the next generation B-versions (TL331B, LM339B, LM2901B, LM393B, and LM2903B) are a popular and long-lived family of standard comparators due to the flexibility, availability, and cost-effectiveness.
  • Op amps and Comparators - Learn About Electronics — The Schmitt Trigger circuit shown in Fig. 6.6.2 is an inverting comparator based on the LM339 quad comparator IC from Texas Instruments, with its reference value applied to the non-inverting input by the potential divider R1 and R2. This sets the reference voltage at half of the 5V single supply.
  • LM339 data sheet, product information and support | TI.com — The LM339B and LM2901B can drop-in replace the LM239, LM339 and LM2901, for both "A" and "V" grades. All devices consist of four independent voltage comparators that are designed to operate from a single power supply over a wide range of voltages. Quiescent current is independent of the supply voltage.
  • Make a Battery Level Indicator using LM339 IC (Part 7/9) - Engineers Garage — Internally LM339 consists of four OPAM which acts like comparators and detect the voltage level. This IC has low offset voltage (+/- 2 mV) and low bias current (Typically 25 nA). The supply voltage of LM339 can vary from 3V to 36V and split supply can vary from +/-1.5 V to +/-18 V. The input common mode voltage is around -0.3 V to Vcc.
  • Make A Battery Level Indicator Using LM339 IC — 12/13 Fig. 12: Table listing voltage at inverting and non-inverting pin of comparator at battery voltage of 13.5V It should be noted that as the LM339 minimum input common mode voltage is -0.3V so a diode is used at the negative supply pin (12th pin) of LM339 IC to ground so it can prevent the voltage going less than -0.3V.
  • PDF LMx39-N Low-Power Low-Offset Voltage Quad Comparators (Rev. E) — LM339-N SOIC (14) 8.65 mm × 3.91 mm 2 Applications PDIP (14) 19.177 mm × 6.35 mm • Limit Comparators (1) For all available packages, see the orderable addendum at the end of the datasheet. • Simple Analog-to-Digital Converters (ADCs) • Pulse, Squarewave, and Time Delay Generators One-Shot Multivibrator With Input Lock Out
  • 6.2: Voltage Comparator - Workforce LibreTexts — Instructions for Comparator Circuit. A comparator circuit compares two voltage signals and determines which one is greater. The result of this comparison is indicated by the output voltage: if the op-amp's output is saturated in the positive direction, the noninverting input (+) is a greater, or more positive, voltage than the inverting input (-), all voltages measured with respect to ground.
  • PDF CMOS COMPARATORS - Springer — COMPARATORS In this chapter we shall deal with the design of CMOS compara-tors. A comparator is the basic component mainly used in ana-log-to-digital converters. Ideally, it generates an output logic signal as an instant response to the sign of an analog input (volt-age or current). Obviously, a real circuit doesn'tachieve the ideal function.

6.3 Online Tutorials and Community Forums

  • PDF Application Design Guidelines for LM339, LM393, TL331 Family ... — LM339 9mV LM339-MIL 5mV LM339-N 2mV, 5mV LM339A 3mV LM339B 5.5mV LM2901B 5.5mV LM2901B-Q1 5.5mV www.ti.com Devices Covered in Application Note. SNOAA35E - DECEMBER 2023 - REVISED JUNE 2024 Submit Document Feedback Application Design Guidelines for LM339, LM393, TL331 Family Comparators Including the New B-versions 3
  • PDF Application Design Guidelines for LM339, LM393, TL331 Family ... — LM339 9mV LM339-MIL 5mV LM339-N 2mV, 5mV LM339A 3mV LM339B 5.5mV LM2901B 5.5mV LM2901B-Q1 5.5mV www.ti.com Devices Covered in Application Note. SNOAA35F - APRIL 2019 - REVISED DECEMBER 2024 Submit Document Feedback Application Design Guidelines for LM339, LM393, TL331 Family Comparators Including the New B-versions 3
  • PDF LM339B, LM2901B, LM339, LM239, LM139, LM2901 Quad Differential Comparators — LM339B, LM2901B, LM339, LM239, LM139, LM2901 Quad Differential Comparators 1 Features • NEW LM339B and LM2901B • Improved specifications of B-version - Maximum rating: up to 38V - ESD rating (HBM): 2kV - Low input offset: 0.37mV - Low input bias current: 3.5nA
  • PDF Low-power quad voltage comparators - STMicroelectronics — Electrical characteristics LM139, LM239, LM339 6/19 DocID2159 Rev 4 3 Electrical characteristics Table 3. Electrical characteristics at V CC + = +5 V, V CC - = GND, T amb = +25 °C (unless otherwise specified) Symbol Parameter LM139A - LM239A LM339A LM139 - LM239 LM339 Unit Min. Typ. Max. Min Typ. Max. VIO Input offset voltage(1) Tmin ≤ Tamb ...
  • Comparator - get the difference between inputs? - Electrical ... — Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, ... Is there any way to have a comparator (say LM339) output the difference between its +V and -V ?? For example, if +V is 6.3 volts and -V is 5 volts, how to get a 1.3 volts signal? ...
  • PDF Operational amplifier, Comparator (Tutorial) - Mouser Electronics — Op-Amp/Comparator Application Note Operational amplifier ,Comparator (Tutorial) This application note explains the general terms and basic techniques that are necessary for configuring application circuits with op-amps and comparators. Refer to this note for guidance when using op-amps and comparators. a Contents
  • Schmitt Trigger Calculations | Electronics Forum (Circuits, Projects ... — Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. ... Electronics Forums. Electronic Projects Design/Ideas/Reviews . Schmitt Trigger Calculations. Thread starter apl247; Start date Apr 9, 2009; Status Not open for further replies. A. apl247 New Member ...
  • How to build a proportional pulse stretcher? : r/AskElectronics - Reddit — A design I was considering myself was to have the pulse input connected to an RC circuit, that will charge up as long as the pulse is high, and then discharge when the pulse is low. An LM339 comparator could be used to measure the voltage across the capacitor and be referenced to a voltage divider.
  • LM358 Comparator as Arduino digital Input — I'm currently working on a book page indicator project. I'm using a photoresistor/LDR as the book page indicator, which will be exposed to light from each opened page. Since there are 10 pages in the book, the analog pins on the Arduino are insufficient. So, I thought of using an LM358 as a brightness level comparator sensor for the LDR, and this is the circuit I've created. *Im using 10K ...
  • Loudspeaker protection circuit | Page 2 | diyAudio — Another approach is to design your own, using opamps, comparators, 555 timers and other general purpose ICs. You can be more precise or choose different operating levels than the ready made circuits permit. So here are a few different approaches to show the range of possibilities.