audio output to headphones or active speakers

I am about to implement a software synth/sequencer - and I have an audio signal output from an analog pin (generated via PWM).

...what I want to end up with (on the user interface) is basically a 3.5 mm audio-jack socket enabling the user to connect either "headphones" or "active speakers".

My question is - How do I approach this?

Do I need some sort of amplifier circuit between the arduino-output-pin and the external device - or is it sufficient with a current limiting resistor. I have tried to search the web and found different stuff. But I need some fundamental guidance here :) ... so can anyone give me some basic input about this "subject" links or "keywords" are fine. I just need something to go with...

Thanks in advance!

There are two issues, PWM filtering and impedance matching. To fix first one, you need a filter, for example passive RLC, as shown here: http://interface.khm.de/index.php/lab/interfaces-advanced/arduino-realtime-audio-processing/

Second issue: Arduino could drive 200-250 Ohm safely, Active speakers have about 50 kOhm inputs, Headphones 16-32 Ohm. As you can see, its safe to drive speakers, but not headphones. You need an amplifier, specifically design for this purpose, or you may use headphones output of the active speakers, I think most of them have one.

An important point is PWM frequency - to generate audio bandwidth signals using PWM you'll need to set a high PWM freq, much higher than the audio, which means reprogramming the timer or timers involved to an ultrasonic frequency - for instance setting the prescale to divide-by-1 would give PWM at 62.5kHz.

Couple this with a low-pass filter with a roll-off at about 10kHz and you'd get a reasonable signal. boost the output with an opamp or an audio amp like the LM386 for more power.

There are techniques for getting a lot better than 8-bit resolution out of this 8-bit PWM by using sigma-delta and noise-shaping methods, so the quality can be improved.

thanks for input!

How do I know which kind of opamp to use? Would this be ok -> http://www.dx.com/p/jtron-njm4558d-jrc4558d-low-noise-dual-op-amp-circuit-black-100-pcs-289715

See this topic http://forum.arduino.cc/index.php?topic=179761.0 Nothing is needed to drive the "active" i.e. selfpowered speakers, such as might be found in a desktop computer system. What is needed is something to bring the output level down from 0-5V to the +/- 1V (line level) range so the output is not distorted. A simple capacitor and resistor divider will do.

For headphones, some kind of power driver is needed, such as http://tangentsoft.net/audio/cmoy/ Follow the links and look at the parts used.

thanks. How did you figure out that the output level is in the range +1v to -1v ? ... I have wondered about that part... what it was supposed to be

Just one of those things I picked up playing with audio circuits over the years.

http://en.wikipedia.org/wiki/Line_level

I have tried to take your inputs into account. And this is what I came up with: http://tinypic.com/r/vr31c4/8

The basic flow is Arduino (PWM 0 to 5v) -> Buffer -> RC-filter -> DC-Bias -> audio out

I am not sure about the values of the rc-filter yet. But I have seen a few places where they recommend samplerate/2 as cutoff-frequency (1/(2pi*r*c)).

The idea is that the Buffer would supply the needed current. The rc-filter would smooth out the signal and the dc-bias would keep the output within -1v to 1v.

Does the schematics make sense? do I miss something?

I'm not sure why you are using a linear buffer on a digital signal.

100 to 220uF for the output coupling cap would be sufficient. The bigger values really come into play for amps driving speakers. For line level, not as critical in my experience.

Where it's line level output to an amplifier input, the op amp is not even needed. For driving headphones, some amplification will be needed.

ok. here is my updated schematics.

I have chosen values for the rc-filter ending up with fc = 8kHz (my sample rate will be 16kHz). My PWM frequence will be 62,5kHz. I still have the voltage divider after the ac-coupling to keep the output in the +/- 1V range which seems to be the standard.

now the order is: arduino_out → rc-filter → buffer → ac-couple + dc-bias

after simulating in partsim.com I realized that the voltage divider in the end did not work as I thought. Should be like this…

schematic_v3.jpg

Yes, the last 2 resistors setup for bias, as labelled, were good. The last 2 setup to cut the signal in half and then remove DC via the 100uF cap will give you AC centered at 0V.

180pF, 180nF, not much filtering going on there I suspect. http://sim.okawa-denshi.jp/en/CRtool.php

oh, yes! 180nF (will give 1/(2*pi*110*180nF) = 8kHz).

thanks.

...hmm. I think I need a buffer between the voltage divider and the ac-coupling in order to supply the current if headphones (low ohm's) are connected to the output.

I just saw a youtube video explaining the issue when connecting a 50 ohm motor to a voltage divider - ending up with a too low voltage (about 5% of max) at the output.

Hi @sharepointme,

I'm wanting to do the same thing as you described in your old post here (send simple Arduino PWM audio output to externally powered computer speakers via a line level signal).

Did you have success going to externally powered speakers?

I'm a total neophyte in the analog circuit world; thus it would be awesome if you had specs on components you ended up concluding were necessary.

Also, while headphones aren't a critical need for my application, would be interested to know what additional components would be necessary (if any) to prevent damage to the Arduino if headphones were connected instead of an externally powered speaker.

Happy to be redirected to other discussions of this topic, but searching this topic here and on the web hasn't seemed to turn up newbie-comprehendible solutions.

Thanks in advance!