«

»

USB Audio Multiplexer

On my desktop PC I have a speakers and a headphones. Usually I use headphones, but when I need to switch to speakers I need to physically plug in speakers instead of headphones to my PC’s soundcard. I wanted to solve this problem for a long time, but never get around of that until recently I saw this posted on Hackaday.

And so I’ve decided to build my own really simple audio multiplexer.

Features

  • 1 Input, 2 Outputs (or the other way around)
  • Built upon FT232R (has drivers for Windows, MacOS and Linux)
  • Easy to control from any serial terminal program
  • Consumes only about 15mA
  • Completely isolated analog ground
  • Standard 3.5mm audio connectors

So, basically it’s a low-power USB-controlled relay which used to switch audio signals.

When you connect it to the PC, OS detects it like a virtual serial port (COMx in Windows, /dev/ttyUSBx in Linux).

Then you can use any serial terminal program to connect to that virtual serial port and control it using three single-character commands.

Here I’ve used Terminal v1.9b – free serial terminal for windows to control my audio mux.

The supported commands are:

  • a – switch to channel A
  • b – switch to channel B
  • t – toggle between channels

As you can see after each command it responds with channel that currently active.
For example, if you would send “b” command, it will respond with “CH B” after channel is switched to B.
If it will recieve any other command then those three, it will respond with “Unknown”.

Design

As you can see, the “audio” ground completely isolated from “digital” ground. And I’m using top copper layer as a shield for both, audio and digital ground. This helps to isolate audio part from picking up noise from digital circuitry and other EMI.

The schematic of this USB Audio Multiplexer is pretty straight-forward.
USB<—>FT232R<—>ATtiny13A<—>Relay

So, I just will point out some design aspects of it.

  1. Relay connected not straight to MCU pin, but it is connected through R3 and C2. It’s made for lowering relay power consumption from 28mA to about 12mA. I wrote about this trick in my article: Using Relays (Tips & Tricks). This might be helpful when this device is connected through usb-hub full of devices, when even ~15mA can make a difference. But it is not necessary implement this.
  2. Pin PB3 of MCU connected to CBUS3 pin of FT232R with 10k pull-up resistor, which can be used for power saving functions, or it can be used for providing clock to ATmega13A. You can change functions of CBUS pins of FT232R using FT_Prog software which you can download from FTDI website www.ftdichip.com
  3. Ferrite bead FB1 after USB port is needed to reduce EMI noise that comes from FT232R. You can read more about this in FT232R datasheet.

At first I wanted to make single-sided board, but eventually I’ve end up with double-sided one. Because of that the USB connector stayed on the bottom of the board and audio connectors on the top. But if you want you can easily change that fact.

If you can’t find the exact relay I’ve used in this design, you can use any DPDT (2 Form C) 5VDC signal relay which not exeeds ATtiny13 maximum pin current.

And for different relay you might need to change R3 and C2 values (if you don’t care about saving a couple of dozen of milliamps, just put jumper in there).

MCU Choice and Firmware

For this simple task I was looking for cheap microcontoller(preferably from Atmel of Microchip) with minimal number of pins and with hardware UART. But the smallest and cheapest thing I found was the PIC16F688T from Microchip.

Well, I guess 14 pins is too much for this task, so I’ve ended up using ATtiny13A, which, btw I had in my junk box. I just decided to write software UART for this micro. To do that I’ve used AVR304 app-note from Atmel “Half Duplex Interrupt Driven Software UART”. I’ve used 8-bit timer and one external interrupt to do that, but for this simple task it’s actually is overkill. It is possible to use only a small fraction of memory to implement software UART without using external interrupts and timers. Anyways, if you want you can still do that.

Before flashing the firmware as-is, you need to change fuses to get 4.8MHz internal oscillator frequency.

Issues

The only issue I had with this device was ATtiny13 internal RC oscillator calibration. UART protocol is very sensitive to changes in oscillator frequency. ATtiny13 internal oscillator is calibrated under 3V and 25 degrees C, but in this Audio Multiplexer it’s powered straight from USB port 5V, and because of that it can even not work after you will flash the firmware. You might need to tweak number of timer cycles in firmware (read comments in code, there’s only two values at the beginning of the program).

