Why is this oscillator unstable?

I designed a simple triangle wave oscillator based around a switchable curent soure. It works for a few cycles, then it becomes unstable and finally stops working altogether. Why is this?

If anyone wants to simulate this - here is the link.

One other thing - occasionally, the osillator will manage 20 cycles, other times it won't complete a single one. Why is the simulation apparently not deterministic?

Alternatively, instead of the window comparator, simply use a comparator with positive feedback.

It has the advantage of being MUCH simpler, in terms of parts. Also, it should be VERY stable, thanks to the positive feedback on the comparator.

You can make it even simpler by just getting rid of the analog switch, as well as two of the op-amps.

Ok, I'm having fun now.

So, this circuit never makes a perfect triangle wave, because you're charging the capacitor with a voltage through a resistor.

To make it operate as a true triangle wave generator, we need to do a significant amount of refactoring.

Basically, we need to charge the capacitor with a current source.

This is simple enough to do, all you have to do is stick the cap in the op-amp feedback.

Look at This

(Note: this oscillators start-up is a little weird. It basically relies on leakage to charge the capacitor enough that the bottom op-amp output goes to one of the rails. This would not be a problem in the real world, since op-amps always have a little bit of offset, which would drive the output to one of the rails immediately on startup.

Basically, the simulated op-amps are too perfect.)

• the last one is no longer a triangle wave, because the "current source" has such a low output impedance. – markrages Mar 10 '11 at 7:07
• @markrages - True, but the original drawing isn't a perfect triangle wave generator either. Anyways, I added a true triangle wave generator. – Connor Wolf Mar 12 '11 at 5:51

What's happening is that the simulation is not deterministic! What an exciting property for a simulator to have! It appears that if it takes too long for an event to occur (computationally) it gets delayed a time-step. If you set the simulation speed too fast, you may get a different result!

At any rate, your flip-flop is getting clocked twice at one of the peaks, and that causes the output to rail or do other silly stuff.

You can improve this circuit by using a S-R latch instead of a flip-flop. That way, even if you have glitches out of your comparators, it's the first glitch that counts. Second, there are no possible invalid states. Notice in your image how if the Q_Bar output = 0 and the output wave is below -0.2V, your circuit is permanently stuck.

What you really want is something like a Set-Reset latch. That way you don't care about the comparators glitching, because your circuit will still function. Here's a link back to the Farstad simulator, as well as a screenshot.

• Alternatively, add a little bit of positive feedback to the comparators – Connor Wolf Mar 10 '11 at 6:29
• Agreed - some additional hysteresis in the comparators would improve the original circuit. I still maintain that the SR latch is a "stable" solution. – W5VO Mar 10 '11 at 6:33
• It would definitely be stable. However, it is not very efficient in terms of parts. – Connor Wolf Mar 10 '11 at 7:06
• Of course, you could always just use a 555... I was just answering towards the question. The window function is a bit pricey, although the current sink/source would be easy on an IC without opamps. – W5VO Mar 10 '11 at 7:50
• I've played with the code for the Falstad simulator quite a bit. Some components are designed to take a time step to react, while others are designed to be "instant", and cause the simulator to re-evaluate everything when they change. If this re-evaluation process repeats too many times, the dreaded "Convergence Failed" message pops up. One difficulty with this is that some components which normally take a step to pass inputs to outputs may change their output "mid-step" when the simulator is re-evaluating the effects of changing something. I've experimented some with... – supercat Feb 23 '14 at 20:29

Not giving a full answer, but I remember oscillator simulations as being notoriously difficult to do. If you don't set the step time correctly you won't see anything at all. I'm not sure I'd assume the simulation is correct.

• Usually the difficulty with oscillator simulations is getting them started. Typically simulations don't have any noise, so there's nothing that can be amplified and filtered. Also, startup may take hundreds to thousands of cycles to simulate. This is just an unstable oscillator. – W5VO Mar 10 '11 at 7:42

If you set the voltage slider lower, it seems to simulate fine.

• Yes; but have a look a the tips of the waveform; they show microinstability (is that a word?) Maybe the circuit just isn't correct... – Thomas O Mar 9 '11 at 20:32
• You're fretting over pretty minor things in a simulation. Is this circuit so complex and expensive you can't just build it and see if it works? – AngryEE Mar 9 '11 at 21:31
• @AngryEE, well, it's nice to have a pure wave. Look at the op-amp output during those periods, it's oscillating rapidly. – Thomas O Mar 10 '11 at 7:43