The comparator
A comparator asks one question, sample by sample: is its + input higher than its − input? If it is, its out sits at its high rail (the top of the voltage it can reach); if not, at its low one. Give it a capacitor and three resistors and it makes its own square wave.
New words

A comparator is an op-amp's cousin with only two answers: its out is at its high rail while its + input is above its − input, and at its low rail otherwise.

A relaxation oscillator charges a capacitor until something flips, then lets it run back the other way: a square wave, with no oscillator module.
1Writing one
Write a comparator as an op-amp, with the word comparator after its three points: its + input, its − input and its out.
U1 plus minus out comparator [rails 10V | rails -5V 12V] [open]
- Its out is at its high rail while its + input is above its − input, and at its low rail otherwise. Without
railsthey are +13.5 V and −13.5 V. rails 10Vis ±10 V;rails -5V 12Vgives lopsided rails.openmakes its out an open collector: it can pull its out down but not up (joined to its low rail through 10 Ω while it is low, let go at 100 MΩ while it is high), so give it a pull-up resistor to a supply.- It needs no feedback. An op-amp in SynthMaker needs a way from its out back to its − input; a comparator is made for the other way round, feedback to its + input.
- It switches inside the step: SynthMaker works out where between two samples its inputs crossed, so an oscillator built round it keeps its pitch instead of snapping to whole samples.
2A square wave from a capacitor
In Comparator Oscillator, R1 and R2 put half of the out on the + input. Rf charges C1, on the − input, towards the out. When C1 gets past the + input, the out flips to the other rail and C1 turns back. One cycle takes 2 Rf C1 ln 3 (its period): with 10 kΩ and 100 nF, 2.2 ms, about 455 Hz.
Against that formula, the period comes out within 53 parts in a million at the plain sample rate (1×), and within 13 at twice it (2×), where a comparator runs unless the circuit says otherwise.
# A relaxation oscillator. The comparator's out is +10 V or -10 V. R1 and R2 put half of it on its + input, and Rf# charges C1, on its - input, towards it. When C1 gets past the + input, the out flips and C1 turns back. Its period# is 2 Rf C1 ln 3: with 10k and 100n, about 455 Hz. tune turns Rf. R0 gives the unused input, in, a way to ground.circuit Relax setting output: 10 V, from 1 V to 40 V setting tune: 10k, from 47k to 2.2k R0 in gnd 1k U1 p m out comparator rails 10V R1 out p 10k R2 p gnd 10k Rf out m tune C1 m gnd 100nend

3A Schmitt trigger
Feed a slow wave into a comparator through a resistor, and take some of its out back to its + input. Now it flips up at one voltage and back down at another, so a wobbly input can't make it chatter. Here it flips at +5 V and −5 V: 10 V times 10 kΩ over 20 kΩ.
R1 in p 10k
R2 p out 20k
U1 p gnd out comparator rails 10V
Put an integrator (an op-amp with a capacitor as its feedback) after it, and feed the integrator's out back into the trigger: the pair is a function generator, a square from the comparator and a triangle from the integrator. With 10 kΩ and 100 nF in the integrator it runs at 500 Hz.
4Its limits
- A circuit holds up to 4 comparators.
- With only resistors, capacitors and ideal op-amps around it, each comparator switches at most once a step, so a reset shorter than a few steps (samples) doesn't work there: it would cross both of its switching points within one step. Keep each reset longer than a few steps, or oversample. With a diode, a transistor or an op-amp with rails in the circuit, even a reset shorter than a step works.
- It switches at once: no slew (the time a real one takes to swing), no input offset, and no delay.
Try it
- Open Comparator Oscillator and hold a key.
- Turn
tunedown toward 47 kΩ: the note falls, since the period grows with Rf. - In the parts list, change
R2 p gnd 10kto4.7k: C1 has less far to go, so the note rises. - Change
C1 m gnd 100nto47n: a little over an octave up, since the period grows with C1 too.
Remember
- A comparator is
U1 plus minus out comparator: its out at one rail or the other, ±13.5 V unlessrailssays otherwise. - It needs no feedback, and switches inside the step, so its oscillators keep their pitch.
- Its oscillators keep their pitch, whether the reset is a resistor, a diode or a switch.