The new Raspberry Pi B Model B+ is here - Pick one up in the store and check our detailed guide!

Re: Crystal Oscillator Question (TS922 Op Amp)

by john444 on Fri Nov 23, 2012 2:15 am

Maui fan,

I got no joy connecting your circuit with +6v on pin 4 & 0v on pin 11.
I see 60-Hz spikes but no oscillation.
As we discussed, without a bias circuit to shift the operating point,
this thing will not oscillate properly.

However, when powered with +3v on pin 4 and -3v on pin 11 & ground at 0v.
I get a distorted sine-wave*. It is strongly clipping on the + cycle.
LM324 osc powered from +&- 3v split-supply.jpg
LM324 osc powered from +&- 3v split-supply.jpg (29.36 KiB) Viewed 1381 times


* The wave is probably distorted due to my mistake. I hooked power up backward.
I know better because I have made this same mistake before.
A moment of distraction and the chip gets hot.
Good thing the cells I powered it from are weak or the smoke would have escaped.
The green PCB is an old thermostat. The only thing I could find
tonight with a crystal.

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 Fri Nov 23, 2012 2:51 pm

Not trying to ignore anyone, but I just received some guidance from Adafruit. In short, files need to be under 1MB... and mine were a bit over that limit.

With any luck, here are two photos of my breadboard setup. The "overview" version is a wide angle shot of the pertinent areas of my breadboard, and rotated 90 degrees so it would all fit. The "closeup" version zooms in on the breadboard itself and shows some of the wiring, though I imagine it is not the best.

Note: This version connects to +6V with ground at 0. My next step will be to modify it with "ground" at +3V per john444 suggestion.

breadboard-overview.jpg
Breadboard Overview
breadboard-overview.jpg (889.17 KiB) Viewed 1363 times

breadboard-closeup.jpg
Breadboard Closeup
breadboard-closeup.jpg (780.78 KiB) Viewed 1363 times


Notes:
1) Generally speaking, all of my wiring is on the left side of the board (under the "1"). The crystal itself is the cylinder to the right of the op amps. The other components (e.g. inductor, 4MHz crystal) in that vicinity are in "storage."
2) The large op amp is the LM324N. The small one is the TS922.
mauifan
 
Posts: 161
Joined: Sun Aug 12, 2012 10:13 pm

Re: Crystal Oscillator Question (TS922 Op Amp)

by mauifan on Fri Nov 23, 2012 11:49 pm

WOO HOO!!! I am finally gettin' some love from the LM324N!

Attaching a picture of my scope's output, along with a grand overview of the wiring. John444 -- you were right! Assigning the +3V power rail as "ground" gave me a very consistent output. The only "complaint" I have is that the frequencies varied between 19-23kHz or so (as opposed the the crystal's rated 32kHz) when I varied the pots. I am somewhat sure that the crystal was oscillating, because it stopped when I pulled it out of the circuit and started when I reinstalled it.

LM324N-Love.jpg
The LM324N seems to work!
LM324N-Love.jpg (73.05 KiB) Viewed 1356 times


I guess I will need to try this on the TS922 as well as see if I can tune this to the desired 32kHz and maybe connect "ground" to a voltage divider, but for now I think I will just savor the moment. :lol:
mauifan
 
Posts: 161
Joined: Sun Aug 12, 2012 10:13 pm

Re: Crystal Oscillator Question (TS922 Op Amp)

by john444 on Sat Nov 24, 2012 1:54 am

Congratulations!
Doesn't it feel great when a circuit finally works the way you intended.

That sine-wave looks much better than the one from my overheated '324.
Now, adding the capacitors across the crystal should bring it into a more stable mode.
The final tweaks will be to set the drive and gain resistors.
But, now that it oscillates, they will be easy to implement.

Good job,
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 Sat Nov 24, 2012 11:50 am

john444 wrote:Congratulations!
Doesn't it feel great when a circuit finally works the way you intended.

