# How To Detect If Two Voltages Are The Same And Trigger An Output If They Are

Basically, I'm struggling to design a circuit with the following requirements:

Requirement 1: Output is high (say 5v) when the two input voltages are different. [If it makes it any easier the output voltage only needs to be high when, say, input 2 is lower than input 1. That is the output is 5v when voltage 2 is less than voltage 1.]

Requirement 2: As soon as the 2 voltages are equal, the output shoots down to 0v (grounded/low). [Or as soon as voltage 2 is in a few microvolts or nanovolts below voltage 1, ie they are very close, then the output immediately shoots to 0v.

Requirement 3: Once the 2 input voltages are no longer equal the output goes back to high (5v). [As soon as voltage 2 is out of the microvolts or nanovolts range below voltage 1, ie voltage 2 is below voltage 1 (voltage 2 will never be higher than voltage 1, it can only match it) then the output immediately shoots up to 5v.

I've tried using a basic subtractor using opamps, but you see the 2 input voltages are sinusoidal. This means the difference between the 2 inputs can be very small, and the output as a result, slowly decreases to 0 rather than immediately 'trigger/shoot down' to 0. It would be useful if the output was a steady 5v and as soon as say the 2 inputs are within a very small range of each other (say a few microvolts or nanovolts) then the output immediately drops to 0. Once the two input voltages are no longer in that range, then the output shoots back to 5v.

Thank you! Any help is appreciated.

• What is the voltage range and frequency of the input signal? e.g., "+1.3 V to +4.2 V, 50 Hz" or "-35 V to +23 V, 10 kHz". Commented Apr 8, 2018 at 15:58
• Voltage 1: is +6v to +2v at 1hz. Voltage 2 is actually a staircase waveform but it is of a higher frequency than voltage 1, and its minimum voltage is 0v, it's maximum voltage being +6v. Commented Apr 8, 2018 at 16:02
• But for the sake of this, we can treat Voltage 2 to be sinusoidal with a range of +6v to 0v and frequency of 10hz Commented Apr 8, 2018 at 16:06
• Do you want them "equal" within a nanoVolt? Do you want that equality to be identified within a picosecond? Commented Apr 9, 2018 at 17:14
• @analogsystemsrf If that was possible, then yes, that would be brilliant. Commented Apr 11, 2018 at 14:24

You are looking for a specialised "window comparator". As the name suggests this would use comparators rather than op-amps. (The symbols look the same but their internals are different.) Many of these have open-collector outputs which makes logical OR functions quite easy to implement.

Figure 1. A basic window comparator using a fixed voltage reference. Notice that both open-circuit outputs are tied together with a pull-up resistor. Source: Electronics Tutorials.

The problem with this circuit is that the reference voltages are fixed. You want the reference voltages to track the other input.

More later. I have to put on the rice ...

... Rice is on.

simulate this circuit – Schematic created using CircuitLab

Figure 2. The tracking window comparator concept.

• With the arrangement of Figure 2 a fixed current is run through R1 to IN2 which causes CMP1 + input to be I1 x R1 volts higher than IN2.
• Similarly a fixed current is run through R2 causing CMP2's - input to be I2 x R2 volts lower than IN2.
• In theory I1 and I2 should cancel out causing no current draw from IN2. In practice IN2 will have to supply the difference in currents due to imperfections in the current sources.
• The result will be a moving window with fixed offsets that track the voltage at IN2. This defines the tolerance for "voltages equal".

Your challenge will be to design the constant current sources. I suspect that you might have to use a negative voltage rail for I2 and a few volts more than 5 V for I1.

Rice nearly done ...

• you might mention the very important 'equal to a tolerance', that is, the width of the window. Commented Apr 8, 2018 at 16:07
• If it was up to me, I'd ban the use of current source symbols in the circuits altogether. Looking at this, thinking "hey, just one window comp chip and couple resistors... simple!" And then I see those two current sources and realize that it is impossible to judge the complexity of the circuit at all :( No wonder it end's up with "concept" subtitle. Commented Oct 9, 2018 at 17:21
• @Maple: Here you go, laddie: CRD-1407. Commented Oct 9, 2018 at 17:32
• Ooops... I had no idea something like that exists :) But... would they work in series? Commented Oct 9, 2018 at 17:33
• Kind-of maybe. Look at the I-V curves. Since they're not perfectly flat they should stabilise but maybe with differing voltage drops. I agree with you that I took a big shortcut but was aware of these devices although I've never used them. Do a search for "constant current diodes". There seems to be a market for LED applications and 20 mA versions are popular. I wrote about them here. Commented Oct 9, 2018 at 17:47