Home | Software | Rules and About | Atom feed
Admin | Edit
published: Saturday 17 April 2021
modified: Sunday 18 April 2021
author: Hales
markup: textile

Amplifiers, horse plague, SPICE and home etching

For the past week I have had horse hand foot and mouth disease. Not to be confused with foot and mouse disease, but that has not stopped friends and family making farmyard noises at me continuously.

Getting this as an adult sucks (a bit like chicken pox): I was initially on max doses of ibuprofen and paracetamol to deal with the fever & shakes and was at one point recommended to an emergency department. Eating food was difficult or impossible due to throat pains, but I'm now back to eating half a mammoth every day. Pain when using the soles of my feet and my hands (including interesting phantom sensations out of nowhere) have now subsided, replaced instead with me kicking power tools with my toes and getting sudden unwarranted leg cramps at 6AM in the morning :D

Somehow I suspect Rubenerd is at fault. Maybe he emailed me this virus.

I'm still spotty, but my mind has been slowly returning enough that I have had some more audio amplifier adventures. Onto the main course!


Single-channel 12V audio amplifier:

Gain is flat in the middle with -3db points around 20Hz and 60kHz:

(Tested with Vin=100mVrms, load=10R resistor, ambient=20degC)

This is more than good enough for 90% of audio work. The flatness is due to the opamp's negative feedback control. The low rolloff around 20Hz is caused by the AC coupling at the input. The high rolloff is caused by intentional bandwidth limits on the amplifier.

Crossover distortion was initially quite bad until I tuned it. Quiescent current is below 100mA when tuned (depending on temperature it can be lower than 20mA).

Output voltage swing range (and power output) is severely limited due to some bad design decisions that prevent the transistors being used anywhere near their limits. After mods described below: max 4.8V volts peak-to-peak (a few watts across a 4R or 8R speaker) before clipping suddenly occurs, which in practice means you have to run it at a much much lower average to avoid transient sounds clipping. I am working on improving this, more detail further down.



Nothing too fancy here. The capacitor and the resistor provide AC coupling of the input, centering the audio signal around a pre-defined middle voltage point. An extra jack allows you to bypass this AC coupling, which is suicidal for normal audio use but occasionally useful for some specific tests.

100nF and 100kohm makes a high-pass filter with a -3dB point of f=16Hz. This is more than low enough for the kind of listening I do, I don't think my speakers can go anywhere that low anyway. Whale communications?

Discrete opamp

Controlling the amplifier is an opamp. Normally I use off-the-shelf well specced opamp ICs, but I thought I'd have some fun this time and make my own out of discrete parts.

Two 2n7002 transistors act as the + and - opamp signal inputs. This configuration is called a long-tailed pair. The two PNP transistors at the top act as a current mirror. The PNP transistor on the right provides much of this amplifier's gain, outputting the signal to the next stage.

Capacitor C5 on the output transistor is a quick hack to make the amplifier stable. Without it I found my breadboarded circuits did work, but modulated a very high frequency into whatever desired signal you have, making your signal look super-fat on an oscilloscope:

In other words the amplifier oscillated at a high frequency. Adding the capacitor dramatically reduces the device's gain at higher frequencies, stopping it from oscillating.

There are several other ways of changing the gain & phase of amplifiers to fix problems like this oscillation, of which I plan to experiment with a few. I want to get some more bandwidth back (to try and over distortion a little more, more on this later), but at least for now it works.

I didn't have any 100ohm SMD resistors so I used 10ohm ones instead.

Ideally I want to see if I can plug my NanoVNA into this and create gain + phase plots like you see in opamp datasheets. This would greatly help me work out where & how compensation would best be done (aka work out where I need to plop my poles and zeros to fix this problem).

Output driver

On the left is the bias circuitry, designed to try and eliminate crossover distortion. Then the two big IRL40B N-channel mosfets are used to do the actual speaker driving. On the right are capacitors for AC coupling the speaker. On the lower-right is a resistor divider to set the gain of the amplifier (~9.9dB) and send feedback back to the opamp.

