Discrete Class D Audio Amplifier Part 2

This is my second attempt at a discrete class D amplifier. And I’m glad to say that it works this time around. Not only did I greatly decrease the complexity of the design, but I’ve also made it much more stable. I’d say that its actually somewhat usable. Let me show you how I put it all together.

This video is a follow up to the first part. I recommend you watch it first to fully understand this video.

The Comparator

Like I said in the intro, I greatly reduced the number of transistors needed for the circuit. When starting on this second version, I started with the comparator. Last time I missed the greatest advantage of a discrete design, which was that I could form the comparator as needed. If you recall from the original, I made a copy of the LM393. But, like I said, a custom design would work much better in this case. If you’ve watched my op-amp video, then you’ll know that the differential pair naturally has a differential output. In most cases, we simply take only one side to get a single ended output. But if we take both, we can get a naturally opposite output.

This removes any logic inversion that was previously needed, which helps to simplify things. Another improvement I made to the differential pair was emitter degeneration. This should help to stabilze things a bit in the comparator. Beyond that, the most confusing part left in this design that I have not covered in any previous videos is how I handled the high-side current mirror. In a normal single-ended comparator, you’d simply tie one transistor to one side and leave the other. But that won’t work in this case since we still need to get a voltage on both sides of the output.

Instead I made double current mirror. Now, something like this may not work the best on a differential op-amp, but we are working with a comparator. This is suitable to generate either a one or a zero on the output. And as an awesome bonus, the value of this resistor, along with the amount of current in the differential output’s tail, together set a sort of dead-time between the outputs. Adjusting the resistor will allow you to fine tune the dead-time to a certain extent.

The dead-time works by having the current setting transistor determine the base voltage for both of the other transistors in the current mirror. When the comparator decides that it is time for that particular output to be off. The input transistor will starve the other transistor of current. This places the transistor into saturation as it tries to maintain the current mirror’s current. When the input finally gets back around to feeding current, the transistor will still be in saturation. It will take some time to get out of saturation, which creates a delay. This delay is enough to form the basis of our dead-time.

All that’s left is to place an output transistor. Since we used an npn for our differential pair, we need to use a pnp for the outputs. Unfortunately, this is actually kind of inconvenient when we need to implement bootstrapping later on. So I decided to avoid this problem and invert the polarities of all of the transistors. All of the NPNs became PNPs and the PNPs became NPNs. The basic functioning of the circuit is still the same, its just that everything is upside down now. And we now have two NPN outputs.

Oh and one more thing about the transistors used in the comparator. For the differential pair and the current mirror, I found a matched pair for each of them using this transistor tester. I simply picked two pairs, where each transistor in the pair had a very close hFE.

MOSFET Drivers

Since we improved the comparator, we can essentially remove most of the old MOSFET driver circuitry from before. All that’s left are the push-pull pairs like we had last time and the extra intermediate NPN to invert the logic level just one more time. What we should talk about though, is the bootstrapping. It’s essentially the same thing as the first time around, but this time I’ve replaced the diode with a schottkey. 1N4004s are extremely slow. They are suitable for things like full-bridge rectifiers operating at 60Hz, but when it comes to 400kHz, they are just too slow.

So instead, I opted for one of the faster diodes around, the 1N5819. This schottkey is fast enough to keep up with our high frequency and to keep the bootstrapping capacitors charged. And one more thing about the MOSFETs, I went ahead and added RC snubbers. These are here to suppress high voltage spikes from the inductor and also the fast switching from the other MOSFET. You’ll see why this is useful later in the video.

The LC filter

I’ll give the LC filter a proper explanation in this video since it seems like I didn’t do the greatest job of that in the first part. As per the theory in the first part, we need a low-pass filter on the output of the MOSFET half-bridge to remove the high-frequency switching component and leave just the original audio signal. Something like an RC filter won’t perform quite as well since the cut-off frequency isn’t nearly as steep. Not to mention that the power losses will be higher.

Instead, an LC filter has a much steeper cut-off and is more efficient. Unlike a resistor, the inductor can store some of the energy and reuse it later on. So, what value inductor and capacitor should we use? Well, luckily for us, Texas Instruments has created an entire paper on the subject. I’ve attached it in the description in case you are interested.