Indeed it does!!! I think I am going to take a break from this and go do something else for a day or two. :lol:

john444 wrote:Now, adding the capacitors across the crystal should bring it into a more stable mode.
The final tweaks will be to set the drive and gain resistors.
But, now that it oscillates, they will be easy to implement.

Good job,
John

???

I am a little confused by your word "stable." The output I saw was incredibly stable in the sense that I always saw something. Varying the gain and the pot connected to the crystal varied the frequency, but it didn't seem like I had to walk on egg shells when adjusting the pots. Are you saying that "stable" means getting 32kHz all the time?

Also... I probably should go back and read your explanations again, but thinking out loud... well... I would think that it might not always be practical to have the "stiff" 3V power rail. Shouldn't I be able to achieve the same results with a voltage divider using the midpoint as virtual ground?
mauifan
 
Posts: 161
Joined: Sun Aug 12, 2012 10:13 pm

Re: Crystal Oscillator Question (TS922 Op Amp)

by john444 on Sat Nov 24, 2012 12:52 pm

Maui fan,

mauifan wrote:Varying the gain and the pot connected to the crystal varied the frequency,

Exactly. The caps reduce the dependence on the op-amp gain, supply voltage,
and temperature & signal level stability are improved.
For really low distortion and signal level stability, we are back to talking about 'light-bulbs'. :)
Keep in mind, time keeping circuits need stability in parts per million.
It may reliably oscillate yet not keep good time or have excessive distortion (for some applications) without the additional parts.

mauifan wrote:Shouldn't I be able to achieve the same results with a voltage divider using the midpoint as virtual ground?

Yes. I can see that it is making sense to you now.

Enjoy the holiday.
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 Nov 26, 2012 3:36 pm

Ok... did a quick test and tried added a few caps across the 32kHz crystal. Physically, I used two 22pF caps in different configurations. In once case, they were in series effectively adding an 11pF cap across the crystal. In the other two cases, I used one and then two of the 22pF caps for a total of 22pF and 44pF, respectively. In all cases, the extra caps raised the operating frequency, but also seriously distorted the output waveform. The "best" I could get out of it was a distorted sine wave similar to john444's picture. Sometimes the wave looked more like a sawtooth, and the worse case... well... I don't know what that was, but I suspect I might have seen the beginnings of a second harmonic or something.

Still need to try out my oscillator circuit using the TS922, but I think that LM324N demonstrates some understanding of how these circuits should work, but I am still not entirely confident about how they do work. It will be interesting to see how my circuit performs using the TS922....
mauifan
 
Posts: 161
Joined: Sun Aug 12, 2012 10:13 pm

Re: Crystal Oscillator Question (TS922 Op Amp)

by mauifan on Mon Nov 26, 2012 4:01 pm

Ok... just tested my circuit using john444's suggestion of using the +3V rail as "ground" with the TS922, and I ended up with very different results. First off, the oscillations were MUCH faster -- perhaps twice as fast, if not more. Second, I am not sure that the oscillation was due to the crystal. I pulled it out of the circuit, and I still saw oscillations. Adding caps across the crystal affected the output, but as will the LM324N, I don't think they were all that significant. The pots controlling the gain and the op amp(+) varied the output frequency greatly.

What the heck???

Also... my confidence is shaken, but... well... is this normal? Y'all have stated a couple of times that this is a bit like walking on a tightrope, but... well... I would like to be able to design circuits someday without having to ask for help all the time, and today doesn't seem to be that day. :?
mauifan
 
Posts: 161
Joined: Sun Aug 12, 2012 10:13 pm

Re: Crystal Oscillator Question (TS922 Op Amp)

by john444 on Mon Nov 26, 2012 6:49 pm

Maui Fan,

