I'm trying to generate a square wave at 21kHz (+13V,0V) using this schematic:


I used formulas and this website to find the correct values for my components but it doesn't seem to work on Simetrix.

Do you see any problem?

  • \$\begingroup\$ If you start with IC=0 all nodes being being 0V is a valid. Solution but not stable in the real world due to noise. Try setting a different IC, does this help? \$\endgroup\$ Aug 29, 2019 at 10:36
  • \$\begingroup\$ Simetrix examples include at least one square wave generator that works! \$\endgroup\$ Aug 29, 2019 at 12:58
  • \$\begingroup\$ This is just a canned comment to let you know that what you're trying to build from discrete analog components (possibly incorporating Opamps and/or NE555) is a digital control problem and thus can easily and with lower parts count be solved with a microcontroller with really minimal firmware to write. \$\endgroup\$ Aug 29, 2019 at 13:04
  • \$\begingroup\$ Hi Gragon. Another canned comment - ground symbols should never point anywhere but down. Rotate the op-amp, flip it, whatever it takes - convention is very important for readability. Here is a short reference on how to draw great schematics. \$\endgroup\$
    – rdtsc
    Aug 29, 2019 at 13:35

2 Answers 2


Your positive feedback attempts to move the non-inverting input above and below ground. This would work with a dual supply system - ie negative rail below ground.

In a single supply system you need to provide hysteresis above and below some intermediate voltage - this may be Vcc/2 or some other value to allow for eg the fact that input common mode range is typically ground to Vcc-1.5V.

As Jasen notes - the resistor values are on the small side.
The LM2904 will source and sink 10+ mA but it is best to limit I/O current to usefully less than I_out_max.

In this case try eg at the non-inverting input

  • Remove R2

  • Add 15k to V+

  • Add 10k to ground.

  • Change R1 to 10K.

  • Increase R3 and decrease C1 - or reduce the hysteresis range (smaller R1) to increase frequency.

That should provide an OK starting point for playing.

LM2904 data sheet

  • \$\begingroup\$ also use higher resistors, the LM2904 can only do a few milliamps, \$\endgroup\$ Aug 29, 2019 at 11:27
  • \$\begingroup\$ @Jasen Yes. Probably around 10 mA but quite a lot less is desirable. I've added related comment in my answer. \$\endgroup\$
    – Russell McMahon
    Aug 29, 2019 at 12:04
  • \$\begingroup\$ @Peter Karisen - your answer was OK, but (as you know) only covered part of the options. Leaving it there would have done no harm. \$\endgroup\$
    – Russell McMahon
    Aug 29, 2019 at 12:05
  • \$\begingroup\$ @RussellMcMahon Thank you for you answer. At first it wasn't working but then i reduced R1 to reduce the hysteresis range and it worked! But i only have spikes and not a square wave, where does that could come from ? \$\endgroup\$
    – Gragon
    Aug 29, 2019 at 12:17
  • 1
    \$\begingroup\$ @Gragon You have not advised what R & C values you have used or what the frequency of operation is. We are unable to start to guess what you are doing or seeing - and updated circuit and functional description would give us some chance of being helpful. The cap max V value MUST remain below (Vcc-1.5V) and preferably lower yet. That's why I made the suggested bias resistors assymetrical. Increasing R1 will reduce the hysteresis voltage swing - which increases frequency but may be a good idea. || What component values are you now using? | What is the frequency of operation? \$\endgroup\$
    – Russell McMahon
    Aug 29, 2019 at 20:46

Let's first look at the output divider pair, \$R_1\$ and \$R_2\$, you provided. This takes the opamp output and divides it in half. (We are assuming you aren't over-loading the output's current compliance for the moment.) If you assume the opamp is a perfect rail-to-rail output then the output may either be \$V_\text{CC}\$ or else \$0\:\text{V}\$. So that means that \$0\:\text{V} \le V_{\text{IN}_+}\le \frac{V_\text{CC}}{2}\$. But clearly, given \$R_3\$ and \$C_1\$, it follows that under all circumstances \$0\:\text{V} \le V_{\text{IN}_-}\le V_\text{CC}\$.

Note the fact that both ranges have \$0\:\text{V}\$, inclusive? Not so good.

What you want is that the range for \$V_{\text{IN}_-}\$ to completely envelope, clearly and unambiguously, the range for \$V_{\text{IN}_+}\$. Let's leave the basic concept presented by \$R_3\$ and \$C_1\$, so that we continue to allow \$0\:\text{V} \le V_{\text{IN}_-}\le V_\text{CC}\$. But we must now restrict the range of \$V_{\text{IN}_+}\$.

It's really convenient to set a range such that \$\frac{1}{3}V_\text{CC} \le V_{\text{IN}_+}\le \frac{2}{3}V_\text{CC}\$. Then you may keep your resistor values all the same; for both \$R_1\$ and \$R_2\$, as well as a new one I'm adding to your circuit. (But I'd recommend increasing their values, somewhat -- perhaps to \$10\:\text{k}\Omega\$ to lighten the load on the opamp's output.) And then simply add one resistor from \$V_{\text{IN}_+}\$ to \$V_\text{CC}\$, using the exact same value for it that you use for \$R_1\$ and \$R_2\$.

If you sit down with the simple RC exponential decay equation and work out the timing required to go from \$\frac{1}{3}V_\text{CC}\$ to \$\frac{2}{3}V_\text{CC}\$ you will have half of the total cycle time. And you can use that equation to solve for a value for \$R_3\$ given some value for \$C_1\$, pretty easily. In that way, you can achieve your \$21\:\text{kHz}\$ value.

You should be able to write that equation very quickly in this fashion:

$$\frac13 V_\text{CC}+\left(V_\text{CC}-\frac13 V_\text{CC}\right)\cdot e^{^-\frac{t}{R_3\:C_1}}=\frac23 V_\text{CC}$$

That reads as, "The capacitor voltage starting at \$t=0\$ is one-third of \$V_\text{CC}\$. To that, we add the charging rate which is driven by the difference between \$V_\text{CC}\$ and the starting point voltage, that difference then times the exponential decay rate over time. We want this result to reach two-thirds of \$V_\text{CC}\$." Or something like that, anyway.

You can work out that half the time is \$t=\frac1{2\:f}\$ where \$f=21\:\text{kHz}\$. Just drop in your value for \$C_1\$ and you should be able to compute a value for \$R_3\$.

It's really no more complex than that.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.