Multi-Zone Stereo Page STM32 Design Contest
Blog for this project
project will be published
Cellar Magazine Jan. / Feb. 2014 issues
The Schematics and PCB
files are here
The STM32F embedded
code is here
In 2010 I wanted to improve my coding skills, get into a new
processor, and start a product development. A lot to take on all at
once. So when the opportunity to enter the STM32 Challenge appeared
in December '10, I decided to do it. Winter is a perfect time to do
nerd projects. So what to design? I wanted to do something with both
nerd and general appeal, something that I was familiar with and
could use myself. Years ago I built a house-wide home stereo,
capable of playing music anywhere in the house. I have wanted to
update this system to newer technology. The original system sports:
An 8 x 8 stereo crosspoint: 8 input channels and 8 zones.
A preamp per zone with volume, tone, balance, etc.
Control via front panel, IR remote and wired-remote button
boxes for each zone
A 240 x 64 monochrome graphics display to show the status of
High quality audio: about .01% distortion, low noise and
High quality phono preamp
Line level outputs to drive external amps, powered speakers,
line-in of stereos, PCs, etc.
It was built in the mid 90's, and powered by a Motorola 68hc11
processor and surplus graphics LCD driven by a custom FPGA. The CPU
board had separate RAM, EPROM and I/O, and was hand-wired. The
crosspoint was also hand-wired. The preamps were small home-etched
single-sided PCBs, one per zone. The original system used a motley
assortment of external amplifiers, collected over the years.
Here is the original system, now dusty and neglected.
The new system should do all that plus:
Use real PC boards throughout (ExpressPCB to start)
Use updated components and development tools based on a
single-chip flash microcontroller
Available, low cost LCD with built-in controller and LED
4 Channel preamp board
Allow at least 2 units to be built: one for development, one
Include 4-6 zone stereo audio amps, 20-40W per channel
Other features on the wish list:
IPod cradle: just audio out for now, maybe add controls later
1-2 outputs without preamps: just line level
Ethernet control: web page
Controls for an external audio server via Ethernet
Smarter room controls: POE based with displays, IR receivers,
maybe other home control functions
Include MP3 player that can access a local or network file
Digital audio (SPDIF) inputs and outputs. Maybe some DSP
Home theater output channel(s).
Isolation / differential I/O to address grounding for PC audio
Zone amplifier power on/off controls for power savings
I already had the basic code and LCD working when the boards
arrived. I spent one long caffeine-and-pizza-powered weekend writing
the control code for the crosspoints and preamps, front panel
keypad. STM libraries are quite powerful, maybe too powerful.
Fortunately there are good examples of how to use the basic and
advanced features of each peripheral. For example, there are about
30 I2C functions, and 5-6 are required just for basic I2C master
operation. If there is no I2C device present, then no acknowledge is
sent and the example code just hangs waiting for acknowledgement.
The debugger can then be stopped to find out where in the code it is
hung. Since I have a bunch of I2C devices, not all may be connected
at any time. having it hang trying to access a non-existent device
is no fun. The best way is to poll the device, timeout if no
acknowledge is present, and reconfigure variables to tell the
control code it isn't there. I didn't have time to code all that so
instead I made a constant for the number of preamps to control.
Most preamp functions are working including the keypad and IR remote
control (not shown). The ethernet module is just sitting there. No
hardware or software yet. There is still just one preamp channel
I prepared a video demonstration for the contest proof of concept
stage and was selected for the finals, and the judging is in early
May. Lots more board stuffing and coding to do.
The schematics for this project can be found here.
Here is the first pass open breadboard. Across the top, L-R, are the
crosspoint and the 2 quad preamp boards. Across the bottom: the CPU
board with STM32 processor module and Wiznet Ethernet modules is
just plugged in, not connected, the 128x64 LCD, and the 32 button
Below is the Crosspoint board with 8 dual input buffer opamps and
two 8x8 crosspoint chips. The crosspoints use 8 bits of control,
provided by the IC on the bottom. It is an MCP32008 I2C GPIO port
that drives the 8 parallel bits.
The 16 pin ribbon on the bottom supplies +/-12V and +5V power and
I2C control from the CPU. The two wider ribbon cables supply the
same power and I2C, plus 4 channels of stereo audio to each of the
preamp boards. This board has ground planes on top and bottom to
guard the audio signals from each other to reduce crosstalk.
Below is a Quad Preamp board with just one channel populated. The
preamp chips are ST TDA7439 which provide full function audio
control. The red and grey film caps are for input coupling and tone
control. These preamp chips don't have I2C address selection,
so logic on the left uses another MCP32008 and a CMOS switch to send
I2C to just one of the 4 preamp chips. All audio signals are guarded
from other channels and from the I2C control signals to reduce
digital noise and channel-to-channel audio crosstalk. The
bottom PCB layer is almost solid ground plane. As a result, there is
no audible I2C crosstalk. I have not measured the crosstalk but none
has been heard.
The project is a top ten finalists, and here is the prototype
ready to ship to the STM32 Design Challenge. A front panel was
built, and a power supply added. All 8 channels are working as are
the IR remote control, the encoder knob, and the remote keypads.
I'm happy to say the project won an honorable mention, one of three
second prizes. Meanwhile I have started building a second
prototype.The Crosspoint and Preamp boards are stuffed and working.
Most of the time was spent hand-wiring a smaller CPU board. The
original CPU board (above) was incrementally built over several
months, starting with the STM32 Discovery module and the LCD, slowly
adding the I2C, Keypad, remote keypads, IR, encoder, etc. Hand
wiring the second board has taken many hours, and I realized that I
could have done it better, faster and smaller on an ExpressPCB Mini
board for $80, for 3 bare boards.
Now on to building the final unit that will live in the living room.
It needs audio power amplifiers and a real case. This version will
have 4 stereo amplifiers and 4 line level outputs. Here is the block
6/17/2011 LM3886 Amplifiers
The prototype is back from the ST design contest, and the next step
is to build or buy amplifiers to drive speakers in the rooms of my
house. I, like a lot of of the DIY audio community, am pleased with
the LM3886 audio amplifier from National Semi. I have built up a few
LM3886's over the years. My plan here is to build a modular
multi-channel version to drive speakers around the house, that is
cheap, simple and provides good performance. My goal idea is to
build 4 channels of the amp on an ExpressPCB mini board. Here are my
requirements for the amp:
30-40W per channel, very clean
4 or 6 stereo zones (8 -12 amplifiers)
Low crosstalk from zone to zone
Single power supply
On-demand fan cooling
Based on the ExpressPCB Mini board: 4 amplifiers per board,
$60 to $85 for 3 boards, 12 amplifiers.
One challenge with the LM3886 is that the package is designed so the
PC board is at a right angle to the heat sink mounting plane. This
type of mounting requires a fair amount of physical volume. A 12
channel amp would require a large case. To save space, I envisioned
a design where the device was in the same plane as the board. I am
happy with the results. The board mounts only with four screws in
the mounting holes of the four LM38886's, which are sandwiched
between the board and the heat sinks. The board can be flat mounted
to virtually any flat heat sink with just four #4-40 screws. This
requires re-bending the LM3886 leads, a simple operation with
needle-nose pliers. I used the insulated package LM3886 so no
insulators are required, just a bit of thermal compound on each
device. While searching Ebay for heat sinks. I found a nice
Express-PCB-Mini-Board-sized one (3.75" x 2.75" x 1.25", search Ebay
for "heat sink 3.75" ) and bought a few. It has a wide mounting
flange on the bottom and even comes with two 6-32 tapped holes on
the flange. It could not be more perfect.
Here is a 4 channel amp mounted to its heat sink. The board
uses a mix of surface mount parts (0805 and larger) and some
thru-hole on the front side. There are only the LM3886's on the
back. Film capacitors are used for input coupling, and a Zobel
network is used on the output. No output inductor is currently used,
but there are provisions for one in case it is needed. For the amp
DC power and speaker connections, pluggable .2" screw terminals are
used These are reliable, small, inexpensive, and easy to field
The back side showing four LM3886's, ready for
thermal compound and to be mounted to a heat sink.
This is what 12 channels of amplification would look like. At this
density a fan is needed. The speaker connectors will protrude from
the rear panel (not shown).
Multi-Channel amplifiers require a
My goal is to build 8 or 12 channels in a small space and for short
money. So it is desirable to use one bipolar DC power supply for all
the amps. A problem is that most amp designs will crosstalk badly if
you simply wire multiple amplifiers to a single power supply. The
high output current from one amp channel induces audio voltage
on its input ground pin. This causes the next amplifier's input
ground to have the same voltage. So there is a voltage between one
amplifier's input an the next. This voltage is multiplied by the
amplifier gain (+26dB) and appears as crosstalk. This
crosstalk is a function of the resistance of the audio cable grounds
and the length of the ground return wires between the power supply
and the amps. A spice simulation of this problem showed that
sure enough, with normal wire sizes and PC traces, the crosstalk
from one zone to the next is about -40dB, not very good. But by
making an "input ground", separate from the speaker grounds, and
tying the input grounds to the power grounds only at the power
source, the crosstalk is more like -90dB. Electrically this requires
a separate Ground return pin for each amplifier board, where the
input, input circuitry and the feedback circuitry all return. Then
these low current grounds are run back the the common power supply
"star" ground. The result is that only very low currents flow
through this input ground and the crosstalk is reduced to about
90-100 dB. Here is the final board schematic showing IGND the
separate input ground. Ideally there should be an IGND per amplifier
or per zone, but a single connection per 4 amps will do the job well
enough and simplifies the wiring.
How much power?
For the main living room system, I have a separate high power
amplifier and speakers. For the remote rooms, the bedrooms,
deck, basement, etc., typically these will be used at 5 watts per
channel per room. Modern speakers are small and efficient. 30-40W
amplifiers provide lots of headroom, preventing clipping. It is
unlikely that all zones will be simultaneously driven to maximum
power; I have neighbors. My goal is to build 8 or 12 channels
to drive 4 or 6 rooms. So at 5W per channel x 8 channels, that's
only 40W of audio. That requires about 80W of DC power. If one or
more rooms are turned up loud, they might use 20 or more watts each.
And the transformer and power supply capacitors should have plenty
of capacity for the occasional loud passage. I sugggest a
160VA transformer for 8 channels, 250W for 12 channels. Audio
purists may be concerned. Since the '70s I have designed and built
many amplifiers and when designed 'by the book' to provide full
power sine waves, the designs are far too conservative and heavily
over-designed. The only time anything gets hot is when I am in in
the test lab heating up 8 ohm load resistors with full power sine
waves. In normal use, nothing even gets warm until you are about to
go deaf. Real audio is different than sine waves. Sine waves have a
peak to RMS ratio (crest factor) of 1.41:1. Real audio is closer to
5:1. So the system will have plenty of capacity for big bass notes
but will stay cool.
But alas, there is a problem. I had planned to tightly pack these
amplifiers, and to use the LM3886 mute function to control the power
to each zone as needed. Then use a single small, quiet fan to cool
them only when the temperature rises. Do you see my error yet?...
The mistake is that I assumed the LM3886 mute function reduced the
quiescent current of the amp. No, it just mutes the audio, in my
opinion a fairly useless feature. Each amp uses about 50mA of
current always, even when muted. At +/- 30V each amp uses 60V
x 50mA = 3W when it is powered. 8 amps draw 24W, 12 draw 36W. Pretty
bad. With small heat sinks and close packing, the temperature rise
is high enough to warrant a fan at all times. I am bothered by
wasting 24 or 36W all the time. There is no easy way to turn off the
DC to each amp. Doing so requires 2 high current transistors or a
relay for each zone. The current boards use single power connections
for 2 zones, so no easy way to control each zone.
My interim hack is to manually switch DC power to the rarely-use
amps only when they are being used. In my house, the most commonly
used zones, the living room, den and 2 bedrooms, all have
their own external amplifiers. The Kitchen and basement are commonly
uses and so are always on. The other 2 zones (bathroom and deck) are
rarely used and so I switch their power manually. For
now there will be a simple front panel switch to switch DC power to
the amplifiers for those zones. This issue is motivating me to
consider efficient, switching (Class-D) amplifiers. These will
address the quiescent power issue, but I suspect will make the
crosstalk issue much worse when operating from a single supply,
since Class D amps draw lots of high frequency switching current.
Enclosure for the Preamp and Amps
With the preamp and 8 or 12 channels of amplifiers, I wanted the
entire system to be mounted in a single enclosure. A Visio drawing
below shows that this is possible in a 2U 19" rack , a 17" x 12" x
3.5" enclosure with 1" rack ears to make 19" wide. . The advantages
of a single case for both preamp and amps are:
Reduction of external interconnect cables and rear panel
space, expense, etc.
Reduction of sheet metal and assembly work
Saves an AC power cord and a power supply
Reduction in space in my stereo system
Possible hum from power transformer magnetic fields to phono
Power density requires a fan for cooling
Single point of failure: when one thing breaks, the entire
system is down
Also if I ever add power amp DC power control by the preamp, having
that wiring internally will be cleaner than doing it
externally. The trick to getting it all to fit is to stack the
two Quad Preamp boards piggy-back style via spacers. The bottom one
has 4 sets of RCA jacks to drive line level outputs to 4 zones. The
top board has 4 x 4 pin headers for internal connection to the 4
stereo amplifiers. There is room for 12 channels (3 modules), but I
expect to only use just 8 because that is what I need, and also to
save power. The added height still fits nicely in a 3U (3.5" )
For the +/- 12V power to the preamps, small DC-DC converters will
convert the +30V from the power amp supply to regulated +/-12V. This
is not shown.
For cooling, there will be exhaust holes in the rear panel near the
speaker connections. Intake holes will be in the top cover, forward
of the fan.
The main boards are mounted to the base and a new 19" front panel is
in the works. Most of the wiring is in place and the system is
Control code cleaned up.
The new front panel is installed and looks good. 8 channels of
amplifiers (4 zones) are installed and wired up to speakers around
the house. The new remote keypads are working. My family has
attended the training class and they are enjoying music in the
new zones as well as the old ones.
There is no fan yet or DC power switching and so the amps get quite
warm. The chassis consists only of a bottom and front panel.
The original quick-and-dirty control code was bothersome. The zone
management was all manual. When you controlled one zone, it
permanently stayed at that zone until you set it back. The
expectation is that the front panel controls (IR, knob and front
panel buttons) are primarily for the living room zone. The
original system had a default timer to reset the controls back to
the main zone, and this one needed one too.
The mute key caused an annoying problem. Having every key
auto-repeat including zone select and source select was never a real
problem since the audio output was barely disturbed. It simply
selected the same zone or source over and over. But with the muting,
you want to mute once and stay muted until the button is pressed
again. It is the first function where auto-repeat is a problem. The
old way of having zone and source select repeat as long as you held
the control was inelegant. So now there is code to only repeat those
functions that should be repeated: volume, balance and tone
I addressed the control code. All of the controls now use a
consistent data structure for de-bounce time and repeat time. It
also has a time-out timer to reset the zone back to the default
after 20 seconds. Keys no longer repeat by default, but only those
keys that need to repeat do so. The user experience is much better,
less twitchy now. It's amazing to me how much time, effort and code
is needed just to make a handful of different buttons act nicely. I
want them to all act similarly, and don't want to duplicate that
code, so made a consistent set of code for the various controls.
Arrays of control structures are your friends.
Another system issue is fixed: The various line level sources are
pretty well matched, but they were higher level than expected. Also
my main living room amp has more gain than the LM3886s (34dB vs.
26dB) and has very efficient speakers. So the lowest volume setting
of -47dB on the TDA7439 preamp chips was too high for the living
room. But the maximum level is just over clipping (and very loud!)
so I am reluctant to just turn the gain down on that one zone. I
suspected that -47dB of volume range was inadequate, and it is. Now
the volume function uses some of the 'speaker level' range of the
preamp chips to extend it to 60dB at settings below -47dB. There is
also an input range adjust that can be used and has 2db steps. Using
the speaker level for both balance and volume complicates the volume
and balance setting code a bit, but 60dB is a decent control range.
Maybe 70dB would be better? I also changed the volume steps from 1db
to 2db so it takes less time (30 steps vs. 60) to adjust the volume.
2db steps work fine.
9/1/11 Class D Switching Amplifiers
I purchased a 4X100W
switching amplifier board made by Sure and sold by Parts
Express. It has decent specs and has fairly quiet audio. Amazing
deal at $48. Quiescent current is lower than my LM3886 amps, and 2
of these boards will stack in about the same space as my 2 x
4channel amps. It hasn't gotten past the lab bench though. I suspect
that crosstalk will be a problem, just as it is on any multi-channel
amp unless it uses the input ground fix I describe above. On a
switching amplifier this problem is harder to solve, I suspect.
Photo from Sure
2/1/12 Yet Another Audio
SparkFun has a stereo amp kit based on the ST540 Stereo
Amplifier chip. This chip is a good quality 35W per channel
amp. It has 2 channels per IC, uses a single 20V power supply
(bridged outputs) and has a nice shut-down feature, unlike the
LM3886. It also has good stability when driving long (capacitive)
speaker cables, requiring no Zobel (RC) networks. Driving long
speaker wires is key for a whole-house stereo. SparkFun gets $4.95
per chip, qty 1, $3.96 for qty 100, much less than two LM3886s. I
think I can easily build 3 x 2 channels on the same ExpressPCB Mini
board size that I used for four the LM3886s. The design will require
a similar grounding trick to the one used on the LM3886 board to
prevent channel-to-channel crosstalk.
Photo from SparkFun
I want to add a simple web page to control the system. Since the
serial port has commands to replicate all the buttons, that is a
good starting point. I'm no networking guru, so I'm looking for a
simple solution to adding Ethernet. There are lots of ways to get
networking on an STM32 including these that I have considered:
Use a STM32 processor with Ethernet (STM32F107 processor plus
an external PHY and mag-jack)
Use a Wiznet like W5100 (SPI to 100BaseT) chip or module
Use a Serial to Ethernet device. XPort looks good
Use an external Linux CPU with a proper web server and serial.
Use Arduino and an Ethernet Shield
1. would require a new CPU board. I would need to buy a $300 eval
board to get started, then either use the eval board in the product
(expensive) or build a CPU with Ethernet PHY. I still haven't seen a
cheap STM32 board with Ethernet. Nor have I found a simple
HTTP example for the STM32.
2. could use a Wiznet SPI to
Ethernet module such as WIZ810 ($20)on my current board. I
haven't seen any port of the Wiznet code to STM32, but it probably
isn't too big a job. Where the STM family has a version with
built-in Ethernet, this is not the most elegant solution. The
problem with Wiznet is its HTML code is pretty rudimentary and after
that I'm on my own. Like I say, I'm no networking guru.
XPort is $45 and is packaged in a very small, extended-length
RJ45 connector. It comes with HTML, FTP, Telnet, TCP, Email, decent
tools, and is pretty easy to use. It has a Java run-time engine
(JRE) so you can install Java code to build GUIs and applications.
Java is probably a decent skill to have The Lantronix tool for
downloading code is a bit clunky, requiring you to break your filed
into chunks that fit in 64K. Clearly a proprietary, closed solution.
4. is promising. Embedded Linux is good where you need access to
networking, server, USB, video, audio, big GUI, file system... I'm
not seeing any ARM Cortex M3 Linux ports since Linux needs too much
memory for M3, requiring large chunks of SDRAM and flash. Until
recently an embedded Linux board was about $100 but there are sub
$50 boards available. Raspberry
Pi claims impressive specs and capability at a $40 price tag,
but it is a bit of a toy. It is not open hardware and not available
for commercial design, since the processor is available for high
volume (consumer) use only. Olimex iMX233-OLinuXino-MAXI is an open
hardware solution and looks decent for $60. If I were to want to add
audio server (audio file player, ether network or local thumb drive,
Pandora or on-line music, etc) capability to this project, Linux
would be the way to go.
5. the Arduino approach is appealing since there are both
hard-wired Ethernet and WIFI shields available along with decent web
server demos. Two possibilities:
1) add a low cost Arduino (Leonardo + Ethernet
Shield) to the STM32 as a simple stand-alone web server, or
2) use a higher-end Arduino Due (Arm based) and
eliminate the STM32.
Option 1) is probably quicker and easier and would be a good
starting point if I ever decide to move to 2). It has the
disadvantage of adding 2 boards at a cost of about $70.
Tools update In case you wondered how ST can sell the Discovery series of
development boards for $12 and up, the answer has arrived. You can
only purchase them in small quantities, and only for development.
The Discovery modules are not to be used for a product. I'd like to
see someone build a low cost STM32 module.
On the compiler front, Atollic further restricted their free
compiler version. While I was developing code, they dropped the
number of code breakpoints from 3 to 1. That wasn't terrible, just
an inconvenience. But in 2012, they dropped the maximum n code size
from 128K to 32K. The full version of Atollic is quite
expensive. Since my code size is 48K and growing, that is a
deal breaker. I installed CooCox
ARM compiler suite and with minor code cleanup, got it to
compile nicely. CooCox is a very well done Chinese development tool
based on gcc and Eclipse IDE. It supports 9 manufacturer's ARM
chips, hundreds of chip versions, and many debugger choices. Truly
Circuit Cellar Article
In the spring of 2013, I contacted Circuit Cellar about publishing
an article for this project. I wrote it they accepted it and it will
appear as a two part article in the Jan and Feb 2014 issues.All of
the design files are available on the Circuit Cellar web site as
well as here. Let me know if you are interested in building one. I
am considering offering bare or assembled PC boards. Email me at