On page 9, you’ll find these two equations. Equation 5 will allow you to solve for your inductor and equation 6 will allow you to solve for your capacitor. Keep in mind that omega is angular frequency, you can replace it with 2 pi multiplied by your frequency in Hz. I plugged in 20kHz since that is the upper end of human hearing. I got a value of 45 uH for the inductor and 1.4 uF for the capacitor. I had a 47uH inductor already, so I used that. The largest value film capacitor that I had was just 470nF. This is much smaller than what the calculation calls for, but it still works. This arrangement gives us a cut-off frequency of 33.8 kHz, which is larger than the 20kHz minimum, but still much smaller than the 400kHz switching frequency.

Triangle (Ramp) Generator

If you remember from the first part, I had a lot of trouble with the triangle generator. We used a combination of a schmitt trigger and an integrator to get us the triangle. The problem with the original design was that we had to create three separate and discrete op-amps to get the job done. This adds a significant amount of complexity and instability. This time around, I figured that we should make everything much simpler to increase stability. After some R&D, I came up with the following design.

To begin, I started with just a capacitor. If you are familiar with a capacitor’s time-based equation, you’ll know that the current through the capacitor is equal to the capacitance multiplied by the change in voltage over time. If we keep the current constant, then we get a constant change in voltage over time, creating a linear ramp. We can create a constant current source by using a current limiting circuit. If you are unfamiliar, watch my previous video on BJT transistors.

Using a resistor setting of 220 ohms, we get a current of about 2.7mA. To go along with this current value, I used a capacitor of 4.7nF. Test different values as needed to fine tune your frequency. I also recommend that you use a film capacitor for this purpose. Simple ceramic capacitors will change their capacitance based on the voltage applied, which will mess with your waveform.

You’ll notice that this is only the first half of the triangle and it flattens out at the top. Well, I’d like to remind you that for generating our PWM signal, we can use either a triangle or a ramp wave. They are both linear, which is what makes it suitable for PWM operation. And I’d say that making a ramp is easier in this case, because when the capacitor reaches the height of the ramp, all we have to do is empty it.

The hard part now is detecting when the capacitor is full so that we can empty it out. A comparator won’t do, since it would cause the capacitor to rapidly charge and discharge. Instead, we should take a look at a schmitt trigger. Once the ramp achieves a certain voltage, the schmitt trigger will maintain its ON state until the capacitor is sufficiently empty.

Like last time, I’ve greatly simplified and improved the design of my discrete schmitt trigger. R18 and R19 set the voltage levels for which the schmitt trigger activates. R20 and R21 provide a virtual ground point for which the schmitt trigger will operate. And finally, Q20 is the transistor that empties out the capacitor. If the design of the schmitt trigger is confusing to you, I’d like you to notice that the core of it is simply a differential pair. R18 and R19 form the feedback between the input and output. Here is an op-amp view of the circuit. If you are still confused, please refer to my op-amp video.

Either way, we get an output of about 300kHz at the current moment. The frequency still changes a bit since we are on the breadboard. When we get to the PCB later on you’ll see how stable this design actually is.

The final thing I added to the ramp generator was this simple common-emitter amplifier. It’s purpose is to essentially allow me to change the DC bias at which the ramp operates, which will be useful when we start integrating the audio signal into the design.

Audio Input

Now it’s time for the fun part. We need to take our audio input and amplify it to fill the ramp wave. We also need to ensure that the DC component of the audio signal is the same as the ramp’s. The first time around, I had a discrete op-amp fulfill this requirement, alongside an experimental feedback system. This time around, I did away with the feedback system. This means that we will be operating open-loop, but it should be fine for this project. For the audio amplifier itself, I made a common emitter amplifier.

Most of the values are the same as the ones that I used for the ramp wave. This should mean that the DC bias on the both of them is the same. There are a couple of differences though. The first is that the input capacitor is much, much larger. Keep in mind that audio frequencies are much lower, so we need a larger capacitance to make sure that we don’t lose those low frequencies in the process. I also added a bypass capacitor to the amplifier. This means that our DC bias is unaffected but we can have a much larger AC gain.

The bypass capacitor was chosen so that it was large enough to essentially be considered a short circuit even at the low bass frequencies. The series resistor is simply there to fine tune the gain and provide a bit of emitter degeneration.

There was one more interesting discovery I had involving the audio amplifier. I found that when the amplifier was connected to the comparator along with the triangle wave, the high-frequency switching was adding interference to the audio input. This was messing with the final output quite a bit. There was actually an easy fix to this. I simply added another LC filter to remove this noise. And with that the problem was solved.


