Multi-Zone Stereo Page
STM32 Design Contest Entry
The Blog for this project

I have 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:
My original system was built in the mid 90's, and is based on a Motorola 68hc11 processor and surplus graphics LCD driven by a custom FPGA. The CPU board had separate RAM and 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 amplifiers collected over the years.

The new system should do all that plus:
Other features I want someday:
3/26/11
I already had the basic code and LCD working when the boards arrived. I spent one crazy 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. 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 loaded.

For the contest design entry and a video demonstration, check out http://www.stm32challenge.com/detail/379 This is the proof of concept stage. I was selected for the finals, and the judging is in early May. Lots more board stuffing and coding to do.

4/15/11
The full schematics, software, bill of materials, etc. can now be found on the project link above.  This is the updated video for Phase 3 on Youtube.  http://www.youtube.com/watch?v=5vdvAfCXLkM Or click <play> below.

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 attached, the 128x64 LCD, and the 32 button keypad board.

system photo

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 audio crosstalk but none has been heard.

Crosspoint board

4/20/2011
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.

Phase 3 system

5/8/2011
I'm happy to say the project won an honorable mention, a 3-way tie for second.  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 under $100, and would have gotten 3 bare boards.

Blog for this project

6/17/2011
LM3886 Amplifiers
The prototype is back from the ST design contest, and the next step is to build / 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:
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 connect.

4 Channel LM3886 Amplfier

The back side showing four LM3886's, ready for thermal compound and to be mounted to a heat sink.

Rear view
This is what 12 channels of amplification will look like. At this density a fan is needed. The speaker connectors will protrude from the rear panel (not shown).

Side View LM3886 Amp


Multi-Channel Amplifiers Require Ground Trick
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, 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.
Schematic
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 use 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 overdesigned. The only time anything gets hot is when I am in in the test lab heating up 8 ohm 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 bug. I had planned to tightly pack these amplifiers, and 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 (60V x 50mA) each amp uses 3W when it is powered. 8 amps draw 24W, 12 draw 36W. Not terrible, but 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 fix is to manually switch DC power to the amps only when they are being used. In my house, the most commonly used zones (living room, den and 2 bedrooms) all have their own external amplifiers. The other 4 zones that use these amps (Deck, Basement, Kitchen...) are less commonly used. For now there will be a simple front panel switch or two to switch DC power to the amplifiers for those zones. Maybe add relays or FETs in the future. 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 enclosuer. A Visio drawing below shows that this is possible in a 2U 19" rack (17" x 3.5") x 12" deep enclosure. The advantages of a single case for both preamp and amps are:
The disadvantages:
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 beaus that is what I need, and also to save power.

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.

case
6/29/11
Getting there.
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 working well!
Installed

Final

7/25/11
Installed and 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 are getting quite warm. The chassis consists only of a bottom and front panel.

The quick-and-dirty original 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 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 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 control. 

I addressed the control code. All controls now use a consistent data structure for debounce 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 the 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 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.
Sure 4x100W

10/25/11
Web page???
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:
  1. Use a STM32 processor with ethernet (STM32F107 processor plus an external PHY and magjack)
  2. Use a Wiznet like W5100 (SPI to 100BaseT) chip or module
  3. Use a Serial to Ethernet device. XPORT looks good
  4. Use an external CPU with a proper web server and serial. Embedded Linux or a PC
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 haven't seen a cheap STM32 board with ethernet yet.

2. could use a Wiznet SPI to Ethernet module such as WIZ810 or WIZ811($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 withWiznet's is its HTML code is pretty rudimentary and after that I'm on my own. Like I say, I'm no networking guru.

3. Lantronix XPORT is $45 and is packaged in a very small extended-length RJ45 connector. It comes with HTML, FTP, Telnet, TCP, Email, decent download tools, and is pretty easy to use. It even has a Java runtime engine (JRE) so you can install java code to build GUIs and applications. I have a couple of these and am learning Java.

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. Linux needs too much memory for M3, requiring large chunks of SDRAM and flash, I think. Up to now an embedded Linux board was about $100 but there are sub $40 boards on the horizon. Raspberry Pi claims impressive specs and capability at a $25 price tag, but is still alpha-ware.


The Blog for this project

Back to STM32 Page
128 x 64 LCD Page
  Dave's Home Page
BoatBus and AVR Projects

Last Updated: 2/18/2012