## Creating my first (intentional) oscillator, part 1.

As part of my RF beacon project I needed to built an oscillator, not just wanting to copy something I had to jump through a number of hoops to really understand what was going on. The practical limitations when building oscillators are actually pretty complex.

For a feedback system like the one below to be in stable oscillation it needs to adhere to the Barkhausen stability criterion, which requires two things:

• The loop gain should be 1 – IE, the input should be as big as the output. We can actually cheat here in practice. Given that actual amplifiers have non-linear characteristics near the rails, if the gain is too much the universe will clip it for us. The signal might not be pretty but it might still oscillate. Or as I read somewhere on the web “Linear steady state oscillators are mathematical fiction, you cannot balance on the razor’s edge.”, your loop gain is always going to be more than one. The downside of this is the higher you make your gain the uglier your signal will be, making it lower will clean it up but could cause it to drop out of oscillation.
• The phase shift around the loop should be a multiple of 360 degrees – This basically says the signal output by the amplifier (and possibly phase shifting circuitry) used above should be in phase with the input. Thus if we use an inverting amplifier we need another 180 degrees of phase shift to make up the rest.

What initially confused me about oscillators was, if we feed the output back into the input why wouldn’t the value just remain constant? The second point above solves this for us in practice. Circuit elements that create a phase shift don’t do this for all frequencies, you generally only get the desired phase shift at a specific frequency. This frequency will be our oscillation frequency. In addition, other frequency elements will be attenuated in real world applications, which is why our output can be ugly while still maintaining oscillation.

The easiest amplifier to understand (for me at least) is the simple four resistor NPN configuration, while not the ideal for this type of application it does work and is easy to follow. It gives a 180 degrees phase shift so we will need a frequency selective feedback stage that provides another 180 degrees of phase shift. Our initial circuit thus starts of like below:

The easiest way to create this phase shift is by using a quarts crystal, this way we can avoid winding coils. A quarts crystal can be represented as a LC series and parallel circuit with a very high Q, IE, it is selective over a very small frequency range. Given that it is both series and parallel resonant (IE, gives a very low or very high resistance based on frequency) within a couple of kHz, it enables us to use other components to create a 180 degrees phase shift. Recall that a voltage divider created by at least one reactive component gives a phase shift.

You often see the PI configuration when used with crystals, the resistor R1 (below) is often ignored in explanations but it is actually pretty important. In Pierce oscillators this resistor is contained in the output impedance of the NOT gate. Along with the capacitor C1 this provides the first phase shift to our signal, although not a significant portion of the final phase shift, it is needed. The crystal and C2 makes up the rest of the needed phase shift. So at some frequency the phase shift taken between X1 and C2 is going to be 180 degrees. How do we go about choosing R1, C1 and C2 to work at this frequency? Well in short we don’t, this is almost entirely controlled by the crystal. You can tweak these values to alter the frequency slightly (called frequency pulling), but this is hardly needed in practice.

In the graph above fp and fs are actually pretty close together, within a couple of hundred kHz. A small increase in frequency will thus have a big change of the crystal impedance. With that in mind, in the circuit above some frequency will experience exactly the correct impedance through the crystal to form a 180 phase shift in combination with C2. Let’s say the R1 and C1 pair produces 5 degrees of phase shift at some frequency. At this same frequency the crystal would present a specific impedance that combined with C2 gives another 175 degrees of phase shift, completing our total. It should thus make sense that the values of R1, C1 and C2 can be used to alter the frequency, because the oscillator impedance changes so quickly over a small frequency range you don’t really have to worry about it though.

Crystal manufacturers generally specify the capacitor values to use for Pierce oscillators, these should work fine in most cases. Although you might find that your frequency isn’t exactly what is stated it will be pretty damn close. Creating a phase shift in a signal generally attenuates it, we thus need to amplify it again before passing it back to the system input. So we can just amplify it with something like 1.1 to make up for losses etc? Well no, but we can test how much amplification we would need fairly easily. I built the circuit above to get a feel for how this would work and got the following output.

Using a 3.579Mhz crystal, 15pF capacitors and a 1K resistor I adjusted the frequency until the output was exactly 180 degrees out of phase to the input. This shows that with this configuration the output is 2.3 times smaller than the input.We now have a pretty decent idea of how our circuit should look and what gain we need to achieve. The final phase shift of 180 degrees was at 3.5798Mhz. Let’s look at our first circuit attempt: