Although generally not as stable as their harmonic relatives, relaxation oscillators are quite handy little circuits for low frequency generation, and can be found in everything from turn signal indicators to joule thief circuits.

Relaxation oscillators generate a changing voltage at a particular frequency by charging and discharging a capacitor through a resistor, and are often built around an operational amplifier:

Before designing an oscillator for ourselves, let’s take a look at how this circuit functions.

### Circuit Analysis

To analyze how this circuit oscillates, let’s start with just the op amp with no external components:

Remember that op amps have very high internal gain (in the thousands, or even millions), and that an op amp amplifies the difference between its two inputs. Without any negative feedback to limit the gain, even small changes to the op amp’s input will cause the op amp’s output to (ideally) drive “rail-to-rail”.

In other words, if the inverting input is even a little bit above the non-inverting input (the non-inverting input is tied to ground in the above circuit), the op amp’s output will be saturated at Vss; if the inverting input is even a little bit below ground, the op amp’s output will be saturated at Vcc:

Effectively, this is a crude inverting comparator.

Now, instead of supplying an external signal to the circuit, let’s add in the R1 and C1 components from the relaxation oscillator schematic (we won’t worry about specific component values at this point):

The start up state for the negative input pin is now dependent on the charge across C1. If C1’s charge happens to be a little bit negative, the op amp’s output will be at Vcc, and C1 will begin to charge via resistor R1; if C1’s charge happens to be a bit positive, the op amp’s output will be at Vss, and C1 will begin to discharge through resistor R1.

However, as soon as C1’s voltage hits 0V, the op amp’s output will drop to 0V as well, because both its inputs will be at equilibrium. Since ground, both inputs, and the op amp’s outputs are now all at 0V, the capacitor has no voltage difference across its terminals, and thus cannot charge or discharge; it just sits there at 0V, hence keeping the op amp’s output at 0V as well:

To force the circuit to oscillate, we need automatically changing thresholds on the positive input pin: one “high” threshold which is above 0V, and another “low” threshold below 0V. This is known as hysteresis, and is the function of resistors R2 and R3:

Instead of being tied to ground, the op amp’s positive input pin is connected to the junction of R2 and R3, which form a voltage divider between the op amp’s output and ground. In this case, since R2 and R3 are the same values, the voltage seen at the op amp’s positive input pin will mimick the voltage at the op amp’s output pin, only at half the voltage:

To get a better picture of how hysteresis and C1’s dis/charge time create an oscillation, let’s take a look at the positive and negative input pins of the op amp:

When the op amp’s output is at Vcc (high), the positive input pin is held at 1/2 Vcc by the R2/R3 resistor divider. At this point, C1 begins charging up through resistor R1 until it too crosses the 1/2 Vcc mark. The op amp sees that its inverting input is more positive than its non-inverting input, at which point it drives its output to Vss (low), since it’s an inverting amplifier.

Because the op amp’s positive input pin is controlled by the op amp’s output (specifically, it is set to 1/2 the voltage of the op amp’s output) the op amp’s positive input pin is now at 1/2 Vss, and C1 must discharge through resistor R1 until it crosses the 1/2 Vss mark, at which point the op amp’s output will flip back to Vcc, beginning the cycle all over again.

### Frequency Calculation

The RC time constant of C1 and R1 has an obvious contribution to the frequency of oscillation. Larger values of C1 and R1 will cause longer charge and discharge rates, thus producing lower frequency oscillations (smaller values will, of course, produce higher frequency oscillations).

But the hysteresis resistors R2 and R3 play a critical role here as well, because they control the voltage thresholds that the C1 needs to charge up to. If C1 only needs to charge and discharge to 1V and -1V respectively, it will obviously be able to do so faster than if it needed to charge and discharge to 10V and -10V.

To calculate the frequency of oscillation for any given combination of R1, R2, R3 and C1 (assuming Vcc and Vss are symmetric, e.g., +5V and -5V):

\(

\begin{aligned}

k = \frac{R2}{R2 + R3} \\

\end{aligned}

\)

\(

\begin{aligned}

f = \frac{1}{2 \times R1 \times C1 \times ln(\frac{1+k}{1-k})} \\

\end{aligned}

\)

