Crystal Oscillator Question (TS922 Op Amp)
Moderators: adafruit_support_bill, adafruit

Crystal Oscillator Question (TS922 Op Amp)

by mauifan on Sun Oct 21, 2012 10:55 am

Got a question for you that I was tempted to ask on Ask An Engineer, but I chickened out on the grounds that the question (and subsequent answer) was too complicated for a 15 second "sound bite." :D

I have been studying up on crystal oscillator circuits. My goal is simple: Come up with a circuit that causes a crystal to oscillate. There is quite a bit online about how crystals should operate, but not much in the way of troubleshooting and/or explaining to a novice.

I breadboarded a circuit using a LM324 op amp. Nothing I did worked. I tried again using your TS922. To my shock and amazement, it worked -- my oscope showed a perfect sine wave at 32k using a watch crystal! Amplitude was on the order of 1-2v.

Fast forward to earlier this week, I planned to replace the TS922 with the LM324 to see if it would work... but my son decided to "undo" my breadboard wiring before I got to it. Although I think I have restored the circuit, I can't seem to get the TS922-based circuit working again. At best, the circuit may oscillate... but the output is clipped. And sometimes I see some harmonics on my scope trace. In no case does it work as consistently as it did before.

So the questions I have are:
•What's going on?
•What is so different about the TS922 and the LM324?
•What's different?

In all instances, I have only been successful using the watch crystal. It never worked with a faster crystal. The circuit I used came from a diagram I found online somewhere. Don't remember where I found it... but basically it looked something like... well... I can't find the exact diagram, but it looked similar to the diagram shown in the bottom of page 6 in this article: http://www.niu.edu/~mfortner/labelec/lect/p575_04b.pdf

The only difference is that I added a 10k resistor between the op amp's (-) and ground to control the gain.

Help! Thx!
mauifan
 
Posts: 161
Joined: Sun Aug 12, 2012 10:13 pm

Re: Crystal Oscillator Question (TS922 Op Amp)

by john444 on Sun Oct 21, 2012 12:50 pm

Hi Maui,

mauifan wrote:it worked -- my oscope showed a perfect sine wave at 32k using a watch crystal! Amplitude was on the order of 1-2v.

That is surprising. Without some form of regulation, the signal should decay to 0 or increase until it clipped.

mauifan wrote:At best, the circuit may oscillate... but the output is clipped. And sometimes I see some harmonics on my scope trace.

This is what you will get without some method to control the amplitude.

There is a lot of stray capacitance on a breadboard. This capacitance makes it
very difficult to predict or duplicate breadboarded analog circuits.
Keeping these cautions in mind, here is what you might try to get it working again.
Using the circuit you referenced @ http://WWW.niu.edu:
1 place a large value (10-M) resistor across the opamp from output to + input.
This will provide some dc coupling.
2 place a resistor (100-K) in series with the crystal. This will limit the drive.
3 place small value caps (20-pF) on each side of the crystal to ground.
It is hard to know if the caps will be needed because of the already high stray
capacitance. Circuit placement on the breadboard can be critical.
The values listed are just a starting point. Expect to vary the resistor values to
achieve reliable oscillation. If it works the first time, you are just lucky.
4 Consider using the other opamp in the package to control the output amplitude.

Good Luck, John
john444
 
Posts: 443
Joined: Sun Mar 04, 2012 1:42 pm
Location: Claremore, Ok

Re: Crystal Oscillator Question (TS922 Op Amp)

by mauifan on Mon Oct 22, 2012 2:10 pm

Let me provide a little more information that in retrospect I probably should have mentioned earlier. Then I'll get to my question.

I can't be 100% certain, but that circuit schematic I referenced on NIU.edu looks suspiciously familiar. I think I tried that exact circuit (save using a watch crystal) and couldn't get it to work until I added a resistor between the op amp (-) and ground. Cannot for the life of me remember what that resistor value was... but I tried using a 1M pot. Varying the resistance of that pot resulted in different waveforms, but nothing seems to get me back to the sine wave I had before.

I should also mention that my original working circuit used pots rather than fixed resistors so I could vary the gain.

And now for my follow-up question....

I think I understand the high-level theory. Too much damping causes an oscillating signal to fade to zero. Too little causes the output signal to hit Vcc. Obviously there is a "sweet spot" somewhere in between -- but how do I know where that sweet spot is located? Theory says that you need a gain of slightly higher than 1 to compensate for circuit losses.
mauifan
 
Posts: 161
Joined: Sun Aug 12, 2012 10:13 pm

