# How can I size the components of a square wave generator in order to obtain a 7kHz frequency?

I used this circuit to generate a triangle wave that comes from the - input of the square wave generator. This is part of a circuit that generates a PWM signal. I need to have a frequency of 7kHz and to size the resistors and capacitors in order to get that. Can anyone help we with a formula for the frequency for this circuit? • Have you come across the subject of RC time-constant in your studies yet? Can you identify which components would determine the frequency of your circuit? – Transistor May 11 at 21:43
• I don't know exactly,I think R4 and C1,am I right? I tried to use the formula T=2R4C1ln(1+a/1-a) where a is R2/R2+R3 but it doesn't quite work – Teodora Bianca May 11 at 21:47
• Start with $\tau = RC$ and see how you get on. Please edit your question to show your calculated values and your measured values. – Transistor May 11 at 21:51
• Well,I chose the values for R2=R3=10k and C1=1uF and then I applied the formula from above to calculate R4 for T=1/f ,but when I run the simulation,it was not correct,so I think that the formula is not correct – Teodora Bianca May 11 at 21:56
• I obtained the value for R4=65 ohms,but my frequency is not 7kHz how I need – Teodora Bianca May 11 at 21:57

What you're making here is called a relaxation oscillator.

Here's a reference for that: http://www.analogzoo.com/2015/01/relaxation-oscillator-design/

The summary for a basic calculation:

• Charge / discharge time is the time constant which is 1.1*RC.
• Period is twice that, or 2.2*RC.
• For frequency we get 1/(2.2*RC)

Some items to check and/or fix in your design:

• 1uf and 68 ohm is kind of a low impedance for an op-amp to drive at that frequency. Scale these to less-demanding, smaller-current values (more below.)
• R1 and V1 are not needed if your intention is a square wave that swings from +VPS to -VPS. You need to refer the Schmitt feedback only to 0V.
• If you want to affect duty cycle, refer R2 to a voltage instead of GND. Note however this will also affect frequency.
• The LM358 is kind of slow, which will affect the charge/discharge time (it will be longer.) A faster op-amp will give closer to predicted results.
• You can compensate for the slower op-amp by reducing the value of R4.

With this in mind, we can select 0.01uF and about 6.5K to get 7Khz with an 'ideal' op-amp. Try it here.

• Thank you very much,now I try to simulate the circuit with this values and see what I get,should I change the LM358 opamp with another type of opamp? – Teodora Bianca May 12 at 11:14
• I simulated with this values and I measured the period and it is more than it should like 233u and I need it to be 142,8u,do you know why is that? – Teodora Bianca May 12 at 11:54
• It’s because of the op-amp. I tried it with the 741 (similar to 358) and got about 4Khz. The slew rate of these devices is slow and so affects the charge / discharge time. Even with a faster op-amp it will be a little off, you will still need to adjust R4 to compensate. – hacktastical May 12 at 16:29
• I changed the op amo with a TL084 and now it works just fine.Thank you so much everybody for your help! I really appreciate it – Teodora Bianca May 12 at 17:55

Here is a simulation that shows how ill-suited the LM358 is for this application. I've used +/-15V supplies which makes the slow slew rate even more of an issue. Note also the asymmetry in the output swing from +13.5 to -15V, a consequence of the output stage of the LM358. The slow slew rate means that the output frequency is heavily dependent on the power supply voltage as well as the slew rate (which is poorly specified and probably fairly temperature-dependent).

To compare, with an ideal op-amp or comparator the timing is independent of the supply voltage, provided it's relatively stable over the period of a cycle.

• Thank you for your help,so what should I do?Should I change the opamp? – Teodora Bianca May 12 at 11:15

first you need to size/compute the hysteresis input band.

If the band is exactly 1 tau, that may simplify your computation. Note the output drive strength of an opamp will vary with the load current, and both resistors to Vout count as loads.

Then you can think about how to size the R+C tau on the -Vin.

• I don't really know how to compute the hysteresis input band,what exactly should I do? – Teodora Bianca May 11 at 22:26