# Sine to square wave circuit

Following this question Sine wave to square wave - Schmitt trigger, I am trying to simulate a sine to square wave circuit using an op-amp. I am playing around with components values to see their influence.

What is the role of R4? The signal at the non-inverting input of U2 is distorted when I increase its value.

And with R4 = 100k :

When I change the LT6202 for a LT6220 the signal at IN+ is not a sine wave anymore.

With R4 = 10k:

With R4 = 100k:

What is happening?

• The LT6220 is a faster op-amp with a higher slew rate compared to the LT6202. This higher speed might be causing instability or other issues in the circuit, resulting in distortion of the input signal. Commented Apr 29 at 15:01
• The LT6202 has a higher SR (25V/µs) than the LT6220 (20V/µs). Commented Apr 29 at 15:12
• In a theoretical circuit, voltage source drives the midden point of R1-R2 ... R1-R2-D4 can be "forgot" ... Commented Apr 29 at 16:04
• There is no U2, what do you mean? Commented Apr 29 at 18:29
• @JeanB_01 I'm not even very sure what you need to know? You want to learn about these, generally? (There are much less complex circuits using opamps to get the job done.) Or are you trying to solve some specific (unspecified) problem, but are just exploring directions right now? Or something else? Do you care if an opamp is used, for example? Or would bipolar BJTs be just fine? You have a single supply opamp in use, but a zero-centered AC signal input. Is that a requirement? Or an accident of your testing? What's D4 R1 and R2 doing for you? Etc. Commented Apr 29 at 19:03

I'll use the term "comparator" below, as that is its role of the op-amp in this application. Be aware, though, that the LM6202 is an op-amp, intended for analogue applications, although it should work fine here too. Usually you would use a purpose built comparator, such as the good old LM393 (which has open-collector output) or the LMV7239. There are literally hundreds of suitable devices available. Comparators are different from op-amps in that they have purpose-built digital outputs, and a small amount of hysteresis built into their inputs, which improves performance and stability.

R1, R2 and D4 are redundant. They look as if they are intended to bias the signal between the supply rails, somewhere near +2V. They will be completely over-powered by even a modest-output-impedance voltage source, and you can dispense with them. The required biasing is performed by R5 and R6.

R4 seems to protect the comparator input from excessive current that would flow if that input were to stray outside the 0V to 5V limits. The IC's input protection diodes would become forward-biased, and conduct heavily (if they are even present). R4 effectively throttles current in such circumstances, and is well advised.

It is not advised to rely entirely on the comparator's own input protection for such "clamping", and if it's likely that the input might violate the comparator's acceptable input range, then it would be prudent to implement your own protection, with D1 and D2 here:

simulate this circuit – Schematic created using CircuitLab

If you know that the input source will never exceed a couple of volts amplitude, then you won't need R4, D1 or D2. Here, though, R4 is retained, and you can relax in the knowledge that even if the amplitude of input $$\V_{IN}\$$ is too large, then R4 and one of those diodes will prevent the comparator input from straying far outside the range 0V to +5V, saving your comparator from destruction.

Usually you would choose the ratios R5:R6 and R7:R8 to provide potentials close to half-way between the comparator's acceptable input range. Since the LT6202 will work with inputs extending all the way to either supply, R5=R6 and R7=R8 are good choices, setting all bias potentials at exactly +2.5V. If you were to employ the LM393 comparator, the inputs should not exceed $$\V_{CC}-1.5V\$$ (as described in the datasheet), and you'd choose these resistances to produce a potential half-way between +3.5V and 0V instead.

Don't overlook "power supply bypass capacitor" C1. A comparator's output transitions between high and low will cause significant momentary current spikes at the power-supply rails, causing dips and peaks in what should be a clean +5V supply. C1, installed close to the IC's supply pins, mitigates this by becoming a temporary source for the required current transients, keeping the +5V rail where it should be, at +5V. In a simulation, where all interconnections connections have 0Ω resistance, and 0H inductance, C1 won't make any difference, but when you build this in real life, C1 will save you from some big headaches.

### background

The earlier Schmitt triggers were based on bipolar transistors. If you are curious, see my answer here where I also include many references to examine and read plus just such an early schematic. I also include the understanding of how they work and the mathematical approach solving for their behavior.

A single-supply version using an opamp is configured in my answer here, where I provide a way to calculate the resistor values. In that case, however, I used a DC-biased AC source. In your case, where you are using a signal that is centered around ground, a DC-blocking capacitor of sufficient size would be needed.

You don't specify practical details. So I'm not sure if you are just exploring the concepts or if you actually do have a practical problem, but aren't sharing the details with us, yet. If practical, details such as the current compliance of your source (or its source impedance) would be needed and also what kind of load is using the results of the Schmitt trigger circuit. Otherwise, it can be treated as more educational, I suppose.

Since I have no practical information, let's look at both circuits using an ideal signal source as you have already specified (ground-referenced, infinite current compliance, and $$\\pm 3\:\text{V}\$$.

### bipolar version

Here's an example using bipolar transistors:

simulate this circuit – Schematic created using CircuitLab

(I used a large DC-blocking input capacitor, $$\C_1\$$, because of the low frequency.)

Here's the output as given by LTspice, with input signal on top and in red color and the output signal on bottom and in green color:

As you can see, it appears to work well. (At least in simulation.)

### opamp version

Here's an example using an expensive LT1800 (nice rail to rail input and output opamp):

simulate this circuit

(I again used a large DC-blocking input capacitor, $$\C_1\$$, because of the low frequency.)

Here's the output as given by LTspice, with input signal on top and in red color and the output signal on bottom and in green color:

As you can see, it also appears to work well. (At least in simulation.)

### summary

I used design information available in the two answer links I provided at the output in order to develop the above two circuits. There is information there to both understand and create designs.

None of this necessarily helps you to understand your own circuit. I don't understand why some of it is there, myself. So I'm not going down that rabbit hole.

R4 limits the current through the C2 cap and make it harder for it to push AC current through to the schmidt triggers terminal. It would be best to let this current through as it allows the sine wave to affect the bias point of R5 and R6. You might be able to play around with the values of R5 and R6, but I'd just leave it like it is.