Combining audio output with digital 0-5V output - Page 1
Forum section: electronics / beginners

author: Saimoun
author_rank: Frequent Contributor
timestamp: July 24, 2021, 08:33:58 am
content: HiHere is what I am trying to do: I have an audio output circuit, which works fine, but I would like to have the possibility (from an MCU) to change that output to a digital 0 to 5V signal, i.e. square'ish signals.My circuit idea is attached (LTSpice). V4 is basically a GPIO from my MCU (running at 3.3V), so I can turn on or off the digital output as I want.The problem is I clearly need to cut the circuit where the red circle is, otherwise I send +5V into my audio circuit (which has opamps powered by +3.3V), and the C5 cap prevents the signal from moving cleanly between 0V and 5V. The switch cannot be a physical switch.I could use an analog switch like this one -https://datasheet.lcsc.com/lcsc/1811021622_BL-Shanghai-Belling-BL1551_C82528.pdf- but then I need to power it using +5V which will be bad for the audio circuit (because my +5V rail has noise on it, the +3.3V does not).I am a bit out of ideasAm I going at all the right way? If so, how would you do it?Thank you!!

author: Saimoun
author_rank: Frequent Contributor
timestamp: July 24, 2021, 10:20:28 am
content: Just FYI for now I simply send the digital signal from the audio circuit - that works but cannot go very high (about 1.6V is the highest - makes sense with the coupling cap and the audio circuit being +3.3V powered).So maybe even being about to send a 0 to 3.3V signal would be a great improvement. I was thinking if there is a way to connect the MCU output (V4) directly to the output somehow? Thinking that the Audio is the direct output of an opamp and probably will not like loads under 10ohm or voltages outside of 0-3.3V.

author: magic
author_rank: Super Contributor
timestamp: July 24, 2021, 01:56:47 pm
content: Most MCUs have the ability to set their pins as high impedance inputs so a pin could be connected directly to the signal. Some 3-state buffer from any CMOS 74 series family could deliver the same with 5V output swing.Scrap that. ICs generally don't handle voltages below ground very well and the signal is AC coupled, apparently.It would help if you could shut down the audio source or at least make it output DC (for example, by grounding IN- of the final opamp). Otherwise, it will take some electronic analog switch to disconnect audio if relays are unacceptable. Alternatively, feed audio through a series resistor, but this may not be feasible depending on circumstances.

author: Saimoun
author_rank: Frequent Contributor
timestamp: July 24, 2021, 02:35:37 pm
content: Thank you for the reply magic!Yes the audio will be deactivated (it can be set to Vcc/2 fx) when the output is switched to digital.And yes I understand about the high impedance, that is fine. My worries are when the output is driven - that creates large voltages on the audio opamp and the DAC output, is that a problem?See my attempt attached

author: Saimoun
author_rank: Frequent Contributor
timestamp: July 24, 2021, 02:38:45 pm
content: Quote from: magic on July 24, 2021, 01:56:47 pmOh yea I did not think about that - in audio mode the MCU will receive negative voltages on the high impedance pin...

author: Zero999
author_rank: Super Contributor
timestamp: July 24, 2021, 03:14:17 pm
content: Quote from: simonlasnier on July 24, 2021, 02:38:45 pmThen bias the pin at half the supply, with a couple of resistors and connect it to the audio, via a capacitor.

author: Saimoun
author_rank: Frequent Contributor
timestamp: July 24, 2021, 03:38:46 pm
content: @Zero999: if I sent before the capacitor, I send 0 to 3.3V before the coupling cap, which will be -1.65V to 1.65V on the output (after the coupling cap) - and I can already do that with the DACBut ideally I need 0 to 3.3V, or even better 0 to 5V.

author: Terry Bites
author_rank: Super Contributor
timestamp: July 24, 2021, 07:23:18 pm
content: Get rid of impedance and dc bias problems with an opamp and a few bits..

author: magic
author_rank: Super Contributor
timestamp: July 24, 2021, 10:33:41 pm
content: I can't think of a suitable IC for that, unless there is a negative supply available like -2.5V.However, discrete transistors may work. In the example below:Q3 tolerates plenty of negative voltage just fine.Q4 tolerates -5V or so, because its base is pulled down by negative signals and base-emitter junction breaks down at some point.Q2 tolerates the negative voltage at Q4 base.The drive circuit (Q1,Q2) is built in such way that Q3 and Q4 can't turn on at the same time even if the MCU goes nuts and drives it wrong.Transistors like those are available in SOT23-6 duals, TO-92, whatever you like.Some additional clamp could protect Q4 from BE breakdown if long term reliability is a bigger concern than price. (Q3 also wouldn't enjoy voltages much higher than 10V). That being said, I'm not sure how much ESD and how many repetitions it would take to damage them to the point of unsuitability for such simple switching application. Possibly not a serious issue.

author: Saimoun
author_rank: Frequent Contributor
timestamp: July 25, 2021, 08:57:26 am
content: @Terry: I appreciate the help, but a bit confused - I already have an opamp (but in inverting config while yours is non-inverting, is that the main difference?), and then you removed the coupling cap after the opamp in your circuit, which is necessary to remove the Vcc/2 bias@magic: very interesting circuit! I do not think it solves the issue that it conflicts with the audio circuit though, as Q3 on will still send +5V to the audio circuit, i.e. the opamp output.The thing is it seems it is not realy possible to combine the audio and the digital output, so I went around the whole board and found a better connector to send the digital signal fromSo I leave the audio alone and avoid that problem.I am not very strong on transistors though and I will need help to do the actual switching. But it is outside the topic of this thread so I will create a new one. I will put your circuit there magic (because I do not quite understand it).

author: magic
author_rank: Super Contributor
timestamp: July 25, 2021, 04:17:22 pm
content: The opamp will not see 5V DC because it is AC coupled. It will, however, receive spikes on logic output transitions - those could be clamped with schottkys from OUT to 3.3V and GND.Using a different pin is of course better. 74HCT1G04/1G14 (inverting) or 1G125 (noninverting) could provide level translation to 5V.The circuit is relatively simple: IO1 and R1 provide a small base current to one of the output transistors (frankly, the resistors could be increased to limit output current further). Which transistor gets the current depends on whether IO2 is higher or lower than IO1 and which of Q1,Q2 is turned on. Nothing happens if both are equal. The rest of the design is (important) subtleties

author: Terry Bites
author_rank: Super Contributor
timestamp: July 26, 2021, 11:50:14 am
content: The opamp serves two funtions. Adding bias at half rail and separating the audio input impedance from the 4K7. The buffering also improves the switch behavour. High impedances tend to exagerate switching artefacts.Here's a minimal version. Dump the fet and the opamp and us a pair SPDT switches. I've modelled this and it works fine. You can use it on 3.3 or 5V systems. Control (CTRL) swtiches beween pulses and audio.The first switch performs the same funtion as your mosfet.I have assumed you are stuck with the 4k7 on the gpio.