To conquer that you might try to configure CBUS3 pin of FT232R as a clock source for ATtiny13, hoping that FT232R internal RC oscillator is more precise than ATtiny’s oscillator. Or put external crystal for FT232R and still use CBUS3 as ATtiny13 clock source – that would’ve been the ideal solution. I maybe will compare FT232R internal oscillator frequency stability against ATtiny13A internal oscillator. Maybe. If you’ll try to do that before me, it would be interesting to know what the result is.

Files

28 comments

6 pings

  1. Simon says:

    This board is done with toner tranfer? You got an impressive precision!

    1. admin says:

      Yes, I’ve done it with toner transfer. It’s actually not that hard to do that. You just need a little bit of practice and a good paper. That’s all there is to it.

      - Phil

  2. FxDev says:

    I think MCP2200 is better and cheaper than FT232.
    More importantly if you use MCP2200, you dont need to use any other microcontroller. You can use its dll to drive IO pins.

    Just an idea ;)

    1. admin says:

      Thank you! I completely forgot about MCP2200. I guess, because I never used it in my projects. It’s like 2 times cheaper than FT232R, which is awesome!
      I was going to use FT232R in bitbang mode, to get rid of the microcontroller. But MCP2200 beats it hands down!

      I’m definitely gonna use it! :)

      - Phil

      1. Kenneth Finnegan says:

        I believe the FT232R also has controllable I/O pins.

        The FT232R also doesn’t run on an internal RC oscillator, but actually has a quartz crystal integrated into the package, where the MCP2200 does not and requires an external 12MHz crystal and other components, which is why the FT232R is more expensive.

  3. Martin D. says:

    You maybe want to fix the link to this article: http://jumperone.com/2011/10/using-relays/, the link in this post currently refers to itself.

    1. admin says:

      Thanks, Martin!

      It’s fixed!

  4. Matthew says:

    How about using a latching relay?

    1. admin says:

      Unfortunately the local electronic stores didn’t have any latching relays in stock. But that would’ve been better, of course!

      1. Matthew says:

        Ah! That is a problem.
        Maybe for a future pcb redesign design?
        Excellent design nevertheless and very nicely constructed!!

        1. admin says:

          Yeah, maybe. This one was just a proof of concept.

  5. Dustin Dawes says:

    Would this relay work in the inverse way? 2 Inputs / 1 Output? Or would some wiring need to be changed for it?

    1. admin says:

      Sure it will! It works like a simple DPDT switch, but with usb control. No wiring needs to be changed.

  6. Mike says:

    suPutString(“Hey, WTF?\r\n”,11);

    :-)

    1. admin says:

      Well, it happens sometimes :-D
      The other day I found this line in someone else’s code:

      #define THE_BEER_IS_PLENTIFUL_AND_THE_PARTY_SWINGING TRUE

      Doesn’t do a thing, but gives the warm feeling :-)

  7. Alex Southwell says:

    My thought with this project is that it is a little messy a the back of your pc. With two cables going in (audio x2) and two coming out ( usb x1, audio x1) I don’t know how hard it would be to make a decent DAP for audio straight from usb, but you could just hack in a cheap usb sound card and make it usb in and two audio out. Just a thought, I’ve been wanting to play with networked and usb audio for ages but I don’t know anywhere near enough.

    1. admin says:

      There’s no point in that. On my PC I have a few sound card outputs, that I can switch between. But the problem is in software. In Linux I can do it no problems at all, but there’s other operating systems, like windows, MAC OS or Android, where all this could be much more complicated.

      And it is not so easy to hack some USB sound card to have two switchable outputs, because usually those USB sound cards are in fact off the shelf USB DACs with some amplification and filtering circuitry. And if that DAC has a second unused output or has some free GPIO pins, then it is possible, but how much effort it would take to do that? I mean, it’s not just hardware side, it’s also software.

  8. Jonathan says:

    That’s a beautiful board. Great work!

    It doesn’t actually matter whether the ATtiny’s oscillator is as accurate as the FTDI’s oscillator, as long as both of them are stable with respect to one another. If there is only one clock source in the system (the FTDI) and all other clocks (the ATtiny, both UARTs) are derived from it, this will be true by design.

    I’ve never been a big fan of USB-to-async translators and I believe their first-line status in the maker community is unfortunate. They force designers to deal with complexities they might not otherwise need to (e.g. assembling/disassembling streams and packets, worrying about UART bit rates, writing your own host software, finding your device in the list of serial ports) and close off many good options made available by participating natively in the USB ecosystem.

    In particular, USB HID gives you some clever, mostly software-free options. For example, most hosts maintain one caps-lock state per display. When the caps-lock state changes, the host driver broadcasts LED reports to all keyboards attached to the system. A device could monitor and time these reports, and e.g. toggle the relay when the user double-taps caps-lock in a particular cadence. The USBtiny stack could work well in that application and doesn’t need too much more hardware than you’ve already got.

    For heavier tasks requiring hardware USB, I recommend LUFA, a great open-source USB stack. LUFA includes examples for just about every standard device and host class which can be modified easily to suit your application.

  9. joe blake says:

    cool

  10. Nicholas says:

    Can someone tell me the name of the software to design schematics like the one in the article? Thank you

    1. admin says:

      Eagle CAD – very popular CAD software for making PCBs.

      You can download free version from their website:
      http://www.cadsoftusa.com/downloads/

      The free version is not limited by time. But it’s limited by board size – 100 x 80mm and number of layers – 2 layers (you can get all the details on their website).
      For hobby use it’s ideal!

      1. Nicholas says:

        Thank you very much!!!
        I’m trying to replicate a similar audio switch and this post is EXTREMELY useful to me.

        1. admin says:

          You’re welcome!
          Good luck with your project!

          - Phil

  11. Nicholas says:

    I take the opportunity to make 2 questions:
    1. I want to use a toggle switch instead of a relay.. should I use some bounce/current peak protection of some sort?
    2. Can I take directly the 5v of the USB to power my device?(and lower it down if necessary)
    thank you very much

  12. Reginald lorenzo says:

    …. are there any way to connect Flash drives ( USB, MEMORY cards) to my TV with out any USB port>>???? Can you help me with it… well ,,,, i was on to this because My player is a bit crazy…. so i think of this sort of connection…. :)

  13. Andy says:

    Where do you get the small square resistors? what are they called and how do i use them? are the same as traditional radioshack ones? i have been wanting to try them for various projects but dont know where to look. Thanks,
    -Andy

    1. JumperOne says:

      Those are SMD resistors. They come in different physical sizes: 1206 – the biggest one, then it goes down – 0805, 0603, 0402..

      You can buy them almost everywhere (except RadioShack :) )
      http://www.digikey.com
      http://www.mouser.com
      http://www.farnell.com
      etc…

      And check out Dave’s SMD soldering tutorial:
      http://www.youtube.com/watch?v=b9FC9fAlfQE

      Cheers!
      - Phil

  14. trikots ballett says:

    index.php?act=post

  1. Tiny audio switcher eliminates repetitive plug swapping - Hack a Day says:

    [...] remove the headset from his sound card in order to insert the speaker plug. He’s been meaning to rig something up to make it easier to switch outputs, but never seemed to get around to it until he recently saw [...]

  2. Tiny audio switcher eliminates repetitive plug swapping | ro-Stire says:

    [...] remove the headset from his sound card in order to insert the speaker plug. He’s been meaning to rig something up to make it easier to switch outputs, but never seemed to get around to it until he recently saw [...]

  3. Tiny audio switcher eliminates repetitive plug swapping » Geko Geek says:

    [...] remove the headset from his sound card in order to insert the speaker plug. He’s been meaning to rig something up to make it easier to switch outputs, but never seemed to get around to it until he recently saw [...]

  4. Tiny audio switcher eliminates repetitive plug swapping | CisforComputers says:

    [...] remove the headset from his sound card in order to insert the speaker plug. He’s been meaning to rig something up to make it easier to switch outputs, but never seemed to get around to it until he recently saw [...]

  5. Electronics-Lab.com Blog » Blog Archive » USB Audio Multiplexer says:

    [...] Audio Multiplexer – [Link] Tags: Audio, multiplexer, USB Filed in USB | 3 views No Comments [...]

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>