I will explain again that the breadboard is not a stable place to do this experiment.
However, I see that it is what you want to use.
First, put some 0.1-uF disk and 10-uF tantalum (or electrolytic) caps, as close to the op-amp as possible.
Connect one pair from +V to ground, the other pair from -V to ground.
This will probably eliminate the phantom oscillation.
Next,
I would suggest that you start out with 22-pF caps located close to each side of the crystal. One side of each cap is connected to ground, the other to the crystal.
The cap's values are not terribly critical. They can probably vary by +/- 50% and make little difference.
surface-mount caps will work best but disks are ok.

To control the drive to the crystal, start adding series resistance between the op-amp output and the crystal. You may see lots of strange shapes or distortions on the scope as the resistance increases. Increase the resistance until the sine-wave fades away. Then slowly reduce the resistance until oscillation starts again. You may find that by tapping the crystal you can start oscillation that would not start on it's own.
This is where you want to operate this oscillator.
All that remains is to find a negative-resistance device to provide high gain with little or no oscillation and lower the gain with large oscillation.

Good Luck.
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 Nov 26, 2012 9:23 pm

John444-
I understand that a breadboard adds a certain amount of capacitance and "error" into a circuit, but the ONLY changes I made were to move the wires connecting to the pins on the LM324N to the corresponding pins on the TS922. Perhaps there are some miniscule differences between breadboard rows B-E and rows M-P, but otherwise, everything is IDENTICAL. Same wires. Same crystal. Same pots. The only significant difference between the two is the op amps.

The purpose of my little experiments today were... well... if the LM324N and the TS922 were truly ideal op amps, I should be able to use them interchangeably, and the TS922 should in theory give me the same waveform. However, the fact that I saw a very different waveform tells me that there is something different about the TS922. Yes, we have been down this road earlier in this thread and the explanation makes perfect sense. Call it my years of computer training or whatever, I had to do this because that's just the way I think.

"It worked with the LM324 and not the TS922. Therefore, there must be something different about the TS922."

My last post was a lament about how you experts are able to see the internals of each chip and know how to adjust. Why are you saying that I need to add the 0.1uF and 10uF capacitors in the first place? Why connect the 22pF caps on each side of the crystal? Won't these result in a roughly 180 degree phase shift of the signal? This would be just what the doctor ordered for a negative feedback circuit, but my circuits of the last few days use positive feedback.

I have seen the recommendation to use 0.1uF and 10uF caps in conjunction with powering an Arduino. Are you saying that the op amp needs these as well? If so, I didn't think that the caps were all that critical when running off batteries. (It would make perfect sense to me if I were using a wall wart to smooth out ripples.)
mauifan
 
Posts: 161
Joined: Sun Aug 12, 2012 10:13 pm

Re: Crystal Oscillator Question (TS922 Op Amp)

by john444 on Tue Nov 27, 2012 12:11 am

Maui Fan,

mauifan wrote:Perhaps there are some miniscule differences between breadboard rows B-E and rows M-P, but otherwise, everything is IDENTICAL. Same wires. Same crystal. Same pots. The only significant difference between the two is the op amps.
If only it were so. :?
After a little use the internal spring-clips become weak & corroded,
the clips develop significant resistance and become intermittent.
The jumper wires are long and inject significant inductance.
Select the right wire and simply moving it around can change the frequency.

mauifan wrote:if the LM324N and the TS922 were truly ideal op amps

I had hoped we already established that 'ideal op-amps' are imaginary. :?
'Real' components are useful approximations of the ideal.
'Ideal' op-amps would break some of the laws of physics.

mauifan wrote:My last post was a lament about how you experts are able to see the internals of each chip and know how to adjust.
Don't kid yourself. There are no shortcuts putting in the time, pouring over datasheets and making every mistake possible to wire up circuits. It is only the mistakes you make and correct that improve your education. When you finality get it to work, is when you have learned what you can from it.

