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:

Screenshot from 2014-09-04 13:47:22

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.

Screenshot from 2014-08-24 21:18:19

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:

Screenshot from 2014-09-04 14:01:28

Note that as the crystal acts as a bandpass filter we don’t need the an extra coupling capacitor in the feedback loop. So when closing the loop we need to amplify the output by 2.3 times to make up for losses? Nope,  a number of  other factors should be considered when designing a closed loop system. The first of these is that loading the output of your crystal stage will bring down the output even more, you can compensate for this by ensuring that the input impedance of your amplifier is as high as possible and that you choose more gain than what you initially measured. Ideally you want your input impedance to be at least 10 times larger than your output impedance. It is worth noting that loading the output of your crystal stage will often deform your signal significantly, one way of working around this is to add a buffer stage after the crystal but before the feedback loop.

The second is that transistors don’t maintain their gain at any frequency, as you increase frequency the current gain of the transistor goes down. This is generally described as the current gain bandwidth product. For example, for the 2N2222 the current gain bandwidth product is 300Mhz. Depending on the configuration your gain would be around 100, thus we expect the gain to remain above 100 up to around  300/100, IE, 3Mhz. Meaning that if you want to operate at a higher frequency you have to compensate for a loss in gain when doing any calculations.

[To be continued in part 2]


~ by s3c on 2014/08/24.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: