# Basic OpAmp as a Comparator question

I'm continuing my refresher on electronics, and want to validate a conclusion/deduction that I'm reaching. Consider the two comparator circuits below:

In both cases:

• I have chosen not to picture decoupling capacitors for simplicity/clarity
• The input waveform is a 6 Hz square wave that is 3.25 volts peak to peak
• The output waveform is a 6 Hz square wave that is 5 volts peak to peak

Question:

Is the primary reason to build a comparator using a voltage divider on the (-) input to set a threshold voltage (2.5 volts, in this case), preventing stray signals from triggering the output? (My intuition and very foggy memory says "Yes"). If so, is there any other reason to do so?

What I was seeking to accomplish was a level shifting buffer to bring things up to a normal TTL range.

• by the way, what's a "normal" TTL range to you? (To me, with TTL defining the high-level to start at 2.0 V, your original square wave is already solidly TTL-compatible.) Commented Aug 3, 2019 at 11:26
• Wel, ideally 0 and 5, but the threshold is usually around 3.3-3.6 volts on the positive going edge if I remember correctly... which is why the 3.25 needed to shifted. Commented Aug 3, 2019 at 11:29
• That sounds like classical CMOS logic (74HCxx) operated with a supply voltage of 5V, not like TTL! Commented Aug 3, 2019 at 11:33
• Well, @MarcusMüller, I'm generally working from memory after 30+ years, so I'm sure I'm remembering lots of things incorrectly. :) Commented Aug 3, 2019 at 12:39
• David, I find that more admirable than criticizable! Commented Aug 3, 2019 at 12:55

• The input waveform is a 6 Hz square wave that is 3.25 volts peak to peak
• The output waveform is a 6 Hz square wave that is 5 volts peak to peak

I'm assuming this means your square waves have as low voltage 0 V (i.e. VSS potential), and 3.25 an 5V as high level, respectively. "Square wave with a Vpp" is a bit ambiguous, because it doesn't say anything about the average voltage. Your opamp's lowest possible output voltage is Vss+Voffset, and in a good approaximation that's VSS=0V.

Is the primary reason to build a comparator using a voltage divider on the (-) input to set a threshold voltage (2.5 volts, in this case), preventing stray signals from triggering the output? (My intuition and very foggy memory says "Yes"). If so, is there any other reason to do so?

The motivation is to use a selectable voltage (defined by the voltage divider) as comparison threshold. This doesn't fulfill the role of hysteresis or similar, so not quite sure where "stray signals" come into this.

If you want a level shifter with Schmitt trigger, it's probably wisest to just buy one; in fact, you can buy speciality level shifters like the especially promising SN74LVC1T45 that can pretty much be adapted to arbitrary voltages, or you can just get a 74xx logic family IC that accepts your voltage range of interest and outputs a suitable voltage range on its output (with your voltages, 74HCTxx is probably the go-to family). Pick an IC that has Schmitt trigger inputs if you're in for the extra noise immunity.

Your first circuit is highly problematic: your threshold voltage is the negative input voltage. Not many opamps support that – typically your input voltages need stay at least a couple mV away from your supply voltages. Depends on your Opamp! What you'd need is a Rail-to-Rail input opamp; since input is usually the harder part, the abbreviation RRIO is what you'd look for.

• Ah, I did not remember that about tying - to ground. Yes, I should have been more clear 0 to 3.25 in and 0 to 5 out. Commented Aug 3, 2019 at 11:30
• When I said “stray signals” I was actually meaning noise in the power rails/system. Especially since this is currently on a breadboard with an inexpensive switched supply, there was a great deal of noise on the rails until I added filters. Commented Aug 4, 2019 at 11:02
• the good news is that opamps typically have pretty good supply-noise rejection ratios, meaning that as long as the supply voltage doesn't drop close to or below output voltages, things will be fine. Problematic is if your supply voltage actually starts playing a role: for example, your voltage divider will of course divide the nominally 5V of the input. If that 5V is noisy, well, so is your comparison threshold. But: you can easily fix that by adding a capacitor across the lower resistor. Commented Aug 4, 2019 at 11:06
• Marcus: I'm hoping you'll entertain a follow-up. I don't want to start a new question over something that might be very trivial. After implementing the OpAmp to bring up the voltage level on the square wave, I found that the Z80 appeared to work (control signals for the first few steps)... but after a week of troubleshooting, determined that removing the OpAmp restored the Z80 to normal operation! It now works (I have at it about 780hz operating on a breadboard) but I can't think why the OpAmp would create an issue. The square wave was identical, just slightly higher voltage. Thoughts? Commented Aug 11, 2019 at 18:28
• puh, not really. I can just stab in the dark. latching up of the Z80 inputs, maybe? Commented Aug 11, 2019 at 19:21

Is the primary reason to build a comparator using a voltage divider on the (-) input to set a threshold voltage (2.5 volts, in this case), preventing stray signals from triggering the output? (My intuition and very foggy memory says "Yes").

Yes, the primary reason would be to set a threshold voltage at the point where you wish to discriminate between high and low values.

If so, is there any other reason to do so?

Yes. Your amplifier or comparator might not work very well with the input tied to one of the power rails.

Top prevent "stray signals" or noise triggering the output a more effective method is to add hysteresis to the comparator threshold (or input) by using feedback.