mauifan wrote:Why are you saying that I need to add the 0.1uF and 10uF capacitors in the first place?
I have played with op-amps before. Some op-amps are better behaved than others. However, self-oscillation is very common. Especially for high-gain, high-speed op-amps like the '922. (And it is in the datasheet.)
mauifan wrote:Why connect the 22pF caps on each side of the crystal? Won't these result in a roughly 180 degree phase shift of the signal?
No. 22-pF is small in comparison to the crystal's equivalent capacitance so the phase-shift due to them is small (insignificant). However, they do establish a stable amount of capacitance to ground, so that say - 'waiving your hand over the circuit' no longer has an impact on it. I am sure there are engineering-design justifiable reasons but most of my education has been by experience.
mauifan wrote:I have seen the recommendation to use 0.1uF and 10uF caps in conjunction with powering an Arduino. Are you saying that the op amp needs these as well? If so, I didn't think that the caps were all that critical when running off batteries.
They have nothing to do with filtering ripple. When you use long, skinny wires to power a high-gain, high-frequency amp then, the inductance and resistance of those wires cause a voltage drop at the chip when it quickly switches the output, drawing a pulse of current. That voltage drop in the supply gets amplified and your amp is now an oscillator. The 0.1-uF especially, provides a low resistance source of current, long enough to power the amp when it draws that current pulse. That is also why they are needed at the chip, not at the battery. They will do no good at the battery. In high-speed circuits, lead-length is kept as short as possible. These are referred to as 'bypass caps'.

I am not especially smart but, I have enjoyed analog electronics as a hobby and profession for a long time.
During those years, I gained some experience. And, I have shared some of that experience with you so that you might not quit because it was difficult. (You did however, pick a project with a steep learning curve.) But, you have lots of resources including the internet.

I am learning about Arduio's. For example, here is about what I know about programming - Pearl is what comes from an oyster, C is the third letter in the alphabet.

This stuff is fun. Especially when you quit beating your head with it. It feels so good when it works.

Sorry, for going on & on. I only intended to answer your questions but I got a little philosophical.
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 adafruit_support_mike on Tue Nov 27, 2012 10:50 pm

mauifan wrote:My last post was a lament about how you experts are able to see the internals of each chip and know how to adjust.

*laugh* It's more like, "on the internet, nobody can smell the board you just fried." ;-)

Congrats on getting oscillation BTW.. I've been up to my elbows in other things for the past week, but it's good to see that you got some success.

Believe it or not, it gets easier from here. The long slog of 'it just doesn't work' involves learning lots of little things unconsciously, all of which contribute to success. Seeing something work convinces you it can happen, getting it to work as the result of conscious effort convinces you that *you* can make it happen. From there, the good habits just sort of refine themselves automatically.

I can't count the number of times new circuits sat there doing nothing even though I thought I'd followed the design correctly. Eventually I get them to work, and if I keep working with them, it gets to a point where I can hardly throw a handful of components at the workbench without getting them to land in a working circuit. I don't have the faintest idea why it happens, but I know it does, and that keeps me plugging away when the next one refuses to work.

I have to second the advice about breadboards though.. try clipping your probes to parts that obviously shouldn't have any signal, like Vcc and GND. Clip both probes to things that should carry the same signal, like opposite ends of the Vcc and GND rails, or the same rail on both sides of the board.

I've seen half a volt disappear from one end of a jumper to another. Theoretically, that shouldn't happen. In practice it does.. constantly.

john444 wrote:No. 22-pF is small in comparison to the crystal's equivalent capacitance so the phase-shift due to them is small (insignificant). However, they do establish a stable amount of capacitance to ground, so that say - 'waiving your hand over the circuit' no longer has an impact on it. I am sure there are engineering-design justifiable reasons but most of my education has been by experience.

The official term is 'inserting a dominant pole/zero', and it's pretty much the central black art of working with op amps at high gain/frequency. The basic idea is that the caps have a predictable effect that's large enough to swamp out the random stuff.

