RC oscillator - Page 1
Forum section: electronics / beginners

author: sy
author_rank: Regular Contributor
timestamp: June 12, 2024, 12:42:32 pm
content: Hello,I am having a play around with opamps and trying to create an RC oscillator using a single supply rail (0-5V).The goal is to get oscillations happening at about 400kHz centered around 2.5V.I am just trying to get oscillations happening at the moment, without worrying about the particular frequency it's at, however, the output of U2 seems to just sit at a constant value of 2.5V.Can someone help me point out what I am doing wrong here?

author: CaptDon
author_rank: Super Contributor
timestamp: June 12, 2024, 01:30:31 pm
content: A couple of observations, R3, 4,and 5 are too low in value and kill the loop. Raise them to about 10k. Eliminate R6 and R7 and connect the inverting input directly to the last R/C stage. 400KHz in this style of oscillator will drift in frequency all over the place with temperature and VCC voltage drift. I didn't look up the specs on your opamp but you will need a minimum GBP of 4MHz or better to sustain oscillation at 400KHz. You would be far better off with a single I.C. designed for the job of oscillator and perhaps going to a single L/C resonant circuit. You can then drive a good buffer opamp and create the offset in the final buffer. Even the cross-coupled digital I.C. oscillators based on 7404 and such work poorly at this frequency range. There are some I.C. oscillators that use only one capacitor and one resistor but again, they tend to drift like crazy.

author: RoGeorge
author_rank: Super Contributor
timestamp: June 12, 2024, 02:15:20 pm
content: The second opamp has to have enough amplification (about x30) to compensate for the attenuation introduced by the 3 RC cells. Yours has amplification x1. Make R7 33k or smaller, and it might start. Make it 22k to start faster.C1 is not needed in simulation, but in practice might be useful. In practice, you may also want to add a 100nF+10uF in parallel with the 5V power supply, too.

author: sy
author_rank: Regular Contributor
timestamp: June 12, 2024, 03:06:14 pm
content: Quote from: RoGeorge on June 12, 2024, 02:15:20 pmThanks RoGeorge, I totally forgot about correcting for the gain. Good news I can see the circuit oscillating now!May I also ask how you got 20-30x attenuation on the three RC cells?When I tried to solve for the attenuation, for one cell, I had |A|=RwC/sqrt((RwC)^2 + 1) with w=1/[RCsqrt(6)], R=10k, C=100nF.Then for three cells, |A|^3 is about 0.054. So I would need a gain of 1/0.054=18.5 times. Is this the right way to go about it?Quote from: CaptDon on June 12, 2024, 01:30:31 pmThanks for the suggestions CaptDon. I tried as your suggestion and it worked well too although I don't quite understand why it works.How does this circuit achieve oscillation without the 1Meg resistors?I tried to place them there for a unity inverting gain so there would be zero phase shiftAlso, how do we determine that the resistor values are too low, and hence, kill the "loop"?

author: MrAl
author_rank: Super Contributor
timestamp: June 12, 2024, 05:13:57 pm
content: Quote from: sy on June 12, 2024, 03:06:14 pmHi,One way is to analyze the three RC sections to obtain the transfer function T(s) then set s=j*w and you'll have T(jw), then set the imaginary part of T(jw) equal to zero and solve for w which we can call w0, then insert w0 into T(jw) for w to find the attenuation G which is the amplitude with an input of 1 volt. The required gain of the circuit is then 1/G. This comes out to -29 so apparently you did not do the analysis correctly, try it again.You then solve T(jw) for the phase angle ph using w0 again. Verify that the phase angle is 180 degrees which helps to ensure you got the right w0.The analysis is a little simpler even though it's a three stage network. That's because all the R's are the same and all the C's are the same.The above is the theoretically exact analysis.You could also do a numerical analysis by first finding the transfer function T(jw), then solve for the phase angle ph(jw), then plot the amplitude of that versus 'w', notice what value of 'w' causes a 180 degree phase shift and that's your w0. You can then insert that w0 back into T(jw) and solve for the amplitude, then take the inverse of that and that's the required gain of the original circuit.You can set R=1 and C=1 when you do the numerical analysis, then scale them later.See attachment. Note that if you have any other resistance associated with R5 you have to figure that as being in parallel to R5. Your first circuit had two 1M resistors in series and connected to a zero impedance source, so that would mean R5 would have a 2M resistor in parallel with it (2M comes from R6+R7).You can also do this with a program if you write your own programs in Basic, Pascal, C, C++, etc.