If the hysteresis resistors R2 and R3 are equal to each other, these equations can be simplified to:

\(

\begin{aligned}

f = \frac{1}{2.2 \times R1 \times C1} \\

\end{aligned}

\)

So, we can predict the oscillation frequency for any given value of C1 and R1:

\(

\begin{aligned}

f = \frac{1}{2.2 \times 10,000 \times.0000001} = 454.5Hz \\

\end{aligned}

\)

### Oscillator Design

OK, let’s design a relaxation oscillator for an arbitrarily chosen frequency, say 17kHz. Using standard value components, a 5.6K resistor an 4.7nF capacitor should get us pretty close:

\(

\begin{aligned}

f = \frac{1}{2.2 \times 5,600 \times.0000000047} = 17.3kHz \\

\end{aligned}

\)

Let’s substitute those values into our oscillator and see what we get:

Whoa, wait a minute! The oscillator should be running at 17kHz, but instead we’re seeing less than 11kHz on the ‘scope; that’s almost a 40% error!

Unfortunately, our calculations assume ideal or near-ideal components, an assumption that doesn’t always hold true in the real world.

Let’s take a look at where we went wrong, and how to fix it.

### Op Amp Errors

Although an ideal op amp wouldn’t have any effect on C1’s dis/charge time, the slew rate and recovery time of a real world op amp can introduce significant errors:

It is clear that the capacitor voltage is both over and under shooting its mark.

During high to low transitions, C1 continues charging well beyond the high voltage threshold; the LM741 simply can’t bring itself out of saturation fast enough to keep up.

During low to high transitions, C1 continues discharging for a short period of time after the threshold voltage begins going positive again; due to the LM741’s low slew rate, it’s output just isn’t going positive fast enough.

Replacing the LM741 with a TL081 (the TL081’s slew rate is 26 times faster than the LM741) shows a significant improvement:

Clearly, circuit performance has improved, but there’s still a bit of overshoot on the capacitor’s charging voltage and the frequency is still a bit low; there’s room for improvement here.

### Comparators vs Op Amps

Unlike many op amps, comparators are designed to be driven rail-to-rail, and generally have much faster rise and fall times than op amps; this makes them better suited for oscillator circuits.

Let’s replace the TL081 op amp with an LM393 comparator:

Hmmm, that’s not the symmetric square wave we were expecting. What happened?

The problem is that resistor R1 and R4 (a required pull up resistor for the LM393 comparator) are both are connected to the comparator’s output pin, forming a voltage divider between Vcc and C1.

While we could decrease the value of the R4 pull up, making it too stiff would increase current consumption and make the comparator work harder to pull the output down during low transitions.

Instead let’s increase R1 to a value much larger than R4. Setting R1 to 56K (and scaling C1 appropriately to 470pF) solves the problem:

This is much improved, but we can do better.

### Capacitance Errors

All of the above circuits were built and tested on a solderless breadboard, which can introduce additional parasitic capacitance into the circuit. This effect tends to become worse with higher frequencies and lower values of C1, as parasitic capacitance becomes a larger portion of the total capacitance.

Deadbugging comparator oscillator on a scrap of PCB removes this parasitic error and puts us within 3% of our calculated 17.3kHz frequency:

While we’re at it, if your C1 looks like this:

Then do yourself a favor and replace it with a good NP0/C0G capacitor. Ceramics have terrible stability, especially over temperature; you can stick them in your circuit and watch the frequency drift down by several kHz in just seconds!

### Conclusion

When designing a relaxation oscillator like the above, just remember:

- Proper component selection and construction is critical
- All components have an effect on frequency, not just R1 and C1

Oh, and Widlarize those ceramic caps. *

* OK, maybe keep them around as bypass caps

Hi Craig,

I want to use a relaxation oscillator for a very specific purpose. I have a capacitor which is charged periodically and reaches 5V after every 5 seconds or so. I want the capacitor to discharge, as soon as it reaches 5V, into a load and stop discharging as soon as its voltage falls below 3V. Is this possible using a relaxation oscillator?

Can you provide a bit more details about your application? You say it takes 5 seconds to charge your capacitor from 0 to 5 volts; you then want to discharge it into a load until the capacitor voltage hits 3 volts, and repeat that cycle.

