Here is a large 45 watt speaker. And well, the most obvious way to drive it would be with a class D amplifier. Class A and class B would both be too inefficient. And that’s what this video is about: class D amplifiers. And to give us a better understanding, we will make it completely discrete, in that we will only use the transistors themselves. So, let’s dive in!
Why Class D?
Let’s first begin with how exactly a class D amplifier works and why it’s so efficient. To do that, let’s briefly take a look at class A and class B amplifiers to see their shortcomings. Class A amplifiers have the best output quality, but that comes with the worst efficiency of the bunch. The poor efficiency comes from the singular transistor, which is always on and active, even if there is no input signal. Class B does a bit better in terms of efficiency by using two transistors to drive either side of the load. However, the output is still mostly linear, and the transistors will ‘burn off’ the excess power before it reaches the load. Class D is different in that it does not have a linear output. Instead, it uses a switching topology to achieve the end result. It’s efficient in the same way that a switching power supply is efficent. There is no power burn off, but rather, the output transistors are either fully on or fully off.
Block Diagram
Here is a top-down view on how a class D amplifier works. First, we have our input signal which we plan on amplifying. Then, we pass it into a PWM modulator of some sort. Usually, this is in the form of a comparator which compares the audio signal with a much faster triangle wave. The output of this will be a PWM signal. The amplitude of the original signal is preserved in the duty cycle of the PWM. The longer the signal is on, the larger the amplitude of the signal. Then we take this signal and pass it into our output stage. Normally, the output is driven by two MOSFETs, so you will need some sort of MOSFET driver. When the PWM signal is high, then the high-side MOSFET is on, and when the signal is low, the low-side MOSFET is on. This is where the efficency comes from, since there is very little power lost in the FETs due to them being either fully on or off. And finally, we take that amplified PWM signal from the MOSFETs and pass it into a low-pass filter to retrieve our amplified audio signal. Depending on the complexity of your design, you may or may not have negative feedback. But more on that later.
MOSFET DRIVER
Let’s start off with the MOSFET driver. In normal cases, you’d purchase a MOSFET driver IC to handle all of this for us, but we are taking on the challenge of making one ourselves. Basically, here is what needs to happen. We need to alternate which MOSFET is on based on the input PWM signal. A ‘1’ should turn on the top MOSFET and a ‘0’ should turn on the bottom MOSFET. It sounds simple at first, because it is. All we have to do is invert the logic signal to one of the MOSFETs. Let’s take a look at one such circuit that can do this for us.
Here is an AND circuit made using RTL logic. Why AND and not just a buffer or an inverter? Well, I’ll show you in a second. The best part about making this circuit discrete is that we are able to use a wider variety of input voltages as opposed to logic ICs. Anyways, you’ll see that this AND gate has two inputs followed by a common-emitter amplifier. This second transistor is needed since the first two invert the signal, so this just inverts it again to regain the intended signal. The final stage is this push-pull amplifier using a PNP and NPN transistor. This is used to quickly overcome the gate-source capacitance and switch the MOSFET much more quickly. If we had used the stage before, the resistor would have been a very slow driver. So, if we give a constant ‘1’ to one of the inputs and a PWM signal to the other, we can measure the switching speed of the gate.
Here is how the driver looks with a 10kHz square wave applied to it. It looks OK from here, but let’s zoom in. You will notice that there is quite the delay before the gate even starts changing. It’s even worse if we take a look at the falling edge. What causes these differences and why is it slow? Well it comes down to a few things. First, RTL uses resistors to drive everything. Depending on the resistor, this can slow things down. RTL also ends up putting the BJTs into deep saturation when turning on the transistors. This makes it much harder to turn off the transistor, which is why there is such a long delay on the falling edge.
We can fix some of these problems by switching to a different logic type: TTL. Here is what our new AND gate looks like. I already know what you are thinking. That input transistor looks mighty confusing, well let me explain. First off, when you see a transistor drawn like this, it actually represents two separate transistors with their bases and collectors tied together. Their emitters are separate, hence two emitters. Anyways, to fully understand how this logic works, let’s take a look at the diode model of the NPN transistors. When we have 1’s at the inputs, current flows from the base to collectors, since this is the only path to ground. This will drive the next transistor and we will end up with a ‘1’ on the output. Now, if even one of the inputs is a ‘0’, then current will be diverted to it. Since there is only one diode drop over here, it will take all of the current and nothing will flow into the following transistor. This will give us a ‘0’ on the output.
If you look online, you’ll find that most circuits have this totem-pole output. My circuit here uses a push-pull output. I used this instead because it will give us an easier time driving the MOSFET. Anyways, this new setup is much faster than the old RTL setup, so let’s measure it. As you can see, the rising edge is much faster than before. The output basically rises with the edge. The falling edge still has a delay, but it is greatly improved and much more brief. It looks alright for being placed in a 400kHz PWM cycle too.
Now let’s build up the other side so we can get a feel for the push-pull nature of the output MOSFETs. To invert the PWM signal for the second driver, we can add another two transistors in an inverting pattern. When we have a ‘1’ on the PWM signal, it will pull the transistor down, thus pulling the input of the AND gate down to a ‘0’. Anyways, it works as expected, and we get inverted square waves on each gate. However, you may notice that there is some crossover between the signals, periods of time where they are both active at the same time. Ideally, we should separate them out just enough so that they are never on at the same time. We call this period where they are both off, dead-time. That’s what the DT signal stands for on our AND gates.
Dead-Time
I’ve setup our circuit so far such that we can pulse a LOW signal on the dead-time input to disable the MOSFET output. So, all we have to do is generate this LOW pulse. We should generate this pulse on the rising and falling edges of the PWM signal. But how will we detect the edges? Well, let’s take a look at our friend the capacitor. By looking at its equation, we can see that it is differential by nature. We can use this to our advantage and create a differentiator. Imagine what would happen if we differentiated our PWM signal. Well on the flat edges, we’d get zero volts. And on the edges, we’d get steep voltage spikes. So how do we create such a differentiator? Well, we create a high-pass filter. Yes, a high-pass filter is the same thing as a differentiator. We can use this technique to detect our rising edges, since the output of the differentiator is a positive spike. Simply attach an NPN transistor to detect this spike and pull its output LOW.
But what about the falling edge? We get a massive negative spike, how do we deal with that? Well, you move the resistor up to VCC instead, and attach a PNP transistor. Now, when we get a negative spike, the PNP will sink current through the base and turn on the transistor. We will add another NPN transistor to invert this signal so we can pull the ouput LOW on the falling edge. If we combine the two outputs, we will get a comprehensive edge detector which will serve as our dead-time driver. Let’s take a look at our gate voltages now. And as you can see, they are sufficiently separated and neither overlaps the other.
PWM Modulator
Now that we have our MOSFET driver, we need a PWM signal to actually drive it. Like I said earlier, the PWM modulator is commonly created in the form of a comparator. To test that our circuit is working so far, I’ll temporarily use the LM311 as our comparator. It gives us this nice NPN output, which we can use to pull down any signal. I simply put this into a TTL inverter because I needed it to also drive the HIGH-side of its output. I used a totem-pole output this time instead because it can actually reach down to 0 volts, unlike the push-pull driver from before. Anyways, with this, it’s time for the first official test. On the inverting input of the comparator, I placed a 400kHz triangle wave. On the non-inverting input, I placed a much slower sine wave. This sine wave is in the audible range so that we can actually hear it.
And it works, although with some distortion. This is because we still have shoot through. The dead time is working correctly, but there are some timing differences between the HIGH and LOW side due to there being an imbalance in the number of transistors. So to fix things I added two more transistors and a capacitor to the PWM input on the HIGH side to balance things out. I then placed an LC low-pass filter an a speaker for testing. And wow, it sounds surprisingly good. The goal is to make a design using only transistors, so the LM311 has to go. In its place, I put a discrete comparator. If you’ve read the LM393 datasheet, you’ll recognize this right away, because it’s the same thing.
If you’re curious how this discrete version of the LM393 works, well note how it looks a lot like the DIY op-amp I made. This time though, it’s optimized for switching speed. You can see the differential pair, this time implemented with PNP transistors. At the top and bottom you’ll find the current mirrors as well. The main difference is the darlington input stage, which allows a faster response time in the circuit. And when we integrate it into our design, it sounds just as good as the LM311. So, I’d say that we didn’t lose any performance here by going discrete.
Triangle Generator
So far, for the comparator, we’ve been using a function generator to create a triangle wave. But, this won’t be allowed in the final design. So, we need to find a way to generate the triangle wave inside of the circuit. One such way of doing that is by integrating a square wave. Let’s start with the integrator. We have two options: an active integrator or a passive integrator. A passive integrator has the advantage of using a very small number of components, just two, a capacitor and a resistor. An active integrator, on the other hand, also involves an op-amp, but it also comes with the advantage of being more stable and being able to drive a small load. So, we have to weigh up whether building an entire op-amp is worth it here.
I started the experiment with the passive integrator. A 2k2 resistor and a 1nF capacitor. And after feeding in a 400kHz square wave, we do indeed see the approximate triangle wave on the output. However, the amplitude of it is rather small and will make it difficult to work with on its own, not to mention the effect that the comparator will have on it. So, we can add a common-emitter amplifier in order to amplify the amplitude of the signal, but also buffer it against the comparator’s input. And as it turned out, the buffer wasn’t enough, so I added a couple more output stages, and it stays somewhat stable when an audio signal is applied. But, it really isn’t good enough, so I decided that it was best to just go ahead and build an active integrator using a discrete op-amp.
Following our active integrator, we have an op-amp based schmitt trigger. This will give us a square wave which our integrator will turn into a triangle. The triangle then feeds back into the schmitt trigger which creates our square wave. And as we can see, we get our triangle wave on the output of the integrator which we can use. We aren’t done yet though. We should feed the triangle wave into an op-amp amplifier in order to act as both a buffer and to change the amplitude as needed before it enters the comparator.
Audio Input & Bootstrapping
We should make another amplifier to amplify the audio signal from our player. We can use this amplifier to adjust for volume and also to fill the audio signal within the triangle wave. Now, it’s time to test our prototype. And, at first, I tried using this little speaker, but it didn’t sound great. I then upgraded to this bigger speaker. And it was sort of working at this point, but there was still a few issues. The output was very quiet. And after some probing around, I found the issue. I’m sure several of you watching already noticed, but I didn’t put bootstrapping on the high-side MOSFET driver.
Now, N-Channel MOSFETs need a positive voltage between the gate and the source in order to turn on. The problem here is that the high-side MOSFET wasn’t referenced to ground, so we were having issues creating a large enough voltage difference on Vgs. This is the problem that bootstrapping addresses. Basically, we can charge up a capacitor to VCC when the drain is connected to ground through the low-side MOSFET. This capacitor will retain this voltage drop even after the low-side switch closes. Then when we want to turn on the high-side mosfet, we can use this capacitor as our voltage difference. This will mean that the gate will be the capacitor’s voltage higher than the source, which will completely turn on the MOSFET.
And this change worked very well. The next test was very impressive. I played a nice rock song, which I can’t play for you since it would infringe on copyright. But here is a royalty free song that you can listen to. I’m not sure how well it comes across in the video, but in real life, this thing got extremely loud. It’s honestly better than what I was expecting. The only issue really was the quality of the output, but that’s to be expected when making a breadboard circuit.
Attempt at a PCB
I figured the next step was to make a PCB version of the circuit on the breadboard. The only change that I made from the original was that I added a feedback system. This feedback circuit is not original though, I copied it from a paper by Charles Lehmann. I’ve linked it in the description below in case you’d like to read it. However, I wasn’t able to really test it properly as you’ll see in a moment.
The soldering took quite a long time, due to the sheer number of components. I had to probe each transistor individually to ensure that there weren’t any shorts. I do have to say though, that the final result does look very pleasing. Getting it to work, on the other hand, was the very opposite. The first thing was that the triangle generator wasn’t working. So I went through and found that two transistors weren’t properly matched. No big deal, I simply replaced them and it went back to normal. Then another transistor was drawing too much current, so I had to replaced that one.
I could keep going on, but basically, the list of issues seemed endless. It really didn’t help that the triangle generator kept breaking. I would fix it and go about testing another part, then the triangle generator would break itself again. I did manage to get everything working for a brief moment, but the result was less than impressive. I wish that I could have been more successful with this project, but it was taking up so much time and I wanted to focus on other videos. At least the breadboard version it gave good results. I’m also sure that you could greatly reduce the number of transistors used.
Either way, this was an interesting experiment, and it taught me a lot about class-D amplifiers. Feel free to leave improvements and suggestions in the comments. Thanks for watching, if you’ve enjoyed, please consider subscribing so that you can see my other videos. Also, visit my buymeacoffee page. With your support, you can help me afford to make more videos like this one. Thank you Cognisent and Mr. devNull for supporting the channel and making this video possible. Thanks for watching, have a good one!