PWM Tool
This is a dual-signal-PWM-generator. The second signal is inverted and never overlaps with the first one.
Oscillator circuit
Op-Amp
The entire circuit it made out of 3 stages, the first one is the "Oscillator", it will create the base frequency for the PWM signals.
At the heart of this oscillator is an op-amp which we will use in a very simplistic way.
I will first explain and build the individual parts, and when that is done explain how they work together with the op-amp.
We will build the circuit on a so-called bread-board.
On the back we can see how the pins are connected to each other.
The long rows for power, and the short ones for connecting components.
This is a power supply for breadboards, it takes 12 volts from a barrel jack or 5 volts from a USB-C charger.
It provides power and ground to the long rails on the board, 5 volts on left and 3.3 volts on the right.
We need 5 volts for this circuit, so lets test if the rails are powered.
Regular multi-meter probes don't fit in the breadboard holes.
Those probes use banana-plugs, so I take some banana-plug-to-crocodile-clip cables and put them into the multi-meter.
Those clips then grab jumper-wires which DO fit in the board. That's a free tip from me :)
Other free tip... put the multi-meter in DC voltage mode, not AC ;)
5 volts, perfect!
Now we install the IC which contains the op-amp, there are actually 2 of them inside!
Lets look at the print on the IC to see the model and make!
Yup, can't see shit with this thing!
Well, got a schematic on paper, very useful when connecting it to the rest of the circuit!
That notch on the top is also on the actual IC, so you know which way is up.
So the IC has a VCC pin at the top right. Lets get 5 volts from the left power rail to that pin.
If we cut the wire 3 points further than the hole it should go into, then it will be just long enough after stripping the coating.
Now for the ground pin, that's on the bottom left.
I know this looks like overdoing it, but I really want to be sure power actually goes to the IC.
Resistor divider
The next part of the circuit is a resistor divider, I love those things, really.
They are two equal resistors in series, between 5 volts and ground.
That results in the voltage in between them is 2.5 volts.
The resistors are of really high value, so little current goes through them.
And that means that the midpoint voltage can be easily influenced, which is exactly what we will do.
The op-amp can output a signal either 5 volts or ground.
This voltage is send to the same midpoint voltage, but through a resistor smaller in value, so it has a big influence on the final midpoint voltage.
That will be either close to 5 volts, or close to ground, but not all the way, and that last bit is important.
First we do the two 1 mega-ohm resistors.
I also like to test every component before placing them on the board, to make sure they work, and that the value is correct.
These component-testers are really inexpensive from china.
I have the circuit schematic and the IC schematic next to me.
And we just saw how the breadboard is wired underneath.
That and taking your time makes it not that difficult to get the components where they should go.
More testing! I want to see the midpoint voltage at 2.5 volts.
Great, that works!
Now for the final resistor that connects the 2.5 volts to the first op-amps output.
Resistor-capacitor pair
Quick note, that final voltage is also fed into the positive input of the op-amp, just as the final voltage of this next small circuit will be fed to the negative input of the op-amp.
The op-amps output will also be fed through another resistor.
And as the output is either 5 volts or ground, it will either charge or discharge this capacitor here.
The voltage that the capacitor is at will be shared with the negative input of the op-amp.
More testing, this time the capacitor, and I will now stop showing you that, as I suspect you get the point.
Now placing the resistor. But I also need a connection to the negative input.
So I decide to remove the resistor, do that wire first and then reinsert the resistor.
Time to hook up my oscilloscope and see the signal.
First the signal at the capacitor charging and discharging.
It should look more like sort of a triangle, but this is also good I guess.
And now the "modified" op-amps output, that midpoint voltage with 3 resistors I mean.
Yikes, that should look more like a square-wave signal. Guess we will have to fix that!
But first, lets look at how this circuit actually works.
Explaining the first circuit
The output of the op-amp goes high when the positive input voltage is greater then the negative input. And goes low when positive input is lower than the negative one.
Lets start with a high output and see what that does to the circuit.
The resistor divider voltage, that goes to the positive input, is close to 5 volts, but not all the way.
It also is charging the capacitor like this. And that will actually reach the 5 volts, and overtakes that other voltage.
Now the negative input voltage is actually greater than the positive one. And so, the op-amp switches it's output to ground.
The resistor-divider-circuit now goes the other way, voltage close to ground, but again, not all the way, so the discharging capacitor can again overtake that and the op-amp output will switch high again.
And so, that high-low sequence continues, making it an oscillator, very cool huh?
Fixing the signal
I suspect the 1 kilo-ohm resistor connected to the capacitor taxing the op-amp to much with to much current draw, deforming the square wave signal.
Lets change that to a 10 kilo-ohm resistor.
That looks more square to me!
Also the charging curve looks more like a triangle.
Big improvement.
Now we have a nice triangle signal, we can use that in the next circuit.
Variable duty cycle with potentiometer
The main component for the second circuit is also an op-amp.
This time we will be using a potentiometer.
It will let us choose any voltage between the voltage attached to it and ground.
Internally it is a variable resistor-divider, with a total resistance of 10 kilo-ohms.
That, together with the op-amp, will allow us to change the duty-cycle of the PWM signal.
We connect that output voltage to the positive input of the op-amp.
To the negative input, we connect the triangle signal that the previous circuit created.
And then..... done! The op-amp now outputs a variable PWM signal.
First, the potentiometer, it has three wires and I do not know which one is what.
I try to find the two wires that have a fixed resistance no matter the position of the knob.
These will be the VCC and ground wires, the order does not matter.
The third one then will be the one outputting the variable voltage.
So I give it 5 volts and ground and then measure the output voltage of the third wire.
Did you spot the problem?
I forgot to power the circuit!
That's better! We have a variable voltage.
That output voltage now goes to the positive input of the second op-amp in the IC.
It is on the right side, remember that schematic of the IC?
Now we need to transport the output signal of the first circuit on the left, to the negative input of the second op-amp.
At this point, again, I am just following the schematics and remembering the connector strips at the back of the breadboard. So there is no thinking involved here.
Time to hook up the oscilloscope again a have a look at the new output signal.
That looks great! When turning the knob of the potentiometer, we can see the duty-cycle change.
And at both 0 percent and 100 percent duty-cycle the signal flat-lines, either to 5 volts or ground.
Explaining
Now how does al that work? Or better, why?
Well, first we have the triangle signal.
And then there is that variable voltage from the potentiometer.
As long as the positive input of the op-amp, the 3 volts, is greater than the voltage of the triangle-signal, the output of the op-amp is high, like this.
But then they cross, and the op-amp's output goes low, like this.
Until they cross again!
Now what if the 3 volts signal from the potentiometer was lower, like 2 volts?
In that case the first crossover would happen sooner, and the second later, making the output signal low, for longer!
Signal inverter
This is the third and final circuit, the signal inverter!
And also non-overlapping like I said in the intro.
I'm starting to see a pattern here! More op-amps!
And another resistor-divider! This one is fancy, 3 resistors in series even.
The mid-points are connected to each there own op-amp, but not the same-input, very important.
This has to do with a sequence of events that have to happen.
The other inputs of the op-amps are connected to the same now-variable PWM signal.
And the final PWM output signals.
To understand why this works we need to know 2 things.
First: The input signal is a square wave, but zoom in close enough and the signal does not go from 5 volts to 0 volts or back in an instant, it takes some time.
Second: When the inputs of an op-amp flip, meaning, the other one is now bigger than the other, the output of the op-amp also flips from high to low or back.
So, the PWM signal dropping from 5 volts to 0 volts, first passes the 3.3 volts on the first op-amp, and then the 1.6 volts on the second.
And because the second one has the inputs switched, first signal 1 goes down and only after that signal 2 goes up, no overlap! Same goes the other way around.
Pretty clever right?
Here is the second IC with the other 2 op-amps we need.
Add some power.
And the 3 resistors.
Then feed the output of the previous circuit to the 2 inputs of both op-amps.
Lets get this oscilloscope to work and look at both outputs together.
And that's it, circuit's done!
Video version
Alternative local hosted video