Monday, July 29, 2013

Comparators Are Awesome

Ever wonder why people like comparators so much? In various applications they are useful, but being a synth blog, here are some neat ways to use comparators in a synthesizer. BUT FIRST...

~~~WTF is a Comparator?~~~

Simply put, a comparator compares two voltages, an input and a reference voltage. If the input is less than the reference, the comparator will output a voltage near one of its supply voltages. Usually this is performed by an operational amplifier, and the inputs can go in the negative or positive inputs. For our uses, you'll want the reference voltage going to the negative input, and you will want to power the opamp with +-5V.

Now, on to synth uses:

~~~Simple Square Oscillator~~~

You've seen me post about this before, but mate, it's useful. A basic Operational Amplifier oscillator is really a type of feedback-driven Schmitt Trigger. Here is the schematic and output (note that the cap is the general frequency range and the 100k resistor can be varied up or down, I usually use a 1M pot):

~~~Square-Saw-Tri-Ramp-Sine Generator~~~

Now, using the above oscillator, we can derive a few other features using a comparator after an RC lowpass (or highpass, but I'll be using a lowpass) filter. First, filter the output with an RC filter, like this:
The exact resistor value will vary from 10k depending on your frequency range, but make sure you get a generally triangle-like waveform along your whole frequency range. Then, set up a comparator after the filter with a voltage high enough that it only switches near the top of the triangle wave:
And then put another RC filter after that:
You may need an amplifier and DC decoupler stage after this, but once you do you get a saw wave. Now, this section says "Square-Saw-Tri-Ramp-Sine", yet all we have now is square, saw, and triangle. How do we get ramp and sine? Well, one way to get the ramp is to use 2 comparator/filter stages, the second being set to the equal but negative reference voltage as the first. Another is to simply vary the reference voltage, which will sweep the waveform from saw to triangle to ramp (which, by the way, is WICKED FUN).

As for sine, you can simply put a second, low-cutoff filter and amplifier after the triangle wave stage. It won't be perfect, but it will be similar enough for musical purposes... usually. Bear in mind that certain stages may require amplification, decoupling, or buffering, depending on exactly how you process the signals.

~~~Pulse Width/Modulation~~~

I suppose we should start with a couple definitions. Pulse width (also known as duty cycle) is the ratio of time between when a square wave is high or low. For example, a normal square wave is 50% pulse width because half of the time it is high, half of the time it is low. Pulse width modulation is the use of a modulation source to vary the pulse width dynamically.

Now, when I do PWM stuff, I use saw waves for easier control of the pulse width due to having a longer length of wave (from lowest to highest peaks) to work with. For the following pictorial examples I will be using the saw waveform generated using the above generator. All you do is put a comparator (opamp) after it and vary the reference voltage to the comparator.

~~~Unique square waveforms ~~~

If you decide it would be fun to put a comparator on a wavefolder, such as the Lockhart wavefolder, you're in luck. The following image is not mine, however the basic premise is easily replicated:
As you can see, a sine wave (first image) fed into the wavefolder does as you would expect: fold the waveform over itself (second image down) However, adding a comparator to the output (Vref is ground) gives you a unique square waveform. You can alter the reference voltage to get even more unique results, such as PWM. Very fun.

~~~Gate signal from Keyboard/Sequencer~~~

It is always useful to have a gate signal from a keyboard or a sequencer. And, I'm sure you've already figured out how to do it, but if you haven't, it's simple: on the keyboard voltage output, put a comparator referencing ground. If you play legato, you will have a constant gate signal, but if you separate your notes (always a useful thing to learn how to do), you will get a separate gate signal for each note. Cool, huh?

~~~Gating~~~

Sometimes, you need a noise gate or similar system. This is also pretty easy to do:
If you follow the schematic, know that I threw in arbitrary values and your needed values will vary. If you don't want to follow the schematic, don't worry. Here's how it works: Audio splits from the input to a VCA and a diode. The diode cuts out the negative voltages from audio. The diode is followed by a lowpass filter, which smooths out the signal, thus making it easier for the comparator to create a stable gate signal. The comparator (Vref is variable as to compensate for noise) outputs a high gate signal when audio passes and a low gate signal when audio is below the reference voltage. That gate signal feeds the VCA, which turns on and off the volume. Yaaay, gater.

Of course, there are more uses than just these. Play around, see what you end up with!

No comments:

Post a Comment