Op-amp PWM tutorial

I simulated an OpAmp based oscillator in everycircuit.com and then build it on a breadboard to test it.

The first op amp circuit will be a square wave generator.  A side-effect of this circuit is a triangle wave signal on the negative input.

The second opamp will combine this triangel wave signal with a voltage from a potentiometer into a PWM signal.

Simulation

The output voltage of the op amp is cut in half and fed to the positive input pin. This gives the resistor-capacitor pair at the other input a reasonable target to chase.

The resistor-capacitor pair at the negative input is always charging or discharging and the voltage on the capacitor always increasing or decreasing creates a triangle wave.

All components in the simulator start at zero volts and in this circuit it causes a perfect balance that does not exist in real life.

To get the circuit out of balance so it starts oscillating I added a voltage small source to one of the inputs of the op amp.

This extra resistor returns in the actual build of the circuit for a different reason and with a good explanation.

A virtual probe is added to the negative input of the op amp, I expect to see
the triangel wave here. In the simulator the op amp has a voltage supply of +15V and -15V, causing the output to flip between those two voltages.

The positive input pin receives halve of that being either +7.5V or -7.5V.

As soon as the capacitor reaches either of these voltages the output flips.
This causes the voltage to bounche between these levels.

The second op amp will take the triangel wave signal and compare it to a voltage given by a potentiometer.

Because both of the op amps not only get a positive but also a negative voltage supply, I also need the potentiometer to put out positive and negative voltages.

This is why I use two power supplies with a ground in the middle.

Actual build

Lets start with the basics, attaching the power rails, placing the op amp etc.

There are three resistors connected to the positive input pin. Two are connected to the power supply to offset the voltage halfway.

The other is connected to the output pin off the op amp. This signal is partially pulled towards the voltage the other two resistors create. It is now  resistor-divider with three legs. This is the only way to make this op amp oscillate without a negative power supply.

The resistor-capacitor pair is connected to the negative input of the op amp. First half of the circuit is done.

Lets hook up an oscilloscope and check if we see a triangel wave signal.

Looks OK to me!

Now the second part of the circuit. I feed the triangle wave signal into the positive input of the second op amp.

The other input of the second op amp gets the voltage signal from the potentiometer.

Once again I hook up the oscilloscope, this time we check for a PWM signal while playing with the potentiometer.

I works!

Video