# Can a comparator be powered by 2 "positive" voltages in order to output a certain "low" voltage?

Can the "ground" pin of a comparator be connected not to the actual ground, but around 0.2 V above ground?

To provide a little context:

There is an oxygen sensor that is producing between 0-1 Volts. What I want to achieve is to keep its output unmodified when it is above a certain threshold, and send out a fixed low voltage (about 0.2 V) when the sensor output drops below the threshold. (a few mV hysteresis would be nice)

Can this be achieved with something akin to: Another approach I considered using this topic as a reference (How to trigger a relay and LED when a certain threshold of 0.15 volts is passed) is sort of the opposite - sensor output is modified via a voltage divider circuit (which should give an acceptable "low state" output), but whenever the sensor outputs voltage higher that the threshold it is shorted out by a transistor bypassing the voltage divider: Something looks wrong here, although the simulation shows it's working. Apologies for me thinking in terms of switches, relays, etc, I'm a little lost which direction to move now. Any pointers appreciated!

EDIT: in bold to avoid ambiguity in the project goals

New contributor
Bliss is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
• Is it ok to load the sensor output?
– sai
May 26 at 16:42
• Your first circuit has a good chance if you connect the sensor + via a resistor (e.g. 10 kohm) to the comparator open collector output.
– Jens
May 26 at 19:07
• Sai, can you explain what you mean by that phrase and how i can check for that? Or point me in the direction to read about to understand May 26 at 19:37
• Jens, i forgot to annotate, but the DC power supply on the left that's powering the comparator and providing a threshold would be 5 V, so wouldn't your proposal send the (almost) 5 V to the essentially the sensor +ve output? May 26 at 19:42
• I think an LM311 might be able to do this. It has an open collector AND open emitter output. May 27 at 3:07

I wouldn't power any op-amp or comparator via a resistor, either at the positive or negative side, since it's difficult to guarantee the current through such a resistor, and therefore the voltage dropped across it. That's not to say it isn't a useful technique under certain circumstances, but this isn't one of them.

Here's a solution using an op-amp to buffer the sensor signal, and a comparator to detect the threshold, and modify the output accordingly: simulate this circuit – Schematic created using CircuitLab

When sensor voltage, represented by source VIN, is swept from 0V to +1V, this is the output: VR1 allows you to adjust the threshold $$\V_{TH}\$$ to anything between 0V and +1V. In the above sweep I set VR1 to produce $$\V_{TH}\approx 300mV\$$. Below that threshold the OUT is near 0V, above it, OUT follows the sensor's signal.

If you use an LM393 (or any open-collector/drain output comparator), then you don't need D1, since the open collector will perform D1's function. In this simulation, ideal diode D1 is only present to emulate the behaviour of such an open-collector device in CircuitLab. If you simulated this design in a better simulator, like LTSpice, you can omit D1 completely, since the LM393 will be properly modelled.

In reality, an open-collector will "pull down" the output to more like +0.1V, not zero, closer to your requested value of +0.2V. If this is still too low, then we'll need to find a way of "pulling less strongly".

A comparator cannot be used to buffer the signal, but an op-amp may (under certain circumstances) be used as a comparator. The LM358 package in the above example contains two op-amps with outputs that can swing low enough in potential to reliably switch on and off a discrete transistor. The above design can therefore be modified to use both op-amps in a single LM358 package: simulate this circuit

Note that the inverting and non-inverting inputs of OA1b are reversed with respect to CMP1 in the previous circuit, because of the inverting behaviour of Q1.

Most comparators have a little hysteresis (a millivolt or so) built in, which improves output transition speed, and ensures that the output is either high or low, never in between. This hysteresis is not present when using an op-amp in the role of comparator, and this leads to the output transition being less well defined, and even oscillation. You can introduce hysteresis yourself, with a little positive feedback: simulate this circuit

I added R4 for positive feedback. Not only will this clean up the transition and eliminate oscillation, it will also make it faster, and prevent spurious transitions due to noise present in the sensor signal.

Hysteresis can be seen as the difference between the rising and falling transition thresholds (green markers below), when I sweep the input signal up and down again: In practice you won't need quite so much hysteresis. Increasing R4 to 10MΩ will reduce the gap between switching thresholds to just a few millivolts, mimicking behaviour of a real comparator. Adjust R4 to obtain enough hysteresis to overcome spurious transitions near the threshold, but not so much that the hysteresis gap becomes too wide.