author: RoGeorge
author_rank: Super Contributor
timestamp: June 12, 2024, 07:48:31 pm
content: Quote from: sy on June 12, 2024, 03:06:14 pmI didn't say 20-30 attenuation, I said about 30x (it's slightly less, about 29, but 30 or bigger gain will work, with gain 20 it will not oscillate). I've remembered the value 30 by heart, from last time when I've read about phase-shift oscillators. The analytic expression might be more complicated, because the cells do influence each other.However, what is easy to remember it's the value ~30, and that 30 is independent of the R,C, or F values. Though, the number of RC cells does matter. For example, >30 gain is needed for 3 identical RC phase-shit cells, while for 4 cells the needed gain has to be >19.Just as MrAI said before, you can let LTspice compute the exact numerical values.The attached example measures the attenuation introduced by 3 or by 4 identical RC cells (either 3, or 4, or more RC cells will oscillate when the phase shift becomes -180 and the opamp's gain is bigger than the attenuation introduced by the cascaded RC cells). Press CTRL+L to bring the LOG, or click in the plot area, then from menu View -> SPICE Error Log, to see the measurements:g3: mag(V(in))/mag(V(out3))=(29.2765,0°) at 654.566 Hzg4: mag(V(in))/mag(V(out4))=(18.5201,0°) at 1340.66 Hz

author: Zero999
author_rank: Super Contributor
timestamp: June 12, 2024, 08:56:35 pm
content: The OP07 is completely unsuited to this. It has far too lower GBWP and slew rate for 400kHz and isn't designed to work off a 5V supply.Use a faster op-amp, which is also suitable for 5V operation such as the TL972.

author: BrianHG
author_rank: Super Contributor
timestamp: June 13, 2024, 09:16:23 am
content: I would have done this with a 74HC14. If I needed a near sine wave output, I would have RC filtered the 74HC14's output.

author: MrAl
author_rank: Super Contributor
timestamp: June 13, 2024, 12:33:31 pm
content: Hello again,Because all the C's are the same and all the R's are the same the transfer function comes out rather simple:Vout/Vin=(s^3*C^3*R^3)/(s^3*C^3*R^3+6*s^2*C^2*R^2+5*s*C*R+1)and with s=j*w the right side becomes:-(j*w^3*C^3*R^3)/(-j*w^3*C^3*R^3-6*w^2*C^2*R^2+5*j*w*C*R+1)Solving this for the oscillation frequency 'w' the result is:w=1/(sqrt(6)*R*C)then substituting that into the transfer function we always get:-1/29which is the attenuation factor.I should have mentioned though that if a square wave is acceptable there are simpler oscillators that are very stable.

