Can we drive headphones from the DAC+on board Op-Amp?

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
jon2000
Posts: 3
Joined: Tue Aug 12, 2014 4:32 pm

Can we drive headphones from the DAC+on board Op-Amp?

Post by jon2000 » Tue Aug 12, 2014 4:50 pm

Has anyone tried to do this? I think it should be possible, although not sure what (if any) passives may be required - DC decoupling caps??

blmorris
Posts: 348
Joined: Fri May 02, 2014 3:43 pm
Location: Massachusetts, USA

Re: Can we drive headphones from the DAC+on board Op-Amp?

Post by blmorris » Tue Aug 12, 2014 8:39 pm

Probably not very well, though I haven't tried it. The problem is that there isn't really an 'on board Op-Amp' on the pyboard; the closest thing is the DAC output buffer implemented in the STM32F405 processor itself. This output buffer can be turned on or off; with the buffer on you can drive lower impedance loads with the tradeoff that you lose about 0.2V at the top and bottom of the output range. With the output buffer off, you can get closer to the 3.3V range on the output, but only if you are driving a relatively high impedance load (>1.5MegOhms, according to Table 74, Section 5.3.24 of the data sheet, DM00037051.pdf) I assume that micro python uses the DAC with the output buffer on.
The data sheet says that with the output buffer on you can accurately drive a load down to ~5kOhms. Most headphones will have a much lower impedance than this, anywhere from 16 Ohms up to a few hundred Ohms. (A typical speaker will have an impedance in the 4-8 Ohm range.) Even an average Op-Amp will have trouble driving loads much less than 1k, specialized headphone amplifier chips exist which fill the space between the typical Op-Amp and power amplifier chips to drive larger (lower impedance, higher voltage / current) loads. I can look up a few that I have used if you are interested.

Edit- this may not be accurate if you are using the AMP skin, as I assume that has an amplifier built into it.

jon2000
Posts: 3
Joined: Tue Aug 12, 2014 4:32 pm

Re: Can we drive headphones from the DAC+on board Op-Amp?

Post by jon2000 » Wed Aug 13, 2014 10:22 am

Thanks for the comprehensive reply. If you can recommend a small footprint (smaller the better) stereo op-amp that I could power from the microUSB, requiring minimal external passives and that you think would give fair quality through some headphones that would be really helpful :)

I'm interested in playing around with the DACs to create some dual channel sound effects.

blmorris
Posts: 348
Joined: Fri May 02, 2014 3:43 pm
Location: Massachusetts, USA

Re: Can we drive headphones from the DAC+on board Op-Amp?

Post by blmorris » Wed Aug 13, 2014 3:34 pm

Small, minimal external passives, let me see… how about TI's TPA6130A2? http://www.ti.com/lit/ds/symlink/tpa6130a2.pdf
Two size choices: 4x4mm 20 pin QFN or 2x2mm 16 ball BGA packages, integrated charge pump to provide a negative supply so the output is referenced to ground, I2C control for programmable gain and shutoff, only 8 external capacitors required (I use 0603 but I'm sure that 0402 could be used if you were inclined.) I have a circuit using this part which I fit into 10x13mm of board space without trying too hard… but then, my day job is designing audio boards using SMT components; I'm not sure this is exactly what you are looking for. ;)
More seriously, I should note that the audio output from a pair of 12-bit DAC's may be passable for your purposes, but it will be nowhere near 'high-fidelity' without a few tricks- I have an idea which involves interpolation to produce an 8x or 16x oversampled signal and adding in some low-amplitude, high-frequency 'dithering' noise to simulate a higher resolution output - this is standard stuff for commercial audio CODEC's - but I don't want to give the impression that I am anywhere near implementing such a trick in Micro Python.
If you are comfortable with an 8-pin SOIC (1.27mm pin pitch) or the even smaller MSOP (0.65mm pitch with integrated solderable thermal pad) I could recommend the TPA6111A2. http://www.ti.com/lit/ds/symlink/tpa6111a2.pdf It is stereo, behaves like a fairly typical Op-Amp, rated for operation from 2.5-5.5V so it can be run on USB power. My only warning is that in my experience the power supply noise rejection wasn't quite satisfactory for my purposes, but then I was using a fairly noisy switching power supply.
Finally, I should point out that the conventional way to get high quality audio from an STM32F405 would be to drive an audio DAC or CODEC through the I2S bus; but this is not yet supported in Micro Python. I am (sort of) working on it - probably the only one really interested at this point, as I am hoping to use Micro Python to control my amplifiers - but the usual caveats about engineers writing code apply here - basically, don't hold your breath ;)

