Audio signal switching with a micro processor

Hey all.

I’m trying to build a ‘stereo’ with a raspberry pi. I need to switch audio sources, and would like the pi to control it.
I have a couple of HC4067’s. One each for left and right audio channels.
I have sources coming in from an I2S DAC and some 3.5mm jacks for ‘line in’ signals from radios/cd’s/ computers etc. These go straight to the HC4067 and out to the output jack.

I can switch the channels but I’m getting distortion. I suspect I have a problem with signal bias maybe.
The circuit is powered from 5v DC. Should I be doing any signal conditioning before it hits the 4067, or is that the wrong component in this situation ?

Not synth, but synth adjacent. I was hoping you guys might have a ‘go to’ chip or circuit for this sort of scenario.
Any pointers gratefully received.

1 Like

Have a search on the forum for mixer circuits, many of these can be adapted to a switched function rather than pan.

The datasheet says:

These analog multiplexers/demultiplexers control analog
voltages that may vary across the voltage supply range.

In other words, if the chip is powered with 0 to +5 V, then the analog signals it can handle are from 0 to +5 V. Very likely the signals you are putting into it are bipolar, plus and minus something (probably limited to about ±1.4 V). To handle these without distortion you would need to add a DC bias, at least 1.4 V and probably more like 2.5 V would be a good idea, resulting in a signal voltage range like 1.1–3.9 V which the 4067 can handle. You can do this with an op amp summing stage.

1 Like

Are you looking to deal with large quantities of inputs? There’s a couple of chips I’ve used that would probably be better (they’re designed for line-level audio) but you’d be limited to three stereo inputs.

PT2313 is used in cheap car stereos and, as well as giving you the individual input selection, you get bass/treble/loudness/volume controls with front and rear speaker outputs (not amplified, just what they’re intended for). The input selection is actually a separate block to the sound treatment so you could just use that if you wanted.

PT2258 is a six channel (3x2) volume control IC which I’ve used for a mixer in the past. Both of these chips use I2C to control them but you have four of these all connected thanks to the control address being able to be set. I’ve also used a PT2257, which is a two channel version of this in an 8-pin DIP, but you can’t change the control address so it’s rather limiting.

Both are readily available for peanuts from Aliexpress and the likes.

1 Like

I assumed something like that was my problem. So if my googling worked, an input stage like this should get me going : -

I did look at a chip that I think was from the PT series, can’t remember which one it was now, but it was in a package with odd pin spacing. It looked like 0.1" in the picture but was actually a smaller pitch when I got my hands on it. In the end I decided that it was too much trouble with the pin spacing so I moved on. Does look to be a handy unit though.
I have no fixed number of inputs currently, but would like at least 4 if not more. The 4067 gives me 16 which is a little excessive in this instance, but could come in handy one day :slight_smile:

Off topic, but are you using a TS jack for a stereo signal? Normally one would use a TRS jack, with left and right on tip and ring, and sleeve for ground.

With a 4051 analogue mux you can have +/- inputs if for example you power the chip with +/- 5V and ground to give you that swing, I use them in a filter to chose the outputs of filter poles with no clicks etc.

1 Like

No. Sorry. That was just a quick sketch up in KiCAD for the input stage. I am using a Tip and Ring jack in the real circuit. Not sure I have left and right on the correct pins. They may be reversed, but it’s not a problem currently. (That’s a gotcha for later. I’ll check that. Thanks :slight_smile: )
I just wanted to confirm I have understood the idea of the biasing. The 2 x 100k resistors (value chosen at random by me) splitting the supply voltage and giving me me an “audio ground” at 2.5 volts above the 4067’s ground so the audio signal has space to swing between +/- 2.5 volt’s either side of this “audio ground”.
That’s my understanding currently.

For this project I would like to stick to a standard 5 volt supply. I have an on board regulator which will supply both my circuit and the pi.

You might want a different op amp. TL07x can’t swing to the power rails and with only 0 to 5 V you may be pushing its range limits. Something like an MCP6002 rail to rail op amp might be preferable.

The op amp isn’t configured correctly. You need an input resistor (typically 100k) and an equal resistor in a feedback from pin 1 to pin 2.

If there’s a chance the input signal isn’t bipolar, it would be wise to have an AC coupling capacitor on the input. And there should be one on the final output.

1 Like

I’ve updated a bit. Currently using the MCP6002 as I don’t have a part symbol for the MCP5002 but it is rail to rail capable. I think this should be a bit closer to useful from your description of the circuit. After this stage I go into one input of the 4067, then out to an amp via another decoupling cap if I’m following along correctly.

The typical go-to local shop here lists the MCP6002 as rail-to-rail capable at a very affordable price, so that would have been my choice as well. The other available option I see locally is TLV2462, with better noise specs but 5x the price (but still, reasonable). So, by the looks of it, you can shop around according to your requirements and get this project done!

No, the input resistor goes from capacitor to pin 2. See .

You should be able to create a DC offset to your input signal by using 2 resistors (connect them from GND to +5 and connect them together at the other ends) and connect the center point via a capacitor to your input signal source on the one hand, and connect the center point directly to the input of the analog switch on the other hand. In this way you superimpose the AC of the input signal on the DC in the center point. This is how AC-coupling is frequently done in amplifier stages where you need a DC bias voltage for the next stage but only want the AC of the previous stage.

B.t.w. you can do fun things with analog switches and digital circuitry. Have a look here: PWM fader experiment

1 Like

Thanks very much for the info. Been a bit busy for a day or two so haven’t had a chance yet to do the reading, but i’ll get to it. I’ll order up an op-amp or two and get the bread board out :). I’ll update on progress in a while.

Again. Thanks for your guidance.

Bear in mind that some of these IC’s don’t like the input voltages going beyond the supply rails.

Protection Schottky diodes clamped to the supplies would prevent this problem. Unfortunately suitable ones are becoming hard to find except as surface-mount versions.

I’ve noticed some devices tend to have a large supply range.
If I chose a device with a larger supply range, say 16V supply capable, but run it on a 5v supply, would this exhibit problems with signals dropping below 0, or above the 5v supply ? Is it supply related or device spec related ?

Yes, if you power a device from 0-5v then regardless of what its capable of being powered from you will clip the signal outside these power supply limits

Take a look at the datasheets. Generally the absolute maximum input range is something like 0.5 volts beyond the supply rails. So in your example, -0.5 to +5.5 V. Beyond this the device might not operate correctly and could be damaged. The output swing also is limited to 0 to 5 V, but that’s just clipping, it’s not damaged by trying to exceed that.

It’s a little complicated because the - input pin isn’t at the input voltage — the voltage is dropped across the input resistor. The voltage on the - input pin is the same as that on the + pin, i.e. 2.5 V, as long as the op amp output isn’t at the rail. Once the output reaches 5 V the - pin voltage starts to go higher. Similarly it starts to go lower once the output reaches 0 V. So you can go a few volts outside the 0 to 5 V range on the input before the op amp input voltage is out of spec. About -5 V to +10 V.

As mentioned if there’s a possibility the input signal might go outside that range, it’s a good idea to protect the op amp with a pair of Schottky diodes from the - pin to the +5 and ground rails:

I’d use 1N5817, easily found as through hole.

But signals from “radios/cd’s/computers etc.” are very unlikely to be outside -5 to +10 V, so you can probably skip the diodes without worry.

1 Like

Oh yes, I would add protection diodes in parallell tot the resistors just in case the signal that passes through the capacitor onto the voltage divider makes the summed voltage go higher than the supply voltage or lower than GND. Given that it is an input signal from an ‘unknown’ source, you need to be careful.