Triangular waveform to square waveform circuit
A comparator is used to produce square waves:







simulate this circuit &ndash; Schematic created using CircuitLab

At high frequencies (\$ &gt; \frac{1}{2\pi R C}\$), the R-C filter passes only the DC offset of the input signal, and the output switches at the zero-crossings relative  to this level.

At low frequencies, the R-C filter simply produces a time lag and the output switches based on the slope of the input signal.