Simple introduction for those not familiar this this style of design: this amplifier uses two transistors (the big IRL40B's) to "push" and "pull" current in and out of the speaker. They are wired in what is called an AB amplifier arrangement. If you send your audio signal directly to the gates of a pair of AB amplifier transistors then you will make a working power amplifier, but, a whole chunk of the signal in the middle of each waveform will be lost due to a problem called crossover distortion. This distortion sounds nasty. This problem is fixed by the biasing circuitry.

Acute readers will notice that I am using two N mosfets in this AB amplifier, rather than one N-type and one P-type. Normally this style of "common collector" ("common drain" really) amplifier uses two opposite types of transistor. I cheat by instead converting the bottom transistor into a P-type using a little PNP transistor. This is called a Sziklai pair and I wish more people knew about it, it's an amazing little circuit that makes the lower mosfet perform like a P type with very little (almost no) extra voltage drop (as opposed to a darlington pair, which adds a lot). The 100ohm resistor is optional, it theoretically may prevent ringing in the mosfet gate, but I never bothered checking if this was even needed.

The biasing circuitry on the left is of my own design (I've seen people use rubber diodes instead). The aim of my design was to try and provide more stable behaviour when Vin changes away from 12V, but it ended up being abysmal there anyway. The 5V drop is way, way too much (I've replaced the 5V zener with a 3.3V zener) and has severely limited my output voltage swing range. The quiescent current that is wasted through the two main mosfets goes up dramatically with temperature too, something that concerns me.

The output capacitors remove any DC from the voltage being sent to the speakers (DC makes speakers burn). Other traditional solutions include attaching the other wire of the speaker to your middle voltage (requiring a split-rail power supply) or using a second amplifier outputting an opposite/inverted audio signal for the other wire of your speaker (which gives you 2x the output voltage swing as a bonus). Capacitors were the simplest solution in my case. 2000uF into a 4-ohm speaker is a high-pass filter with a -3db point f=20Hz (or f=10Hz for a 8-ohm speaker), way more than good enough for my uses. Ideally I would add a relay and dummy resistor to eliminate startup pop, but that's an extra nicety I have skipped for now.

The two 0.1ohm resistors between the main output MOSFETs are there to make biasing a bit easier. According to my SPICE sims: adding these resistors makes the quiescent current slightly less sensitive to changes in the bias. In other words: the amplifier doesn't go boom as easily if you are a little too quick turning the bias pot.

On the topic of SPICE...

SPICY interlude

I've found SPICE sims to be useful for a few parts of audio amplifier design and complete utter hair-pulling garbage for others.

I use QUCS to do my sim work. Another option is the (now free) Micro-cap 12, but according to my experiments it runs sims at a fraction of the speed of QUCS (wild guess: it redraws the window during sims, which may be slow on Wine/Linux). I have never tried LTspice in any depth so I can't pass opinion there, but it's very popular. If you are happy to describe your circuits in text (!) then ngspice is an option, but I have not wrapped my head around that.

DC sims

One thing SPICE sims can do really well are DC simulations to give you amplifier transfer graphs. In simple terms: what does my amplifier output for any given input (ignoring high-frequency AC effects)? Have a look at the lower-right graph for Vin vs Vout of an output circuit similar to what I have been describing in this article:

Notice that around Vin=5V to Vin=7V the output does not change, it's falt. That's the crossover distortion that needs to be fixed. Negative feedback alone (from the opamp) isn't enough to completely get rid of this, you still see little skips/errors in the waveforms as the cross the middle.

Also notice the output limits: about 2.5V min and about 9.5V max (the circuit is being supplied with 12V). This is useful information for predicting the output swing range of your amplifier.

For this sim I have pretended the speaker is a dummy 8-ohm load that sits halfway between 0 and 12V (an actual 8-ohm resistor to a 6V source would be equivalent). It's not 100% accurate, but it's good enough for simulating & fixing problems with crossover distortion and output limits.

Earlier I mentioned a rubber diode circuit for fixing crossover distortion, here it is in action:

Notice Vin versus Vout graph on the bottom right no longer has the flat bit in the middle. It's a little curved too, but the negative feedback from the opamp can more than easily correct the effects of this (it's only a small change in the slope). Now if only I used that bias circuit on my real board!

Transient sims

Oh god the pain oh why.

So let's say you want to see how your amplifier works with a real signal, all simulated in a SPICE sim. This lets you see if there are any weird behaviours or instabilities.

That doesn't look too painful, does it? The output (blue line) matches the input (red line) exactly, showing this 1x opamp amplifier is working fine.


Getting a transient sim to work in any circuit with feedback is painful. Change the resistor values slightly? Jacobian singularity. Change the number of simulation points to be higher or lower? Jacobian singularity. Sneeze? Jacobian singularity.

So what causes these errors? Answer: anything that makes the solution finding in the spice sim get confused and be unable to find converging solutions. What does that mean in simple terms? Basically anything in your circuit could be misbehaving, good luck finding out what, trial and error is your friend.

If your amplifier isn't stable at a certain frequency (this is something that you probably want to find out!) then the transient sim will shit bricks at that frequency. On that note: simulating actual intentional oscillator circuits is a pain too, you often have to dial their gain way down and fiddle a lot to make the sim happy. Sometimes increasing the error tolerances in the sim properties helps, but not always.