author: Zero999
author_rank: Super Contributor
timestamp: June 13, 2024, 09:26:12 pm
content: Go for a Wien bridge oscillator, which only requires a gain of 3.https://en.wikipedia.org/wiki/Wien_bridge_oscillator?useskin=vectorI tried building it one a breadboard, but used the TL072. It did oscillate, but I consider it to be a failure because the frequency was well-out, at 220kHz. I chose lo resistor values, to reduce the effect of the parasitic capacitance of the breadboard. I tried increasing the supply voltage from 5V to 12V, but it made no difference. The TL071 obviously isn't fast enough.I used the standard Wien bridge circuit, with the classic lightbulb gain control. The only difference was I designed it for a single supply.f = 1/(2πRC)R1 and R2, form a potential divider with an output impedance equivalent to their values in parallel, to the non-inverting input, so a resistance of 820/2 = 410R.R3 = 390R.For simplicity, consider R to be 400R, which should be near enough.C = 1nF.f = 1/(2π*400*10-9) = 400kHz.Note: the C1 and C3 are connected to +V, to avoid the risk of the TL071 going into phase inversion (when the functions of the +- inputs exchange, due to the common mode range limits being exceeded). If you're using a different op-amp say one which works with its inputs down to the negative supply, you'll be better off connecting them to 0V. It makes no difference, once the circuit is running, as both rails can be considered to be ground, at AC, since the power supply should have a low impedance C4 AC couples them together, for good measure.It's also a little distorted, which is evident from the fact that the peaks are asymmetrical, even though the oscilloscope is set to AC coupled.It might be better if built on a PCB, with a decent layout, but I think a faster op-amp is required.

author: MrAl
author_rank: Super Contributor
timestamp: June 14, 2024, 08:30:55 am
content: Quote from: Zero999 on June 13, 2024, 09:26:12 pmHello again,Yes at 400kHz you need a fairly fast op amp. For low distortion you need one with a slew rate of about 2.5v/us per peak volt.So if you only need 1v peak output then you need an op amp that can do 2.5v/us, and if you need 2v peak output then you need an op amp that can do 5v/us, if you need a 5 volt peak output then you need one that can do 12.5v/us or better.Probably go a little higher like 2.6v/us per peak output volt.Usually when you choose it this way it will have a high bandwidth to go along with the fast slew rate, but you could check that too.