The PCB was critical to the final performance of this circuit. Like I described earlier, the breadboard was introducing quite a few issues. The ramp wave would fluctuate in frequency and the ground was noisy. The PCB fixed these things. I made the board have four layers. The inner two were the ground and power plane. I also added just one more circuit improvement. I added an LM317 voltage regulator that output 9VDC. This was done to ensure stability for the control circuitry because the main power source isn’t completely clean. I know that adding the LM317 makes it so that the design isn’t fully discrete, but hopefully you can give me break since it’s just for power regulation.

The planned main power source will be a 20V power transformer powered from mains. The output of this transformer will go into a full bridge rectifier and then a very large smoothing capacitor. Like I mentioned earlier, this rectified voltage will go into the LM317 to become 9V. However, the voltage will also go into the drain of the high-side MOSFET. This means that our comparatively low voltage control circuitry can control the larger voltage, and thus, we can deliver more power to the speaker. I also added a DC jack for testing purposes.

Anyway, enough talk about the design, here is what the PCB looks like. I’d say it looks great, and its definetly smaller than the original. After sometime soldering, here is the final result. You may notice a few components in odd spots, but that’s because I needed to make a few component changes. The final decisions will be in the schematic in the description.

One of those component changes were the MOSFETs. I had originally used the IRLZ44n for both MOSFETs, but it was greeted with the smell of magic smoke. I was unsure of why this could have been, since the breadboard circuit did not have any issues, and well I believe I found the issue. It took me several days playing around in LTspice to find this, but I believe it was due to shoot-through. And no, it didn’t have anything to do with the dead-time circuitry.

The high-side MOSFETs was turning on at an oddly specific time. Basically, the high-side MOSFET would turn-off, then there would be some delay, as per the dead-time. But, as soon as the low-side mosfet turned on, the high-side would have a very brief turn-on. The driving circuit would quickly turn the MOSFET back off, but not quickly enough to prevent damage from the shoot-through. Like I said, I was stumped for a long time as to why this was, but I found the issue.

Let’s take a moment to look at the parastics on a MOSFET. Most notably, let’s take a look at the parasitic capacitance between the source and gate and the gate and drain. I believe that the very rapid turn on of the low-side MOSFET was pulling the midpoint down so quickly, that the capacitances between the high-side MOSFET were being affected, charging the gate up enough to turn the MOSFET back on. The RC snubbers do help to stop this, but they weren’t enough apparently.

Incidentally, after finding the issue, I found this paper from Infineon. Basically, the ratio between the gate and drain and the gate and source determines how much parasitic turn on you will have. Following this, I switched to the IRFZ44n which was incidentally the only other power MOSFET I had avaliable. Either way, it seemed to do the trick and now the circuit actually works.

Let’s do some testing. Unlike last time, I don’t have to wrestle with the ramp wave. It’s perfectly stable at a clean 350kHz. It remains stable even with a load attached. Speaking of the load, the speaker does not blow up when attached, which I’d say is a good thing. The audio signal is suitably aligned with its DC bias to the ramp wave. Obviously, the audio gets more and more distorted the higher the volume that you use.

Either way, I’ll stop talking for a moment and allow you to listen to the output.

– Sound playing –

I hope that it came across well for you. It may not sound the same after a recording compared to what it sounds like in real life. Either way, I’m more than happy with these results. There is considerable amounts of distortion, but I listen to rock and metal, so it really isn’t too much of a problem.

Despite all of this, there is still a lot of room for improvement. The first thing that could be done is converting the h-bridge output to a full-bridge. This would allow alot more power to be delivered to the load. It would also mean that we could do away with the huge DC blocking capacitor. To reduce distortion, we should add a feedback system. The entirety of the control circuitry could be optimized for power efficiency. Right now, it’s using several tens of milliamps, which is quite a bit. And finally, I could research for a better MOSFET for this project. All of these improvments leave room for a potential part three.

Well, that should just about do it for the class D amplifier for now. If you’ve learned something new, please consider subscribing so that you can see my future videos. Also visit my buymeacoffee page. With your support, I can keep making these videos. I’d like to thank the channel supporters: Mr. devNull, Cognisent and Mark. You’ve helped make this video possible. Thanks for watching, have a good one.