Re: Crystal Oscillator Question (TS922 Op Amp)

by john444 on Mon Oct 22, 2012 6:08 pm

Maui,

mauifan wrote:couldn't get it to work until I added a resistor between the op amp (-) and ground.

The opamp needs something to bias the input stages away from the + or - power rails.
A resistor to ground won't really do it unless ground is ½-way between the rails.

About the theory -
mauifan wrote:Theory says that you need a gain of slightly higher than 1 to compensate for circuit losses.

This is not quite correct. You want it to be 'exactly' 1 after all the loses.
However, this means that you need something to get it started and at the
magnitude or voltage level you want. Then you need something to actively keep
it there as components drift with time & temp.

So.. To answer your question -
mauifan wrote:but how do I know where that sweet spot is located?

You use some means of active regulation. An automatic gain control.
Google is your friend here.

If you had said a square-wave output was ok, then you could just use inverters.
But, if I understood correctly, you want a sine-wave output.

Best of luck, John
john444
 
Posts: 443
Joined: Sun Mar 04, 2012 1:42 pm
Location: Claremore, Ok

Re: Crystal Oscillator Question (TS922 Op Amp)

by mauifan on Mon Oct 22, 2012 9:47 pm

Another update, then more questions.

I revised my wiring a bit more. Same schematic, but the 10k resistor between op amp (+) and ground is now a fixed resistor. The resistors connecting to the op amp (-) are now potentiometers so I can vary the gain.

If I tweak the pots, I can get the watch crystal to oscillate, but the output is clipped -- it looks like a sine wave that has been fed through a diode. If I crank up the gain a bit more, I can get a second harmonic, which my scope sees as double the frequency (from 32kHz to 64kHz).

Which leads to my questions...

The description on https://www.adafruit.com/products/808 suggests (at least to me) that the TS922 is a more "forgiving" op amp that has "rail to rail input and output, which is a common problem for beginners who don't know how to bias op amps." However, you are telling me that I still need to be concerned with biasing?

I do get the high level concept of what biasing means, but I tried this on the LM324 with no success.

Getting back to my reference of a "sweet spot," is there a rule of thumb or something that will help me choose the correct resistors? My original goal was just to try to get the crystal to vibrate at its indicated frequency -- and I have kinda sorta been able to do that in the form of a sorta weird square wave. However, I do feel like I got lucky to some extent, so I hope to gain a greater understanding so I make the circuit do what I want without guessing.

THANKS!
mauifan
 
Posts: 161
Joined: Sun Aug 12, 2012 10:13 pm

Re: Crystal Oscillator Question (TS922 Op Amp)

by mauifan on Tue Oct 23, 2012 3:06 pm

Follow-on to previous post with the hope that I may clarify my question....

The schematic I referenced in my original post is for a 150kHz crystal. I used a 32kHz watch crystal. The broader question therefore becomes, What do I need to adjust to make the circuit work at the new frequency? I can understand that there might be a little bit of experimentation involved to find the exact "sweet spot," but isn't there a way to come up with an estimate that puts me in the ballpark so I don't have to guess?

Now to describe my latest circuit iteration....

The circuit I now have is essentially the same as the schematic on the NIU page, but with a 32kHz watch crystal rather than the 150kHz crystal shown. The 100k resistor is a 100k potentiometer. There is also a fixed 10k resistor between op amp (-) and ground, so I can vary the gain by a factor of up to about 10.

The 10k resistor in the diagram that connects between ground and op amp (+) is now a 1M potentiometer.

Varying the two potentiometers changes the output waveform in various ways, and I am able to get a near square wave with just the right settings. However, I don't fully understand why these settings worked, nor how I managed to get that sine wave. Is there an Op Amps For Dummies book or something that can explain this in jargon that I understand?

Sigh... I have read several tutorials, used Google, etc... but I just don't seem to be getting the finer details. :(
mauifan
 
Posts: 161
Joined: Sun Aug 12, 2012 10:13 pm

Re: Crystal Oscillator Question (TS922 Op Amp)

by mauifan on Tue Oct 23, 2012 3:15 pm

1 place a large value (10-M) resistor across the opamp from output to + input.
This will provide some dc coupling.