• Interesting, worth a try, 0.1 to 0.2 V output would most likely be fine. Can a comparator be used to buffer the signal instead of the op-amp, or, is there a chip with both functionalities combined? I'd rather use a specialized comparator device for ... comparator duties so meaning not a 2 x OP-AMP with one used as a comparator, but instead a 2 x comparator with one being used as the buffer, or a comparator+op-amp in one package. May 27 at 11:33
• @Bliss You can't use a comparator to buffer, and since this design employs the open collector, it relies on both types, unfortunately. You could use two op-amps, (from a single LM358 package, for example) and an additional transistor. I've added this to my answer. May 28 at 4:04
• Thank you Simon, I'll experiment with this setup when my components arrive for sure! May 28 at 23:40

You can connect the power supply pins to any voltages you want, as long as the chip's specifications for power supply are met. In high voltage circuits, it is quite common to have opamps or comparators hanging from the high voltage rail with their own separate power supply. It's also possible to bootstrap opamps. None of these chips know what "ground" means to you (the designer), they only care about voltage on the corresponding pins.

However in your case I'd worry about the supply current of the comparator creating voltage on the resistors, which will add some error voltage. Output current also comes from the power supply, so this error could depend on the load connected to the output.

What I want to achieve is to keep its output untouched when it is above a certain threshold, and send out a lower voltage (about 0.2 V) when the sensor output drops below the threshold.

This is a bit ambiguous, I could interpret this as:

• outputting 0.2V when sensor voltage is below threshold

• substracting 0.2V from the sensor voltage when it is below threshold

I'll assume it's the first one.

The schematic in the question uses the comparator to output a lower voltage when needed, but when the comparator's output is high, it won't leave the sensor voltage untouched: the comparator will simply output a constant high. Also I think the comparator's inputs are inverted.

I think it would be simpler to use a comparator to drive an analog SPDT switch that selects between passing through the sensor voltage, or your chosen 0.2V value.

• BobFlux, thank you for the input! The output isn't really loaded as such, it would basically go to what used to be the sensor input to the control unit. I understand the issue with the possible inaccuracies, so...trimmer pots to adjust in place? As for the scenarious, yes, the first one. When the comparator output is high, it is outputting (almost) 5 V, which I'm feeling should be used to control a transistor of sort to act as a relay. In fact, as you say, I'm definitely more comfortable using a solid state relay just wanted a more "correct", or, better stated, elegant solution. May 26 at 19:57 The following circuit could be used. Note that I added 2 resistor dividers instead of one to isolate the "threshold" from the "0.2V". One limitation here is that you cannot connect a resistive load on "Output" because that will change the "0.2V".

I added the buffer to avoid kickback to the sensor output when output gets connected to the sensor output. If the comparator has sufficient hysteresis to avoid chattering then, you can remove the buffer but then, you need to look at the settling behaviour at the "Output" to make sure that it is acceptable to you.

Edit: Here's a brief about the working of this circuit

1. When sensor output is higher than threshold, it turns ON the NMOS (M2) and turns OFF the NMOS (M1). M2 connects the buffered sensor output to the "output".
2. When sensor output is lower than threshold, it turns ON the NMOS (M1) and turns OFF the NMOS (M2). M1 connects the 0.2V to the "output".

Be very careful about the sensor output impedance and model the same in your simulations so that you can catch any potential issue like comparator chattering.

