## søndag 6. oktober 2013

### Saw frequency divider

In my previous post I described how to make a frequency doubler for a saw wave. Now, more often synths have a frequency divider/sub oscillator. These are usually square wave oscillators, but I wanted one that would work with saw waves. After an initial idea and a lot of trial and error I have finally come up with a working circuit. It works on the same principle as the frequency doubler, i.e. it shifts parts of the wave up and down to achieve the saw form, but instead of cutting each sawtooth in half, it combines two teeth to make one with twice the duration.

 The central idea - half of the teeth are shifted up to double the frequency

Dislaimer: Allthough I came up with the concept of this divider myself, I've since found that the core of the divider is quite common, even to the point that the good old Roland SH-101 uses the same trick - with the same 4013 flip flop :-D. I have yet to see a saw version though.

Some of the interfacing tricks are from Horowitz and Hill, and the RC combination to slow down the feedback in the flip flop are from a site elsewhere on the net (can't remember where right now),

Here is how the divider works:

1) The input saw wave is fed through an op amp set up as a comparator. This turns the +/-5V input saw wave into a +/-15V square wave, 15V whenever the saw wave is >0V and -15V when it is < 0V.
 Saw wave is turned into a square wave by the comparator. Each vertical square equals 5V, so the saw wave is +/-5V and the square is +/-15V.

2) The signal is fed into a D-flip-flop. The internal protection diode in the flip flop chip chops off most of the negative voltage, so the Flip-flop sees a square wave of about 0-15V, in effect a clock signal.

3) The D-flip flop does the main work, and it works like this: Everytime the clock goes high, the value on the D input (0/1 e.g. 0 or 15V) is copied to the Q output. The inverse value is copied to the "not Q" output. The trick now is to connect the "not Q" output to the D input. In this mode, the Q will change state between 0 and 15 everytime the clock goes high. This means that it will take two input pulses to generate one output pulse, which means that the flip flop is a frequency divider, dividing by a factor two. In many synths the output from the flip flop is connected to a second flip flop to get a divide by four-frequency divider. This makes it possible to switch between 1 and 2 octave sub oscillation. In this circuit however, only the divide by two is used.
 Input vs output of the flip flop.  Negative part of square wave is chopped off at the flip flop input. Notice how every high pulse on the input results in a change of the output. NB: The horizontal scale of this picture is half that of the previous one, so the input here are the SHORT pulses, the output are those with the same length as the ones in the previous picture. Also note that the small "ticks" in the middle of each horizontal line are because I forgot to ground the flip flop...

 The flip flop output compared with the input saw wave. The square wave is positive for every second saw tooth, i.e. has half the frequency

4) Now we have to turn the square wave with half the frequency back into a saw wave. Like with the frequency doubler we achieve this by combining the original signal with the square wave. But instead of shifting parts of the original wave closer to the 0 volt line to spit it in two, we shift then further apart to combine two saw teeth.

5) Before combining though, we have to adjust the amplitude of both the original saw wave and the square wave to keep the result within a 10v p.p. range. Also, because the square wave is not centered around 0V (unlike the square wave used in the frequency doubler), we have to add an offset voltage. The outputs of the three operations are summed to give the resulting half-frequency saw wave

 Original saw wave

 Resulting saw wave. The spikes half way through the wave are presumably caused by the spike at the start of each wave, though this has not been confirmed

 The two waves compared. It sounds great!

The circuit looks like this:
 Notice: The square wave in the top right corner is wrong, it should start at -5V, not 0V.

A few things to note about the circuit:
1) The 12k resistor between the comparator and the flip flop limits the flow of current into the chip as it can only handle about 10mA of input current. (page 578, Horowitz and Hill)

2) A 2k2 resistor and 100nF capacitor has been connected between the "not Q" and D ports of the flip flop, to delay the signal between the ports slightly. Without these I could not get my flip flop working. I find this a bit odd since other designs usually do not have these.

3) The output from the flip flop is buffered by an op amp in buffer configuration before it is used in other parts of the circuit.

4) Like the frequency doubler, the next stage is an attenuator (amplifier with gain < 1), found here. It turns the 0-15V square wave from the flip flop into a -5-0V square wave. NB: The wave is inverted, +15V turns into -5V.

5) the same thing is done with the saw input, it is attenuated from a +/-5V wave to a +/- 2.5V wave. Summing the square wave and the saw wave will result in an output with a 10V p.p swing, just like the input signal.

6) However, the signal goes from +2.5V to -7.5V. To adjust the symmetry back to +/-5V, we add a DC voltage of 2.5V, which comes from the 100k potentiometer and is buffered by yet another op amp buffer.

There are a few issues about the circuit though, and it should not be considered final.

1) First of all, because of the 12k resistor after the comparator, the input to the flip flop has a slow slew rate, which is a problem at high frequencies. I started seeing (and hearing) problems due to this at input frequencies > 10kHz. Using two MOSFET transistors for interfacing may solve this, I have not tried that yet.

2) The comparator may "bounce" when crossing 0V (i.e. going between +/-15V very fast), which will lead to multiple clock pulses going into the flip flop. This can be solved either by setting up a hysteresis configuration, using a comparator with built in hysteresis or passing the signal into a CMOS buffer with built-in schmitt trigger before the flip flop.

3) Likewise, the output from the flip flop may be connected to another CMOS buffer like the 4050, this may remove the need for the op amp buffer (I have not tried this yet - see page 586 in H & H).