Can you explain? I can see how a 10M resistor (which BTW I don't think I have) might shunt some of the energy, but I am not certain what you mean by provide some DC coupling.
mauifan
 
Posts: 161
Joined: Sun Aug 12, 2012 10:13 pm

Re: Crystal Oscillator Question (TS922 Op Amp)

by adafruit_support_mike on Tue Oct 23, 2012 6:57 pm

Just so you know, sine wave oscillators are the electrical equivalent of tightrope walking. The closed-loop gain has to be exactly -1 to get a true sine wave. If the gain goes beyond -1, you get clipping and distortion. If the gain falls below -1, the circuit can't sustain oscillation.

For most sine wave oscillators, the 'oscillator' part is pretty simple. 'Keeping the gain exactly where it needs to be' is the complicated part. Bill Hewlett's master's thesis was on how to stabilize a Wein bridge oscillator using a light bulb as a nonlinear feedback element. That circuit was where HP started.

Here are links to a couple of classics on the subject:

http://www.ti.com/sc/docs/apps/msp/jour ... aug_07.pdf
http://www.ti.com/lit/ml/sloa087/sloa087.pdf

and a couple of general works on op amps:

http://www.ti.com/lit/an/slod006b/slod006b.pdf
http://www.ti.com/lit/an/sboa092a/sboa092a.pdf

The best reference I've seen for crystal oscillators specifically is by Matthys:

http://www.bgaudioclub.org/uploads/docs ... atthys.pdf

He goes into a lot of detail, then actually builds and tests the circuits to see how they perform.
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 9147
Joined: Thu Feb 11, 2010 1:51 pm

Re: Crystal Oscillator Question (TS922 Op Amp)

by john444 on Wed Oct 24, 2012 12:12 am

Maui,

I have not abandoned you. It is just that work has been sucking up my time.
Mr. Stone, Thanks for jumping in with some clarifications.

I will try to help with some of the issues here. There are multiple things going on.
mauifan wrote:I can get the watch crystal to oscillate, but the output is clipped -- it looks like a sine wave that has been fed through a diode.

Yes, this is what you should expect with the circuit you have. With enough gain to begin oscillation, the amplitude of the oscillation will increase until the peak voltage approaches the supply rails. The supply voltage is the maximum voltage the oscillation can reach (the flat spot).

mauifan wrote:My original goal was just to try to get the crystal to vibrate at its indicated frequency

The crystal is vibrating at it's frequency. You can cause the opamp to oscillate at the crystal frequency (the fundamental) or multiples of the fundamental (harmonics).

Now we are talking about the opamp issues.
mauifan wrote:the TS922 is a more "forgiving" op amp that has "rail to rail input and output

The TS922 is a nice opamp for many reasons. But, let's talk about why the LM324 didn't work as you expected. Where as the LM324 can also go rail-to- rail, it does not do it symmetrically. The LM324 uses bi-polar transistors in a totem-pole arrangement that simply means it can pull the output towards the (-) supply much stronger than it can pull the output up towards the (+) supply. The LM324 is only linear in the mid range and at moderate output current. The LM324 also has potential problems when the inputs are over-driven. The TS922 uses a CMOS process and the output transistors are very similar in gain and on-resistance. In addition, the input circuitry is immune to the problems of the LM324. So, as Adafruit said, the TS922 is more forgiving because it may still operate 'normally' even if not in the middle of it's operational range.

mauifan wrote:What do I need to adjust to make the circuit work at the new frequency?

The crystal sets the frequency of operation, not the resistors. The resistors are used to set the gain and DC bias the opamp so that it is within it proper operating range. The capacitors are used to stabilize the crystal and the AC signal component.

mauifan wrote:There is also a fixed 10k resistor between op amp (-) and ground

Are you using split supplies? In other words, do you have 2 power sources?

mauifan wrote:but I am not certain what you mean by provide some DC coupling.

A quartz crystal is a good electrical insulator. There will not be DC current through it.
The opamp (especially the LM324) needs an average voltage on it's inputs at about ½ of the total supply voltage.
Without some DC voltage source to keep the inputs near the center of the supply voltage (usually called ground), the inputs will drift up to the (+) supply voltage or down to the (-) supply voltage.

mauifan wrote:Sigh... I have read several tutorials

Mr Stone referenced some good material. They are all worth checking out.

And, good luck, John
john444
 
Posts: 443
Joined: Sun Mar 04, 2012 1:42 pm
Location: Claremore, Ok

Re: Crystal Oscillator Question (TS922 Op Amp)

by mauifan on Wed Oct 24, 2012 12:25 pm

john444 wrote:The crystal sets the frequency of operation, not the resistors. The resistors are used to set the gain and DC bias the opamp so that it is within it proper operating range. The capacitors are used to stabilize the crystal and the AC signal component.

Let me rephrase: Why doesn't the "black box" approach work? For example, why can't I take the original 150kHz crystal that this circuit was designed for and replace it with a 32kHz crystal with no other mods? or a 4MHz crystal?

Note: I understand that a 4MHz crystal may be a bad example due to the gain-bandwidth product, which I understand to mean as The faster you go, the less gain you get. But the broader question is about how to find the right balance. I am using pots in my circuit to give me some ability to experiment, but I'd like to get to a level of understanding where I don't have to guess quite as much.

Aside: I have noticed that my circuit is indeed quite sensitive to small pot movements. There are a couple of points where I can literally watch the amplitude of the waveform grow or decay over the span of a second or so with the tiniest bump of the pot.

john444 wrote:
mauifan wrote:There is also a fixed 10k resistor between op amp (-) and ground

Are you using split supplies? In other words, do you have 2 power sources?

Hmm... I am not 100% sure, but I think the answer to your question is no. I have been doing my experimentation with a Radio Shack Electronics Learning Lab that I bought ~15 years ago. In case you aren't familiar with it, it is basically a breadboard with several different components (e.g. the pots I mentioned) that you connect via springs. It is powered by 6 AA batteries in series. Internally, the batteries connect to the breadboard to provide 1.5V, 3.0V, 4.5V, 6.0V, 7.5V, and 9V power rails. My TS922 based circuit connects to the 6V rail (though it works pretty much the same on any rail other than 1.5V).
mauifan
 
Posts: 161
Joined: Sun Aug 12, 2012 10:13 pm

Re: Crystal Oscillator Question (TS922 Op Amp)

by adafruit_support_mike on Wed Oct 24, 2012 5:08 pm

mauifan wrote:Let me rephrase: Why doesn't the "black box" approach work? For example, why can't I take the original 150kHz crystal that this circuit was designed for and replace it with a 32kHz crystal with no other mods? or a 4MHz crystal?

Take a look at this datasheet: http://cfm.citizen.co.jp/english/product/pdf/CM309S.pdf specifically the "motional (series) resistance" table at the bottom of the page. A crystal running at 3.5-4MHz has a series resistance of out 200 ohms. One running at 10-27MHz has a series resistance of 50 ohms.

Now check this datasheet for a 32kHz crystal: http://www.mouser.com/catalog/specsheet ... -ab26t.pdf . The ESR is about 30 kilohms.

In light of those facts, your question becomes "why can't I replace a 200 ohm resistor with a 30 kilohm resistor and expect the circuit to work?"
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 9147
Joined: Thu Feb 11, 2010 1:51 pm

Re: Crystal Oscillator Question (TS922 Op Amp)

by john444 on Wed Oct 24, 2012 7:49 pm

Maui,

mauifan wrote:Why doesn't the "black box" approach work?

Mr Stone answered the question pretty well.

mauifan wrote:I have noticed that my circuit is indeed quite sensitive to small pot movements.

That is what I would expect. Component parameters change all the time, temperature,
humidity, the solar cycle and anything else you can think of. Those changes will
produce the effect of dampening or enhancing the oscillation.

mauifan wrote:Are you using split supplies?

I believe that you might have better luck with the LM324 (and the TS922) if:
when powered from 6 AA-cells, you connect the (+) connection to the opamp
Vcc+. Connect the (-) lead of the AA-cells to the opamp Vcc- and
make a connection at the 4.5-V point of the AA-cells and connect it to the
places on your circuit identified as ground (Gnd).
This will 'bias' the opamp near the center of the supply and provide a
wider operating range. You might be able to see a signal of about 8-Vpp
before clipping.

I hope you noticed that most of the example circuits use a single transistor
or at most only a few. I do not remember any examples where a opamp is
used to drive a crystal. In this type of application, there can be lots of variation -
from mfg to mfg & model to model.

Good luck, John
john444
 
Posts: 443
Joined: Sun Mar 04, 2012 1:42 pm
Location: Claremore, Ok

Re: Crystal Oscillator Question (TS922 Op Amp)

by mauifan on Wed Oct 24, 2012 9:25 pm

mstone@yawp.com wrote:Take a look at this datasheet: http://cfm.citizen.co.jp/english/product/pdf/CM309S.pdf specifically the "motional (series) resistance" table at the bottom of the page. A crystal running at 3.5-4MHz has a series resistance of out 200 ohms. One running at 10-27MHz has a series resistance of 50 ohms.

Now check this datasheet for a 32kHz crystal: http://www.mouser.com/catalog/specsheet ... -ab26t.pdf . The ESR is about 30 kilohms.

In light of those facts, your question becomes "why can't I replace a 200 ohm resistor with a 30 kilohm resistor and expect the circuit to work?"

I am not sure, but I think you just provided a small "aha" moment. :D

If I understand you correctly:

ESR in a crystal decreases with increased frequency. Therefore, the resistor values external to the crystal must be adjusted (i.e. increased when going to a higher frequency) in order to maintain a gain=1.

Still not sure about how to calculate the losses so I know how much gain to add from the op amp, but hey... if the above statement is true, I may be one step closer to understanding this subject.

That said, I am guessing that the loss I need to compensate for has everything to do with the crystal's ESR and that losses through the crystal's capacitors and inductor (reference the equivalent model circuit for a crystal) can be ignored?

Sidebar: What do you do when you need a spec like the ones you provided, but no data sheet exists? I have had pretty good luck googling for part numbers like TS922, but I haven't been able to find out much about the crystals I have, which for the most part came from https://www.sparkfun.com/products/9994. (This website says that the ESR on the 32kHz crystal is 32k, but the other crystals in this kit mention nothing about it.)
mauifan
 
Posts: 161
Joined: Sun Aug 12, 2012 10:13 pm

Re: Crystal Oscillator Question (TS922 Op Amp)

by mauifan on Wed Oct 24, 2012 9:43 pm

john444 wrote:I hope you noticed that most of the example circuits use a single transistor or at most only a few. I do not remember any examples where a opamp is used to drive a crystal. In this type of application, there can be lots of variation - from mfg to mfg & model to model.

Actually, yes... I have noticed that I should be able to do what I am trying to do with a single transistor. When I got into studying crystals, I started with a single transistor. I got frustrated (mainly because I couldn't get it to work), so I thought I would try doing it with an op amp, which I think is conceptually a bit easier to understand. That, and the circuit schematic on NIU.EDU uses an op amp. :D
mauifan
 
Posts: 161
Joined: Sun Aug 12, 2012 10:13 pm

Re: Crystal Oscillator Question (TS922 Op Amp)

by adafruit_support_mike on Thu Oct 25, 2012 4:03 pm

mauifan wrote:I am not sure, but I think you just provided a small "aha" moment. :D

Congratulations.. figuring out crystals takes a few of those. Glad I could help.

mauifan wrote:If I understand you correctly:

ESR in a crystal decreases with increased frequency. Therefore, the resistor values external to the crystal must be adjusted (i.e. increased when going to a higher frequency) in order to maintain a gain=1.

Sort of.. there are two broad categories of crystal oscillators.. series resonant and parallel resonant.. and they have opposing requirements.

In a series resonant oscillator, the amplifier's output applies a voltage to one end of the crystal, and the amp's input measures the current that comes out the other end. You do that by putting the crystal into the middle a three-resistor voltage divider with R.source between the amp's output and one end of the crystal, and R.load between the other end of the crystal and GND. For that kind of circuit, you want the crystal's ESR to carry most of the voltage through the divider, so you want R.source and R.load to be small relative to the ESR.

In a parallel resonant onscillator, the crystal acts like a shunt to GND that steals energy from another resonant circuit.. usually a pair of capacitors or an LC tank. For that kind of circuit, you want a large resistance in parallel with the crystal so you can see the effects of its ESR shunting current to GND.

mauifan wrote:Still not sure about how to calculate the losses so I know how much gain to add from the op amp, but hey... if the above statement is true, I may be one step closer to understanding this subject.

What you tune depends on the kind of oscillator you're using. The Pierce oscillator (series resonant) is popular because it's one of the most stable and easiest to analyze.. it's basically the same as an RC phase shift oscillator with the crystal taking the place of a resistor.

mauifan wrote:That said, I am guessing that the loss I need to compensate for has everything to do with the crystal's ESR and that losses through the crystal's capacitors and inductor (reference the equivalent model circuit for a crystal) can be ignored?.

Pretty much. ESR is the dominant parameter.

mauifan wrote:Sidebar: What do you do when you need a spec like the ones you provided, but no data sheet exists?

All crystals with the same resonant frequency (and same cut.. 'AT' 99% of the time) have roughly the same ESR. The resistance needs to be in the right ballpark, but there's wiggle room once you get close. The rough values will get you a circuit good enough to see what adjustments are necessary.

The easy way is to drive the crystal at its resonant frequency and measure the ESR through it, but that assumes you have another oscillator that runs at the right frequency.
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 9147
Joined: Thu Feb 11, 2010 1:51 pm