• Sai, looks really cool, thank you! Can you explain a bit the roles of MOSFETs M1/M2? If the comparator has hysteresis and the buffer is removed like you mention, the sensor output is connected directly to the "new output" or the M2 MOSFET is still required? Finally, what do you mean about the "settling behavior"? May 27 at 11:18
• I added some explanation about M1/M2. Even if buffer is removed, you need M2. In your simulation, you used a voltage source to model the sensor output but, in reality, the sensor output will have an output impedance. If the sensor output is very high impedance then, when you connect the sensor output or disconnect it from the final output, it will disturb the sensor output and it can take time to settle back to the correct value. This is the settling behavior.
– sai
May 27 at 12:26
• I made a change to M2 to NMOS instead of PMOS. Hence I had to add an inverter also. With the PMOS scheme, it the threshold is lower than the PMOS VTH, the scheme would not work.
– sai
May 27 at 12:36
• Sai, thank you for the clarification! I can't get my head around the sensor and how it's qualities may affect the circuit. So the issue with impedance for example, will that effectively be solved utilizing an op-amp buffer? Or how can i check if the sensor can cause problems? Measure it's impedance at various outputs somehow? just test a physical circuit? May 27 at 23:13
• A buffer does make the circuit insensitive to the sensor impedance characteristics. If you want to measure the resistance, you can add a load current at the sensor output. The voltage change at the sensor output divided by the current is the sensor output resistance. You can also use a load resistor instead of load current. The formula for output resistance is the same (current here is the current through the load resistor)
– sai
May 28 at 1:30

I concur with bobflux that the intent of the poster is not clear in the question.

What I will respond to is only one possible interpretation, and is possibly not what the OP intended.

I interpret the question as asking how to make a comparator output 0.2V if the + input is less than the - input, and output some other unspecified value (5V?) if the + input is greater than the - input.

I am guessing that the question stems from the assumption that the output would be 0V without special circuitry. Such assumption might be based on another assumption that a comparator output is similar to a typical CMOS output.

Most comparators do not have CMOS type outputs, but open collector (sometimes open drain) outputs.

An open collector output requires a pull-up resistor (or something equivalent) and together with the pull-up resistor acts like a common-emitter inverter. simulate this circuit – Schematic created using CircuitLab

When the output transistor is "off", the pull-up resistor pulls the output toward Vcc. The actual voltage achieved will depend upon the output load. When the output transistor is "on", the transistor pulls the output toward ground, but the actual voltage achieved will be the saturation voltage of the transistor at current level dictated by the pull-up resistor and load.

0.2V is probably quite close to the voltage that one would see when the output transistor is on. In fact, the actual output voltage is probably closer to 0.2V than it is to 0V. The preceding assumes that the output transistor is a BJT and not an N-channel MOSFET. In the latter case, the output may in fact be quite close to 0V.

So, depending upon the purpose of the 0.2V output (if I understand correctly that that is what is desired), it may be that nothing at all need be done if a comparator with a BJT open-collector output is chosen. The saturation voltage may be close enough for what is desired.

However, if one wants to shift the output voltage, there are a number of things that can be done without changing the "ground" for the comparator.

For example, the following modification shifts the "low voltage" up. simulate this circuit

This circuits works almost the same as the previous. However, the "low" output voltage is shifted up by an voltage equal to $$\I_CR_{offset}\$$.

To make the example more concrete, suppose Vcc were 5V, Rpullup 1 k$$\\Omega\$$, and $$\V_{sat}\$$ 100 mV. Suppose we want $$\V_{out}\$$ to be 200 mV, rather than the $$\V_{sat}\$$ value of 100 mV. First we calculate the current through Rpullup = (5 V - 200 mV)/1000 $$\\Omega\$$ = 4.8 mA. Then we calculate Roffset needed to drop 100 mV. Roffset = 100 mV / 4.8 mA = 20.83 $$\\Omega\$$.

This method works well as long as the load current is much smaller than the current through Rpullup.

A similar trick can be played to lower the output voltage, by placing a shunt resistor between Vout and ground.

Again, this technique will work best if the load current is "small".

Rather than delving right into techniques for defining the output voltage more accurately, or overcoming loading effects, I will wait to learn more about the intent of the 200 mV, what problem specifying 200 mV is intended to solve, and whether or not my interpretation of the question is completely off-base.

• I've reiterated the goals to avoid confusion in 1st post. You were right wrt the "low" voltage output below threshold - in fact, values about 0.1-0.2 V should be fine! So a "natural" low-state output voltage is definitely worth trying. (As an aside, you said this applies to BJT-output comparator and not an N-channel MOSFET one - the latter is how the output of rail-to-rail devices is constructed?). Other piece of the puzzle is output of the circuit when sensor output is above the set threshold - it should be the sensor output itself (should "conserve" the top sensor V with <~ 30-50 mV drop) May 27 at 11:55