SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By angelsix
#116573
Simple idea for my home - what I have is several input audio sources (stereo phono leads) that go to my sound system that accepts just a single stereo phono. At the moment I have to keep swapping the wires over. What I want is an automated switch.

Only one sound source should be active at any one time (and even if there are more it doesn't really matter) so it should automatically pick the first active input it finds and send it to the output.

One additional little thing I would like is a remote volume control as my system doesn't offer that either.

The Idea
=================================
What I presume I can do is have a voltage level detection circuit for each input to determine if a line is active or not. I could do this with a uC or an actual voltage detector to fire a high to the uC on detection removing the need for ADC of the uC, but adding cost to the project. I presume the line inputs are 0-1V amplitude so I should look for say 0.3V or higher assuming that if the level remains lower than that for 10 seconds that the line is not active.

Presuming that would be a viable solution I would use an analogue switch to effectively pass the active line straight back out to the output line. Again any suggestions on better approaches are welcome.

With the auto-switching done, I would like to add a sort of volume control to the output. I can sort out the IR remote or wireless no problem, so it is just left as how to attenuate the output via the uC or similar to create a volume change. Not really sure where to start with this?
#116582
angelsix,

I suggest you start by searching the SparkFun catalog and fora for:
  • (audio or analog) and (multiplexer or mux)
  • (mux or multiplexer)
  • amplifier
  • audio
  • volume control

If you don't find what you need (but I did take a quick look and believe that the functions you described could be obtained with SparkFun parts), search elsewhere for the same things.

Happy Hunting,
Eric
#116589
Yeah, this sounds like it can take care of the multiplexing task. I don't know how the sound comes out though, like if the amount of distortion defeats the purpose. 2 digital lines of a microcontroller select which of the 4 sources wil be connected to the output.

http://www.sparkfun.com/products/8970

I don't know how to solve the volume control though. You would need some kind of variable gain amplifier.
#116655
Thanks for the replies. Yes I figure an analog mux would be the way to go so will read up on the datasheets of the SF ones and find a similar one for my use.

I presume the only thing that matters is to pass enough current (think line level audio is far less than 100mA?) so most will do, and low on resistance. Is there anything else to look out for when passing line audio through a mux?

Regarding the volume control, I think it is going to be more complex and costly than it is worth, it was just a nice to have feature as my amplifier doesnt have a remote, but for now I will ignore that and just get the switching done.
By esklar81
#116686
angelsix,

According to its datasheet, this is a 4-channel multiplexer. How about switching Rsignal, Rground, Lsignal, and Lground as your four channels. The question occurs to me, though: Do you need to switch the signal grounds, or could you just tie all of them together?

Ironically, SparkFun appears to offer several audio devices that accept digital volume control, but they are not straightforward amplifiers. One could, I suppose, replace the volume potentiometers on an amplifier with digital potentiometers. Alternatively, you could set out on a search for an amplifier that accepts digital volume control. There are quite a few of them out there, with prices in the ~$2-20 range.

Eric
#116749
Eric,

The way I read that datasheet is you have many inputs, but ultimately onto 2 outputs. I need 4 outputs if I need to switch the grounds too (which I would like to do to be on the safe side).

I have found another mux that seems better for my needs which is a CD74HC4052, which has 4 dual inputs and 2 outputs, instead of more inputs that would be unused as well as this one being a much better cost.

So with that mux I use one per channel (4 left inputs and grounds on one chip, and the right side on the other).
I then tie the Select0, Select1, and Disable pins together, send the 4 left inputs to 4 ADCs of the PIC through a 10k resistor, and all 4 inputs and grounds for both left and right connect up to the 2 mux respectively.

That way I am using the PICs ADCs to scan the 4 left inputs for activity, and switch the 2 chips accordingly, so the outputs will have 4 switched lines (left and gnd, right and gnd) creating hopefully a seemless pass-thru.

I have the parts due today and hopefully will test over the weekend and let you know how I go on.

Thanks for all the advice so far.
#116754
angelsix,

Well, I'm :oops: & :? !

The embarrassment comes from my thinking that what I recommended was a quad, 4-channel mux when it's a dual, 4-channel mux.

The confusion comes from your saying
angelsix wrote:I have found another mux that seems better for my needs which is a CD74HC4052, which has 4 dual inputs and 2 outputs, instead of more inputs that would be unused as well as this one being a much better cost.
because that appears to be the same device as the one I recommended. (It appears that the industry part-naming convention is to use "dual" or "quad" to indicate the number of circuits on a chip and "x:1" or "x channel" to designate the number of inputs from which once can select.

I also don't understand your comment about "wasted" inputs. Among how many different sources do you need to switch? (I, for a reason I can't recall, thought it was 3 or 4.)

All that said, your description of how you plan to use them sounds reasonable to me.

One last thought: It appears that the SparkFun part I recommended is in a DIP, but the one you ordered is in a TSSOP. The DIP is intended for through-hole soldering and is compatible with both breadboards and sockets; the TSSOP is intended for surface-mount soldering. Although surface-mount devices are, usually, preferable for volume production, the flexibility of DIP lends itself well to experimentation and prototyping.

Good luck this weekend,

Eric
#116935
Eric,

Yes sorry for any confusion - basically I need 4 sound inputs and 1 output, which means (from my original assumption of needing to switch the grounds too) that I would need 2 channels per signal, and 2 signals per input (left and right) so for each stereo input I would need 4 switches, meaning to switch 4 inputs I would need 16 channels in total, but in groups of 4, resulting in the chip I mentioned needing 2 of itself to give a left set of 4 high inputs and 4 ground inputs to one high input and one ground output, and the same for the right.

I have a DIP of the package also, but ordered the TSSOP ready for a prototype board not breadboard once it works.


Test 1
============
OK, onto my findings - first test was to check if the switch worked as expected and switched sounds when enables and the Select channel was set to the right input - as expected it worked fine.

Test 2
============
Presuming the rest was simple and I am fairly confident in the operation of it I etched a board to do the entire job. This included 4 LEDs for indication, a button switch for testing, a PIC24FJ64GA104, and 2 analog switches, along with the audio connectors, power regs etc...

Board built, PIC programmed, I first checked the obvious like the LEDs work, the push button works etc... Checked all connections too and they were fine.

Puzzle 1
============
The 2 mux have their DISABLE and SELECT lines tied together so the PIC can switch them. However - I later have discovered I believe the way the mux must work for this it just doesnt' work - only one mux ever seems to be working as the mux that is further away on the board doesn't ever output sound as far as I can tell. Can anyone shed any light on why this might be, and how to solve this (not needed now though as I discover later).

Puzzle 2 - Solved
============
The next thing I discovered, which is sort of good is that all of the inputs and outputs grounds and the board ground all need to be commoned - else the ADC doesn't work, and I suspect it may be causing some other issues. I am a little concerned about commoning grounds though due to different sound inputs potentially having different power supplies, would this be an issue?

Puzzle 3
============
What I did to test the inputs were active and working I read each line in (left channel) to an ADC of the PIC through a 10k resistor then read out the readings on the 4 LEDs as a sort of level output. The first thing I needed to do which was a little puzzling is to make the pins TRIS as inputs as well as configuring the ADC channels and CFG (even though it states not to make the pins digital inputs). Without doing this they don't read in. Anyway, the main thing with this is that AN3 always reads high, when nothing is connected, when something is connected, and when on battery power. I suspect this is because this is on a programming pin PGEC1, so to solve this I intend to move it off this pin to another general purpose pin. However again it would be nice to have some insight on this.

Puzzle 4
============
Finally, the output of the mux works very strangely - if the ADC inputs (the left channel inputs) are set to digital outputs, then the forth input channel is enabled when the SELECT of the mux is set to channel 1, 2 and 3, but not when on 4... so it is behaving in reverse. If they are set to inputs then channel 4 works exactly as expected. However, no other channels work at all. Again I suspect most of this is caused by the fact the 2 mux lines are tied together so I will make up another board and this time only need the one mux anyway because the first 4 inputs (X) can be the 4 left high inputs with common grounds, and the other 4 (Y) can be the right channel, then I will report what I find.
#116936
[EDIT] Sorry, I didn't notice the messages in the rest of the thread, adressing this.
esklar81 wrote:angelsix,

According to its datasheet, this is a 4-channel multiplexer. How about switching Rsignal, Rground, Lsignal, and Lground as your four channels. The question occurs to me, though: Do you need to switch the signal grounds, or could you just tie all of them together?
It selects 1 out of 4 sources and connects it to the single (bidirectional) destination, but in a dual configuration using the same selector pins. So at best, with one chip he can connect Rsignal and Lsignal from one of 4 sources to his amplifier, assuming a common ground is used that does not pass through the multiplexer. (I don't know if that could cause problems, I'm not much into audio) But if he uses 2 chips he can of course also channel through the respective grounds based on the same selector inputs.
Last edited by Valen on Sun Jan 09, 2011 7:09 am, edited 1 time in total.
#116942
Valen wrote:
angelsix wrote:...

Puzzle 4
============
Finally, the output of the mux works very strangely - if the ADC inputs (the left channel inputs) are set to digital outputs, ...
What good will that do?
Not sure I get what your asking. Firstly the ADC of the PIC doesnt work if the pins are set to digital outputs (which is what you usually do for analog inputs), and instead only works if set to digital inputs. Then the reading from the ADC gives the correct results. However, by doing that the behaviour of the mux is different. I haven't bothered doing much more investigation into this part yet as I think this odd behaviour is to do with the tying together of the mux chips, so I will see what problems remain if any when I remake it with one.
#117018
angelsix wrote:
Valen wrote:
angelsix wrote:...

Puzzle 4
============
Finally, the output of the mux works very strangely - if the ADC inputs (the left channel inputs) are set to digital outputs, ...
What good will that do?
Not sure I get what your asking. Firstly the ADC of the PIC doesnt work if the pins are set to digital outputs (which is what you usually do for analog inputs), and instead only works if set to digital inputs. Then the reading from the ADC gives the correct results. However, by doing that the behaviour of the mux is different. I haven't bothered doing much more investigation into this part yet as I think this odd behaviour is to do with the tying together of the mux chips, so I will see what problems remain if any when I remake it with one.
Perhaps it is because I don't know the specifics about how a PIC's pins are configured (I have sofar only worked with AVR atmega8). To me it sounds logical if you use a pin as analog input you also set it as digital input (or just high impedance). Setting it as (digital) output in either high or low state would force the ADC result accordingly. To me it explains the current behaviour.
#117191
Ok all working just fine now. Here is what I have discovered over the short project.

1. MUST use common ground for ADC to work (unless I wanted to add another switch to send each pins ground to the voltage reference pin of the ADC). So for now everything seems happy with a common ground, tested from a PS3, TV, Set-top, and MP3 player, all have no problems.

2. Not 100% sure if these MUX can have their Select/Disable pins tied, as last board is identical to this one but with one mux as I have removed the second mux due to common ground reducing the number of required pins.

3. LEDs are cool - outputting the sound input to the LEDs as a bargraph while it is playing and the LEDs are all different looks cool, makes me want to make a mood light that is controlled via a sound input that just passes through so can still be sent to original device.

4. PIC24FJs seem to have the inverse setup for ADC configuration and need their digitals set as inputs to work for ADC else nothing works, yet the datasheet clearly states they should not be because of excess current draw, and all other PICs I have used have their digitals set as outputs:

10.2 Configuring Analog Port Pins
The AD1PCFGL and TRIS registers control the operation
of the A/D port pins. Setting a port pin as an analog
input also requires that the corresponding TRIS bit be
set. If the TRIS bit is cleared (output), the digital output
level (VOH or VOL) will be converted.
When reading the PORT register, all pins configured as
analog input channels will read as cleared (a low level).
Pins configured as digital inputs will not convert an
analog input. Analog levels on any pin that is defined as
a digital input (including the ANx pins) may cause the
input buffer to consume current that exceeds the
device specifications.

Certainly strange behaviour I would like some clarity on.


Anyway, there are the findings if others have any issues with an audio switch. All in all it was a short and sweet project working brilliantly for my needs, with an added IR receiver to mute the sound channels, and some other little options I have added.

As always thanks for the feedback guys.