author: Zero999
author_rank: Super Contributor
timestamp: June 14, 2024, 12:21:24 pm
content: Quote from: MrAl on June 14, 2024, 08:30:55 amI think it's running out of gain, rather than the slew rate.The TL071 has a slew rate of 13V/μs, yet my circuit only has an output voltage of 600mV peak (1.2V peak-to-peak), which was deliberately chosen, because the supply voltage is only 5V, which I know is marginal.Using the TL072 (I normally use single op-amps for breadboarding, unless I need more than one) with both amplifiers, set to √3, in series might work, but suspect the group delay is also responsible for the distortion, as well as the lower than the expected frequency output, so it maybe not.I don't have a faster op-amp in a through hole package to test at the moment (I'm not messing around with an adaptor board), but I expect it will work properly with a TL972.

author: Picuino
author_rank: Super Contributor
timestamp: June 14, 2024, 02:23:16 pm
content: At that relatively high frequency wouldn't it be simpler to make a transistor LC oscillator?https://en.wikipedia.org/wiki/Colpitts_oscillator

author: Picuino
author_rank: Super Contributor
timestamp: June 14, 2024, 02:47:09 pm
content: https://falstad.com/circuit/circuitjs.html?ctz=CQAgjOCmC0CcIBYB0AmArCsAGAHCrBWAbCgOzxpYhrVVoxhgBQANiAMxYIjRhEdcQOKiKSEwNaFjG40pUjgRpKRBGXYocILEwDGHIluEGtYBNyopUhG7YLsY8ZO1h40sMDndeX2mcwAXEHR+ME0BbjCtKghoNCQSNEV0eRx2eSUeMFQyJPYXTwx2ZXZgghAAE0gAMwBDAFcWAL0TcCIqdkNglAtg6zsBhzhwVBxhNDB03JRXaP8mAHdwWBRwcJC16MXl1ZQeiO6Lbc5uY06jESYAJx2s0JXN7XAba4O97hO2kW6CJgAlW68ULmO5PKgIOhgvxoJgAcze+0+PW+OgA8q1jOYLmCmAAPDg4UjgTqILBEyZONogADCzHx7DGwU8pK0ewgkX41JQx0EZ0EjFWOiWnzMH357W0PO471aMqFrVFCol8pFEvOX0lSzADyBB11Ohu2tWUVucuehDxHDARLQ-Hy3HciCpABk6VbTHgOAzwF4nXwQH83fgOfwZXxKf6-tz8fhSghWShShM-fw-uxLZNSnwaBIs10OTT0-oBY8S2bsgNK2AYETpMQuERyMJYAQiBpfXWsMwtQ8TSWTfKjYdwGFhzoAPYjjiCxDYUKiGywUhEW3oJ7MIA

author: mawyatt
author_rank: Super Contributor
timestamp: June 14, 2024, 02:52:58 pm
content: Quote from: Picuino on June 14, 2024, 02:23:16 pmOr the very simple Peltz Oscillator.https://www.eevblog.com/forum/projects/simple-sinusoidal-oscillators/msg4281568/#msg4281568https://www.eevblog.com/forum/projects/injection-locked-peltz-oscillator-with-bode-analysis/msg4424434/#msg4424434https://www.eevblog.com/forum/projects/things-coming-together-bode-plot-diy-isolation-transformer-peltz-oscillator/msg4288363/#msg4288363Best,

author: Zero999
author_rank: Super Contributor
timestamp: June 14, 2024, 09:25:54 pm
content: Well the thread title says RC oscillator. Discrete is a possibility, but there are op-amps which will work at this frequency.Here's photograph of the breadboard layout.I raided the miscellaneous op-amp bin at work and borrowed an AD817, which I plugged into the circuit and it works. This time the frequency is a bit higher than expected, which I put down to the capacitors and resistors being on the low end of their specifications.

author: MrAl
author_rank: Super Contributor
timestamp: June 15, 2024, 02:15:52 am
content: Quote from: Zero999 on June 14, 2024, 12:21:24 pm13v/us sounds good for now. You could check at what frequency the circuit starts to act up by starting at a lower frequency, even as low as 40kHz. As you go up, you can find the point where it stops working the way you expect it too then figure out why.Sometimes a 5v power supply is not enough, you can check that also.

author: RoGeorge
author_rank: Super Contributor
timestamp: June 15, 2024, 06:44:37 am
content: A phase-shift osc should work just fine even with the most simple voltage amplifier, a CE BJT (common emitter bipolar junction transistor), but I didn't try:Image fromhttps://en.wikipedia.org/wiki/Phase-shift_oscillatorAny other voltage amplifier should work too, a FET, an opamp, etc. as long as it has enough amplification and the phase shift doesn't have any "humps" (or in other words, the Barkhausen oscillation condition has to be met at a single frequency only, or else it will oscillate at more than one frequency at the same time, and the output waveform will be a combination of all the oscillations, so not sinusoidal any more).

author: Zero999
author_rank: Super Contributor
timestamp: June 15, 2024, 11:57:37 am
content: Quote from: MrAl on June 15, 2024, 02:15:52 amChanging the supply voltage to 12V made no difference.I also tried the TL081, which should be the same as the TL071 in terms of AC characteristics, and there was no oscillation whatsoever.I didn't try different frequencies to see what point it stopped working, became distorted, or fell below the theoretical frequency, but I recently built a 50kHz Wien bridge oscillator with the TL071, which worked perfectly.https://www.eevblog.com/forum/projects/want-to-hear-the-bat-flying-in-my-front-yard/msg5518471/#msg5518471I suspect it'll stop working somewhere around 100kHz.I tried simulating it in LTSpice. I had difficulty finding a model for an incandescent lamp. The one I found on the LTSpice Google Group needed to be tweaked before it worked. I changed the time constant TAU from 22m to 10u. With ideal components, it should oscillate around 390kHz. The output voltage is still much higher, than the practical circuit, because the model doesn't match the real incandescent lamp.https://groups.google.com/g/sci.electronics.cad/c/I9QfewHAaSIWein Bridge osc lamp 400k.asc(2.35 kB - downloaded 25 times.)Quote from: RoGeorge on June 15, 2024, 06:44:37 am400kHz would be a struggle for a single transistor phase shift oscillator. The Miller effect means the impedance of the RC network needs to be very low. I think more than one transistor is required to build a reliable phase shift oscillator at this frequency.

author: mawyatt
author_rank: Super Contributor
timestamp: June 15, 2024, 04:40:14 pm
content: If one doesn't explicitly require an RC oscillator the Peltz we mentioned above is quite good for a simple oscillator and produces a very good sine-wave output. We just grabbed a couple 2N3904s, a 10uH, a parallel cap and 1K emitter bias resistor, that's it!!This will run down to ~1V DC supply, and as shown with 2V supply, the frequency is quite stable with supply voltage. The cap was tweaked (another parallel cap) to get close to 400KHz.Best,

author: Zero999
author_rank: Super Contributor
timestamp: June 16, 2024, 12:56:54 pm
content: At these frequencies, an LC oscillator starts to become more practical. Much less gain is required, compared to a very lossy RC filter.Here's a simulation of a discrete Wien bridge circuit. I didn't put any limiting in because the non-linear and slew rate limits the output, without a large amount of distortion.I don't have my breadboard to hand at the moment, but it appears as though the original poster has lost interest anyway, so won't build it, unless someone indicates interest.Wein Bridge discrete 400k.asc(2.35 kB - downloaded 20 times.)It might work without Q1, but I didn't try. I copied the amplifier circuit from another design.EDIT:Here's the two transistor version.Wein Bridge discrete 400k.asc(2.03 kB - downloaded 27 times.)

author: MrAl
author_rank: Super Contributor
timestamp: June 17, 2024, 10:00:27 am
content: Quote from: Zero999 on June 15, 2024, 11:57:37 amHi,I meant for you to check the type of IC chip being used because some op amps do not function well at 5v. Some need at least 10v or something because the inputs do not function right unless they are at least 4v above ground and possibly 4v below +Vcc. With a 10v supply that means you only get 2v to operate within. Some of them were made to work with a very old standard of using plus and minus 15 volt supplies.Just something to check for whatever IC chip you are using.Another thing to keep in mind is if you do increase the supply voltage you probably want to make sure the output of any op amp does not increase too. If the AC output increases also, that means the slew rate has to be higher to work at the same frequency as with the lower supply voltage. That's only if the AC part of the response of the output increases though.

author: Zero999
author_rank: Super Contributor
timestamp: June 17, 2024, 10:22:27 pm
content: Quote from: MrAl on June 17, 2024, 10:00:27 amYes, the TL071 isn't specified for a 5V supply, but it is with a 12V supply. The fact that absolutely nothing changed when increasing the voltage to 12V and I have built a different circuit with the same IC, which did work off 5V, indicates it wasn't that which was causing the problem.QuoteAre you saying the slew rate of some op-amps varies with the supply voltage? The data sheet for the TL071 doesn't imply that, but if it's run at a lower voltage than it's specified to, it wouldn't surprise me, if it might be a little slower.

author: MrAl
author_rank: Super Contributor
timestamp: June 18, 2024, 10:00:58 am
content: Quote from: Zero999 on June 17, 2024, 10:22:27 pmHi,The slew rate can change a little but that's not what I was drawing attention to.For most purposes we can think of the slew rate as being a constant regardless of the power supply voltage like 5v vs 12v.What does change though is the maximum frequency, *IF* the output of the op amp goes higher than it did at 5v. This could be the case if the circuit uses the power supply as a reference of some kind. If the output was going from say -1v to +1v at 5v, then at 12v it was going from -2v to +2v, that's a two-fold change in peak amplitude. If the slew rate was 1v/s when at 5v it would take 0.25 seconds to reach the peak after starting at 0v. At +12v (in this example) it would take 0.5 seconds to reach the peak after starting at 0v. That's twice as long, which means half the frequency. If the output could be reduced to -1v to +1v (peaks) then it would behave the same as before the increase.What this means is if the output does not change in amplitude, then we will not see any difference. It's only if the output increases (or decreases) that we will see any difference in the maximum frequency.