Your experience-trained gut can probably do in two seconds what I'd spend fifteen minutes doing with diagrams and equations. ;-)
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: 8580
Joined: Thu Feb 11, 2010 1:51 pm

Re: Crystal Oscillator Question (TS922 Op Amp)

by adafruit_support_mike on Wed Nov 28, 2012 12:19 am

Also wanted to comment on this:

mauifan wrote:Also... my confidence is shaken, but... well... is this normal?

Yes.

You are absolutely dead center on the trajectory for someone wrapping their mind around a complex problem.

Well.. normal for the 5% of people who don't give up once they come face to face with the confusion and frustration inherent in the process.

mauifan wrote:Y'all have stated a couple of times that this is a bit like walking on a tightrope, but... well... I would like to be able to design circuits someday without having to ask for help all the time, and today doesn't seem to be that day. :?

Nobody ever stops asking for help.. except maybe to start praying for it.

Hard problems are hard because there are lots of moving pieces, lots of subtle interactions, and only a handful of patterns that seem to make sense at the start. Learning to solve such problems is a process of building a mental model of what's going on, seeing it break, then building a tougher one.

The b*banned of it is that half of the time, you can't even understand the tougher model without seeing the simpler one fail. The simpler one gives you the vocabulary you need to ask the questions the tougher one can answer.

You've chosen one heck of a challenge for your first dive into the "seriously.. WTF?" end of the pool, but you're doing well.

Asking for help is smart. It's also good exercise. It's smart because people who've traced a path farther into the confusion can steer you away from some of the dead ends, and can describe landmarks that will start to look familiar when you find the path that works for you. It's good exercise because there's no more important skill than being able to ask -- with precision -- "I'm doing this, I expect this, I'm getting this.. what's going on?" The first three parts give you the foothold you need to understand the answer to the fourth.

By the time you get done chewing on this problem, you'll be able to take a junior-level Signals and Systems class and think "hey, that looks familiar" for half of the more complicated ideas. Learning the structure those tools provide will let you look back at the op amp/crystal sine wave oscillator and say, "oh!.. now I see what that piece was doing!"
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: 8580
Joined: Thu Feb 11, 2010 1:51 pm

Re: Crystal Oscillator Question (TS922 Op Amp)

by mauifan on Mon Dec 03, 2012 7:40 pm

Wow. I can't believe that it has been a whole week since I last posted anything about this topic! It was a busy week that left little time for playing with this stuff.

Still not sure when I will have time to revisit this, but I stumbled on this link:

http://www.youtube.com/watch?feature=pl ... f6bStGjSAg

This isn't about crystal oscillators, but it does talk about op amps in a somewhat intuitive way. In particular, Pete mentions that the input impedance of real op amps is on the order of 100-1000K. That suggests to me that if the impedance feeding into the inputs was on the order of 10k or less, the op amp would behave more or less like the ideal op amp.

True statement?

Personally, I have been thinking about the crystal oscillator circuit as the following block diagram:
oscillator-block-diagram.png
Oscillator Block Diagram (From Wikipedia)
oscillator-block-diagram.png (6.08 KiB) Viewed 1178 times

with the op amp being the amplifier and the crystal being the filter (feedback network). So if the input impedance of the amplifier is about 100K, it would make sense to keep the impedance of the filter/feedback network on the order of 10k or less, no? For my 32kHz crystal, the impedance of the filter/feedback network would be roughly on the order of 30k, whereas a 4MHz crystal would be roughly on the order of 100 ohms or so?
mauifan
 
Posts: 161
Joined: Sun Aug 12, 2012 10:13 pm

Re: Crystal Oscillator Question (TS922 Op Amp)

by adafruit_support_mike on Tue Dec 04, 2012 7:03 pm

mauifan wrote:This isn't about crystal oscillators, but it does talk about op amps in a somewhat intuitive way. In particular, Pete mentions that the input impedance of real op amps is on the order of 100-1000K.