If any readers know the blessed SPICE knoweldge needed to fix problems like these then I would love to hear it. On that note...

Learning SPICE sims

Like all technical software, Qucs has some annoying quirks to its interface (tip: secret key shortcuts are explained in the manual) and the only way to learn how to use the program is to look at the example files shipped with it. The manual barely scratches even basic questions that appeared in my beginner's head when I first started using it, like "where in the menus do I configure the simulation?". Answer: Qucs simulations are objects like resistors that you draw on the canvas, not global settings in a menu.

Some basic understanding of the different sim types is useful (namely the big three: DC, small-signal AC and transient) . The maths language in each SPICE sim seems to be slightly unique, sometimes the manuals help here (but not always!). Half the time variables are in an arbitrary number of dimensions, you need to use various suffixes and 3/4 of the time you're teeting on the precipice of simulated mortality.

What might seem like a simple task from the outside often isn't. Questions like "Mr Software, what is the dominant frequency in the voltage-versus-time plot of my oscillator?" spiral into "I can FFT using arcane sigils but then I need to work out what freqs the bins mean myself and half of these numbers don't make sense when I try". In the end you give up and put a ruler on your screen.


Please don't get me wrong: I really love Qucs and a big thankyou to its devs. It has solved a lot of my problems and taught me quite a bit. Regardless: SPICE software leaves me feeling like I need to be a quantum tunnellist to operate it correctly, like there is a whole field of understanding that I'm barely scratching and need a proper hold on to succeed with these tools.

Back to the amplifier circuit: middle vref

This is a simple voltage divider followed by a voltage follower (aka a class A common-collector amplifier). The capacitors reduce the noise on my voltage reference.

The output audio of the amplifier is centered on this middle voltage reference. In hindsight: I should have made this adjustable with a pot. Instead I guessed at a good value (slightly above 1/2 of VCC) and was completely wrong. In my built board I have now tacked on some extra resistors to bring the vref down.

When the middle vref is wrong: the output of the amplifier starts clipping on one side of the waveform (eg the top) well before it starts clipping on the other. If you re-adjust your center vref to be better then you can get a larger voltage swing on your output before clipping occurs. If you build this amplifier as it's shown in the schematics above: expect maybe 1V P-P of output audio swing before you clip on the top, it's that bad!

This problem was made worse by the massive 5V drop in my bias circuitry. Next time there will be some improvements!

Etching PCBs at home

I have etched quite a few boards at home before, but only ever single-sided and with varying luck. Over the past few days I have learned several tips that have given me much more success.


I used the "toner-transfer method", because I'm too cheap and impatient for anything else. I have taken a lot of advice from a Mr Carlson's Lab video this time around, have a look at that if you have never done this process before.

For years I used the waxy paper that stickers come on (you can order sheets of plain A4 sticker paper off eBay, then peel off and throw away the paper part). At some point I bought actual dedicated toner transfer paper and have been using that instead. This lets me peel the paper off without wetting it at all; interestingly it seems you have to peel it off immediately whilst the boards are hot for best results (not wait until they cool).

Previously I have performed the transfer using a clothes iron, but every time my results have varied dramatically. This time around I followed Mr Carlson's method of using a laminator. It turns out these are only just hot enough, requiring you to quickly put the board right back in the laminator as soon as it emerges, over and over. If you don't then the board cools too much and you get a bad transfer.

Good transfer on top, bad transfer on bottom (showing the source paper too):

I am still failing to obtain really good toner transfers for the amplifier circuit shown in this article (the above photo was an amazing fluke!), so I spent a lot of time with a permanent marker fixing things afterwards. Adding more paper around the sandwich whilst laminating seems to improve things slightly (evenly distributes the pressure?) but it's still not enough for reliable transfers of complete boards.

I used Mr Carlson's lightbox method to align the double-sided design. In my case this was a sheet of glass, a big LED and some spacers. Previously I discovered that old LCD panels are amazing backlights if you throw away the LCD layer and keep the rest, but I didn't have any handy this week.


I have always used the hydrogen peroxide + acid + salt technique. My first foray into this was using expensive glass bottles of weak hydrogen peroxide and strong vinegar from the supermarket, with mixed results. Etching speed and quality varied dramatically. My biggest problem has been pitting of the copper:

This breaks tracks and prevents reliable soldering.

If I tried to etch for less time then I would get un-dissolved copper in places that I did not want it (and still pitting too). I always assumed that this problem was due to bad/porous toner from my printer. It turns out I have been very wrong.