Do you want the capacitor to then be disconnected from the load, discharged back to 0v and charged back up to 5v again? Or do you want the capacitor to charge/discharge between 3v and 5v only? What is the overall purpose of this circuit? What kind of load are you discharging into? Why did you pick thresholds of 5v and 3v (why not 4v and 2v, for example)?

Hi Craig,

The capacitor is connected to the output of a voltage regulator IC. Now irrespective of the ICs input, just assume that the regulator gives a regulated output of 5V which charges the capacitor. The capacitor reaches 5 volts in 4 or 5 seconds. Connected to the capacitor is a load, say an RF transmitter. Now once the capacitor reaches 5 volts, I discharge it into the transmitter which transmits a code. Currently Im doing it with a push button switch. So I monitor the capacitor voltage and as soon as it reaches 5v I push the switch which powers the transmitter. I want the switch to be automatic and if possible, powered by the capacitor itself. So I want it to close every time the capacitor reaches 5V, power the transmitter and then open as soon as the capacitor discharges and keep repeating the cycle.

Lets just take voltage levels of 5V and 0V. At 5V (at the capacitor) the switch closes, discharging the capacitor into the load. At 0V, it opens disconnecting the load and allowing the capacitor to charge up again.

Powering your transmitter via the capacitor is probably not the best solution, unless you have a particular reason for doing so (?). What I would do is just connect the output of the relaxation oscillator to a switch/relay that turns the transmitter on/off (the relaxation oscillator’s output could power the transmitter directly, provided the op amp you’re using can provide enough current…but I don’t know what the power requirements of your transmitter are).

Actually my project is related to energy harvesting. So the capacitor is the energy storage medium for now. It accumulates energy every 5 seconds. Its value is 47 microfarads and it charges upto a max of around 6.5 volts. So you can imagine that even with this small energy, it is able to power the transmitter. I was wondering if I could use a relaxation oscillator stage between the capacitor and the transmitter So that the oscillator discharges the capacitor into the transmitter whenever it reaches 5V. Is that possible? I’m trying to make this arrangement self powered.

I’d try using a low-power comparator to turn on a MOSFET switch when the capacitor voltage hits your desired voltage level. With some hysteresis added, the comparator can be configured to switch off the MOSFET when the capacitor discharges to some other voltage level. In a sense, this would be the same as using a relaxation oscillator. Just be aware that any automated switching configuration will itself require draining some energy from your capacitor.

If C1 only needs to charge and discharge to 1V and -1V respectively, it will obviously be able to do so faster than if it needed to charge and discharge to 10V and -10V.

it is your statement but I think that charging and discharging time is independent of these voltages

I think perhaps you are thinking of an RC time constant? The RC time constant calculates how long it will take for a capacitor to charge through a resistance up to 63% of some applied voltage V. Since this calculation is in terms of a percentage, the time constant obviously is unaffected by what the applied voltage V is.

However, in the context of my particular statement, neither the capacitance (C1), the resistance (R1) nor the applied voltage (voltage output from the op amp) are changing in value. This means that the time it takes for the capacitor to charge up to some particular voltage level (say, 10V), will always be the same.

What *is* changing are the values of resistors R2 and R3. These resistors form a voltage divider which provide a reference voltage to the op amp’s non-inverting input, effectively instructing the op-amp at what voltage level it should charge/dis-charge capacitor C1. This has no effect on the time constant of the RC network comprised of R1 and C1.

Since the time constant of the RC circuit is the same, and the applied voltage is the same, then the absolute time capacitor C1 takes to charge to 1V must be faster than the time it takes for it to charge up to 10V.

pls what do I use as ground

how does using the LM393 comparator as an oscillator change your frequency equation? or does the equation from the op-amp oscilator stay the same? does R4 play a role in the charging of the capacitor?

The frequency equation remains the same, but you do have to account for R4 in the equation, as the capacitor will charge through the series resistance of R4 + R1. Additionally, because the LM393 is an open collector output, the capacitor only discharges through R1, causing a non-50% duty cycle, as shown in the ‘scope traces above. The solution is to either make R1 much larger than R4 such that the effects of R4 are negligible, or to use a comparator that doesn’t have an open collector output and thus doesn’t need the R4 pull-up resistor.