Hmm.. that seems a bit low. I generally figure op amp impedance based on the input bias current.

For bipolar op amps (like the LM358), bias currents are usually 50-100nA (10-20M). For JFET amps like the TL081, the typical bias current is 30pA (30 gigohms).

mauifan wrote:That suggests to me that if the impedance feeding into the inputs was on the order of 10k or less, the op amp would behave more or less like the ideal op amp.

True statement?

Not exactly.. the 100k-1M value is what you'd see if you put a resistor in series with the input terminal. That doesn't account for feedback though, and you always use op amps with feedback.

The official formula for input impedance through an amplifier is Rin * (1 + AB) where 'A' is the open loop gain, 'B' is the amount of feedback, and 'AB' is the closed loop gain. The basic idea is that your feedback network supplies some of the current that goes through Rin. The higher your loop gain gets, the more current your feedback network supplies.

Rin -- the 100k-1M value mentioned above -- does appear in that formula. It just gets multiplied as your gain increases.

In addition, input currents don't actually change the linearity or gain of your amplifier. They show up as voltage offsets at the output.

Let's take a simple voltage buffer as a first example, and assume we know the impedance of the negative input is 100k. To compensate for that, we use a 100k resistor for negative feedback. With no other inputs, the circuit will balance when the current through the feedback resistor equals the current that flows into IN-. Let's call that 1uA (which is high compared to the values in most datasheets). Under those conditions, the voltage across the feedback resistor will be 100mV.

That's an output offset error. For an ideal op amp Vout would be exactly the same as Vin-.

Now let's turn that into an inverting amplifier by connecting another 100k resistor to IN-. If we set the signal voltage exactly the same as Vin-, no current will flow through the input resistor and the circuit will be identical to the buffer above. If we raise the signal voltage 100mV above Vin-, all the bias current comes from the input resistor and none can flow through the feedback resistor. That sets Vout = Vin-, 100mV below where it was before. Rasing the signal 100mV lowered the output 100mV, exactly what you'd expect from a 'gain of -1' amplifier.

As far as the signal source is concered, it sees 100k of impedance from the input resistor. It also sees a parallel combination of Rin and the feedback resistor, but the voltage at the far end of the feedback resistor changes. The output offset error supplies all the input bias current, and the only other path for current to leave IN- is through the feedback resistor. That means the signal sees a total impedance of 200k.

If we take the input and feedback resistors up to 1M, the 'gain of -1' behavior stays exactly the same but the output offset error rises to 1v. The error still supplies all the bias current, so the 'only way out is through the feedback resistor' rule still applies, and the input impedance is 2M.

If we drop the resistors to 10k, the output offset error drops to 10mV, but the input impedance drops to 20k.

Sometimes it's okay to accept a higher offset error in order to get higher input impedance, and sometimes it's okay to accept lower gain in exchange for less error.

mauifan wrote:So if the input impedance of the amplifier is about 100K, it would make sense to keep the impedance of the filter/feedback network on the order of 10k or less, no?

Not necessarily.. that value certainly isn't more important than your loop gain or the intrisic values of your crystal.

Like I said, the non-ideal properties of an op amp show up as output offset errors, and those have the very nice property of being more or less independent of the input signal or gain. There are three major ways to deal with them:

1) "Just ignore it" -- a very popular option if you only want to see how the input signal changes.

2) "Tweak the reference voltage" -- if you have 100mV of output offset error, change IN+ by 100mV so your reference voltage error cancels your output voltage error.

3) "Use a capacitor" -- caps make DC errors go away, as long as you can afford to live with the phase/frequency issues that caps impose.

For an oscillator, you get #3 for free thanks to the resonant elements in the feedback path, but you can also use #2 to center the output if the offset causes clipping.
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: 8580
Joined: Thu Feb 11, 2010 1:51 pm