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?
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.
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.
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.