PinkInk
Posts: 65
Joined: Tue Mar 11, 2014 3:42 pm

Re: Can we drive headphones from the DAC+on board Op-Amp?

Post by PinkInk » Fri Aug 15, 2014 3:59 am

You can drive headphones or a piezo speaker directly from the dac's ... but the output is *almost* inaudible, ok for testing, no good for anything finished.

jon2000
Posts: 3
Joined: Tue Aug 12, 2014 4:32 pm

Re: Can we drive headphones from the DAC+on board Op-Amp?

Post by jon2000 » Fri Aug 15, 2014 10:13 am

Again, thanks for such a good reply. I have done some looking around and agree that the Ti part looks good :) I will let you know how I get on with it! Thanks...

jorjun
Posts: 4
Joined: Fri Sep 12, 2014 1:15 pm

Re: Can we drive headphones from the DAC+on board Op-Amp?

Post by jorjun » Fri Sep 12, 2014 5:10 pm

PinkInk wrote:You can drive headphones or a piezo speaker directly from the dac's ... but the output is *almost* inaudible, ok for testing, no good for anything finished.
I'm finding exactly that: have optimized the code below so that (I think) there is minimal delay between buffer outputs. But the audio quality is still very buzzy & broken-up. (Using a smaller buzzer/speaker).
Note: (Not actually reading from wav formatted file, it's extracted 8 bit, 1 channel audio data only)

Would love to know if I can improve audio quality somehow.

Code: Select all

def play_wav(filename, chunksize=3096, freq=44100):
    dac = DAC(1)
    delay_ms = int(chunksize / (freq / 1000000))
    micros = pyb.Timer(2, prescaler=83, period=0x3fffffff)
    start = time.time()
    with open(filename, "rb") as wav:
        chunk = wav.read(chunksize)
        buf = bytearray(chunk)
        while chunk:
            dac.write_timed(buf, freq, mode=DAC.NORMAL)
            micros.counter(0)
            chunk = wav.read(chunksize)
            buf = bytearray(chunk)
            while micros.counter() < delay_ms:
                pyb.wfi()

PinkInk
Posts: 65
Joined: Tue Mar 11, 2014 3:42 pm

Re: Can we drive headphones from the DAC+on board Op-Amp?

Post by PinkInk » Sat Sep 13, 2014 2:17 am

I wrote a simple module to read and write wav files as arrays whilst I was playing with this feature, I'll try and find it again and post it here.

gercha2
Posts: 6
Joined: Sun Jan 15, 2017 5:19 am

Re: Can we drive headphones from the DAC+on board Op-Amp?

Post by gercha2 » Thu Apr 13, 2017 10:23 pm

Hello everyone!
I have an similar issue. I am testing DAC in my pyboard v1.1 and I used the basic configuration shown in: https://docs.micropython.org/en/latest/ ... b.DAC.html. this is

Code: Select all

DAC.write_timed(data, freq, *, mode=DAC.NORMAL)
as

Code: Select all

dac1 = DAC(1)
dac1.write_timed(buf1, pyb.Timer(6, freq=100000), mode=DAC.NORMAL)
I checked the STM32F405 reference manual: RM0090 and I found what is the register which handle with enable and disable the DAC output buffer. Honestly, I don't know how to configure it directly in micropython using the code DAC configuration above mentioned. Also, I am not sure if BOFF1 from DAC_CR register is enable by default when I use DAC.write_timed(). I was looking for in https://github.com/micropython/micropyt ... mhal/dac.c, but this is not clear for me in my basic understanding. Can anybody help with this?

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Can we drive headphones from the DAC+on board Op-Amp?

Post by pythoncoder » Fri Apr 14, 2017 9:31 am

If you're intending to play music I think there is a problem. The write_timed function outputs a buffer, but when that buffer becomes empty you need to re-fill it and call write_timed again. This process takes time and will introduce a glitch into the sound. So I think that this approach is likely only to work well for very short bursts of sound.

Some time ago @blmorris did some serious work on implementing I2S which would have produced a true hi-fi solution. It showed great promise but alas he never completed the project. See viewtopic.php?f=2&t=2422&p=14118&hilit=I2S#p14118.
Peter Hinch
Index to my micropython libraries.

Post Reply