# Why would a comparator be a better fit to create square waves in this RL oscillator?

I've been playing around with this circuit (Ctrl+S on the text view): It's an RL relaxation oscillator producing square waves rail-to-rail.

The LTC1441 in place is a comparator. The rise could be steeper, but I suppose you could blame that on the slew rate and other minor properties of the comparator. When I try to use opamps in place of it I get, at best, non-rail-to-rail, sharp, sinusoidal waves. Why would a comparator be better at creating square waves than an opamp with a slew rate of 10V/µs? Is it because it's designed to hit the rails with the tiniest difference in the inputs? Then wouldn't being able to adjust gain to the highest it could go be the solution? Yet instead one input is for the bouncing oscillation and the other is to set the threshold.

The opamp tested against is MAX4489 (MAX4488's dual opamp version, as I had trouble with wiring up the MAX4488.) Mainly chosen for being rail-to-rail and its 10V/µs slew rate.

EDIT: I'm just starting to try out different opamps & I'm surprised as to how different each one are. Just look at how different the waveforms are.

• I think square vs sine wave might not be sufficient criteria to decide whether it's working. Reasoning: What if you wanted a sine wave oscillator? Does that suddenly make the circuit okay? Clearly not since the frequency is different. At least one circuit is not functioning according to the intentions of the schematic. You did not say what the input and output range of the opamp was. Rail-to-rail is the minority. Jul 9, 2022 at 19:49
• There's no input. It's a relaxation oscillator. Even at an undefined input initial state, it'll find itself to start oscillating. Jul 9, 2022 at 20:00
• The circuit doesn't have an input, but I am not talking about the circuit. Jul 9, 2022 at 20:01
• "It's an RL relaxation oscillator" - The LR time constant of 10uH and 100k ohms is 0.1ns. Your LTC1441 oscillator is ignoring it and just running as fast as it can. Jul 10, 2022 at 1:38

You think you're asking a simple question, and then you bump into Op Amp Weirdness.

For both of the circuits below, for most op-amps, with a "reasonable" value for the resistor (i.e., in the range that the op-amp can drive) and an $$\\omega = \frac{1}{RC} = \frac{R}{L}\$$ that's between $$\\frac{1}{100}\$$ to around twice of the op-amp's gain-bandwidth product, the circuit will oscillate. simulate this circuit – Schematic created using CircuitLab

That's because most op-amps are unity-gain compensated, and the way this is done is to introduce a pole in the inner circuitry that tends to make the op-amp act like an integrator. That pole causes a 90 degree phase lag. Whatever other poles exist in the op-amp cause even more phase lags. Typically, semiconductor vendors will set the internal compensation so there's between 120 and 150 degrees of phase lag at unity gain (depending on how "sporting" they want to be).

Both of these feedback networks are low-pass, each one has a pole that contributes its own phase shift of up to 90 degrees lag. If there is a frequency where the phase lag is 180 degrees and the gain is higher than unity, then the op-amp will oscillate at that frequency.

Comparators tend to leave out the internal compensation, because they're not supposed to work in the middle of their output ranges. There are comparators that can be coerced into acting like op-amps, but that's not a sensible or reliable thing to do with them. So if you select an op-amp and a comparator of similar slew rate, the comparator will tend to have much less phase lag than the op-amp, at least up to the op-amp's GBW product.

If you want a circuit like yours to work with an op-amp, you probably need to add some phase lead to the feedback, by putting an appropriate resistance in series with the inductor, such that there is some positive phase margin in the circuit. Then you'd need to adjust the amount of positive feedback to overcome the negative feedback you added with that resistor, so that your hysteresis would still work as planned.

• What does it mean to introduce a pole into circuitry - as opposed to introducing a capacitor? Aug 22, 2022 at 21:11
• Cause and effect. A pole is a mathematical entity in the Laplace or Fourier domain; it's the result of any independent linear element that stores energy over time. So a capacitor and an inductor can both introduce a pole into a circuit (in fact, that's what happens in both of my example circuit), a flywheel or a mass usually introduces two, but sometimes one depending on the surrounding mechanism. Aug 23, 2022 at 2:56
• Another answer says "single-pole lowpass filter" which seems much more useful to me. I just wonder why people talk about adding poles instead of adding low-pass filters. I suppose it makes sense for people well-versed in control-theory. Aug 23, 2022 at 21:33

Generally speaking, one of the main differences between a sorta-identical comparator and opamp is that the opamp usually is internally compensated so it does not break into oscillation in low or unity gain circuits. The compensation is done with a capacitor in shat is effectively a single-pole lowpass filter. This limits the available gain at high frequencies and slows down the slew rate.

OTOH, speed and propagation delay are a big deal in comparator circuits, and they usually run wide open with little or no negative feedback, so there is no compensation capacitor in a chip that is grown specifically to be a comparator.

Update:

At high frequencies, an opamp's slew rate limit can straighten out the curves in a high frequency sine wave where the maximum rate-of-change (near the zero-crossings) is greater than the opamp's max. slew rate. When this happens, the output resembles a triangle wave with rounded tops that are the upper portions of the original sine shape, and has a peak value that is less than that of the intended sine wave. This is the case in the second image. The frequency is much higher than the first, and the amplitude is much less.

As the frequency increases, more and more of the sine shape is straightened out and the resulting amplitude continues to decrease. Eventually, with a high enough frequency (relative to the opamp's capabilities), the wave shape is an asymmetrical triangle wave.

All of this applies to a square wave. As the risetime exceeds the opamp's slew rate, the edges begin to slant. At a high enough frequency, the rising edges are so slow that they do not reach the top of the waveform before falling. At this point, again you get an asymmetrical triangle wave as in the second image.

Lowpass: If you look at almost any opamp datasheet, you will find a chart of open loop gain versus frequency. For most general purpose opamps, the curve is flat to around only 10 Hz, then decreases at 6 dB per octave (20 dB per decade). This is the result of the internal compensation, often done with a "Miller capacitor", a form of integrator developed by John Miller in 1920. The capacitor reduces high frequency gain and introduces a phase shift in the signal to increase the phase margin at the output.

• Low-pass? But, as the 2nd pic shows, it's producing higher frequency. Jul 9, 2022 at 20:29
• Reduced slew rate straightening the curves? A straight slope can easily require higher slew rate than sinusoidal waves. So if anything, it should get squashed more. Jul 9, 2022 at 20:31
• The op-amp you have chosen is a relatively high bandwidth one, and the comparator chosen is relatively slow. Typically comparators are for open-loop/oscillation operations, and op-amps are for closed-loop/nulling operations. Jul 9, 2022 at 21:02
• When people talk of hysteresis for comparators they normally mean the threshold voltage levels changing based on the output state. The comparator having a slow output propagation time is not hysteresis. Jul 9, 2022 at 23:47
• True. And, hysteresis has nothing to do with the output stage slew rate. Jul 10, 2022 at 0:19

Why would a comparator be better at creating square waves than an opamp with a slew rate of 10V/µs?

It isn't really 'better'. The L/R time constant of your 10 μH inductor and 100 KΩ resistor is 100 picoseconds. The comparator is far to slow for this to have a significant effect, so your circuit is equivalent to this:- simulate this circuit – Schematic created using CircuitLab

The oscillation frequency is determined by delays inside the comparator. It is simply running as fast as it can.

If you increase the L/R time constant to a more reasonable amount (eg. 10 mH / 1 kΩ = 10 μS) then it will work properly, and an op amp with similar bandwidth should perform similarly. Here's the output of an AD820 (slew rate 3 V/μS) with those inductor and resistor values:- 