The solution is simple: I need to use stronger etchant! If you etch faster then the etchant tends not to make its way through the toner as easily. This has let me achieve some beautiful results:

Notice the pitting is now very minor. The rest of the smudges & blemishes are due to a dodgy toner transfer that I fixed up by hand with a permanent marker.

If you look really close then you will see the copper on the other side of the board :) This was magic to see appear in my etchant bath, I have never done a double-sided board before.

The etching solution was a strong as I could make it:

Obligatory: this is dangerous, you need to research the safety issues here before deciding you want to attempt this. Take responsibility into your own hands and plan how to do this safely. Blindly following a random site on the internet (eg this one) is just stupid.


Side note: Another common etchant is ferric chloride. I started making some a few days ago using hydrochloric acid and steel wool. My steel must have had a lot of sulphur in it as it made lots of rotten egg gas. It's still slowly using atmopsheric oxygen to change from ferric chloride (greeny) to ferrous chloride (orange/brown), notice that the few small drops around the brim of the container have already converted:

Protecting & cleaning

Bare copper boards tarnish within minutes of etching, this makes it hard to solder to them (and eventually ruins them).

There are proper soldermask products available, but those are fiddly, probably smelly and definitely expensive. I give my boards a spray of thin oil instead (in my case Inox Mx3, which claims to be non-toxic) and then wipe all but a thin layer off with a paper towel.

Whilst the boards are coated in oil:

Placing & soldering SMD components

I use (lead-free) solder paste in a small plastic syringe, tweezers and a hot plate. It's dead easy. Don't bother with people telling you about stencils, that's only for mass production or BGA parts.

All the parts except the capacitors soldered on my hotplate. My board started smelling bad so I pulled it off the heat early, I know from experience that the cheap copper-clad boards I use don't last at high temperatures as well as proper FR4 boards that I have ordered from PCB makers do. If I had continued I would have run the risk of the copper bubbling off the board (adhesive failure?). Manually soldering the caps with an iron is easy enough.

I had no issues with the solder paste sticking to the bare copper. The oil + steel wool treatment I mentioned in the last section worked wonderfully.

The copper came out in tasty shades due to the heat, but this coating (surprisingly) did not seem to get in the way of hand soldering the through-hole components later:

Sparkfun has an amazing guide on reflow soldering. They conclude that cheap electric frypans (electric skillets) work just as well if not better than expensive SMD ovens.

My electric hotplate is a bit more fun-n-dangerous than the average skillet. My local K-Mart wants most of 40AUD for an electric skillet by memory (that's over 120 Tim-Tams!) so I bodged together my own a few years back:

That's a round aluminium+element heater from a rice cooker with a solid block of aluminium strapped on top as my working surface. Temperature control is via an oven thermostat -- these things are really cheap (a few dollars off eBay) and very cool, they use the expansion of a fluid/glass in the sensor (long thin round thing that goes through the top block) to operate a mechanical switch. The remainder of the unit is built using plasterboard (heat resistant), pine, bent aluminium coathanger, screws, a mains cord and a small choc-block terminal. I put a little bit of caging around the exposed wires (notice the mesh in the middle) but it's still technically possible to electrocute yourself by putting your hand underneath the element and onto the exposed thermally-relieved sprial wires. But hey, if you can push your hand far enough under the 250degC hotplate to get to those wires then you have earned that privilege.

It's not perfect. It has horrible temperature hysteresis (due to the high thermal resistance between the element & the main working block; not to mention the super cheap thermostat) and overshoots by something like 50degC some 60 seconds or more after the heater has turned off. The safety isn't the best (what gave you that idea?) in that it's possible to drop tools between the box and the hotplate and get shocked. Apart from that it works very reliably so I can't complain too much :)

One of these days I'll get a real hotplate. Albeit they seem to be built down to a price.

Final product

Still needs some cleaning of flux residue and the re-oiling, but it's working well:

Fun things to note:


License: Creative Commons BY SA, including the goat-face artwork. Uses some footprints from the kicad-footprints project (these are very permissively licensed).

What next

It works. I'm going to keep tweaking it a bit, then make a second so I can have a stereo pair for my desktop computer speakers. Complete overkill, but so was the massive YAMAHA radio I had built into my desk until recently. If your amplifier can't set fire to your voice coils then it's not big enough.

Unanswered questions:

Blog posts still todo:

Add your own comment:

Email (optional):
URL (optional):
Enter the word 'irrlicht' (antispam):
Leave this box blank (antispam):

Comment (plaintext only):

If you provide an email address: it will only be used for the site admin to contact you, it will not be made public.

If you provide a URL: your name will hyperlink to it.