I'm trying to use a specific audio amplifier, TPA3111D1, to power a 10 watt speaker from a microcontroller. I would like to generate sound from a microcontroller that doesn't have a built in DAC, so I am looking for a good DAC that would work with this amplifier. The amplifier allows both differential or single audio source inputs and I'd like the DAC to work with 0 to 5V TTL inputs from 16 pins of the microcontroller.
I think 16 bit should be the appropriate size of the DAC but there are so many to choose from. If anyone has a good tutorial on using a DAC for audio generation from a microcontroller I'd love to see it. Can anyone suggest a DAC or at least narrow my search down a little bit? Thanks!
Answer
DACs have different requirements depending on the application. You'll find high precision solutions using expensive components to get good absolute precision, but in audio you don't need that. Linearity is the most important parameter.
Since you'll be using an ATmega2560 which comes in a 100-pin package you can probably spare 16 I/Os, and then I would choose for parallel I/O. You'll have less timing problems than when working with serial I/O like I2S.
edit
Will seems to favor I2S and he has a point on condition that you want to connect to other, (semi-)professional audio equipment. As I understand it your digital audio path is very local, restricted to the connection between your AVR and the DAC. And then I would stick with the parallel. For 44.1kHz sample rate choose a crystal that allows you to get an interrupt every 22.676\$\mu\$s. Use the interrupt to automatically latch the last sample into the DAC, and then you have lots of time to prepare your next sample. That's the only timing you're dependent on. With I2S on the other hand you'll have more things to do. You may use SPI to shift the data out, but in the middle of a word you'll have to toggle the word clock. Things you don't have to worry about with parallel I/O.
The simplest ADC is an R-2R resistor ladder. The linearity depends on the resistors' matching, and there lies the problem for a discrete solution. You would need rather expensive precision resistors. The integrated approach is much better. The AD5547 also uses an R-2R ladder network (see fig. 17 on page 12), so why is this better than discretes? Integrated resistors (and capacitors) may have some tolerance on their nominal value, but their mutual match is the best you can get. So the 80k\$\Omega\$ resistors may be 80.5k\$\Omega\$, but you're sure they're all that value, and that's more important than the actual value itself.
The AD5547 accepts a 5V power supply and is 16-bit parallel in.
The application schematic is from the datasheet, so look there if this isn't very readable.
The DAC is registered, which means you can use the latch to update several DACs simultaneously, but you can make it asynchronous and transparent too by making/WR low and LDAC high (see page 13). Then the output will be continuously updated. But this is only possible if all inputs are updated simultaneously! With an 8-bit microcontroller you will probably write to 2 I/O ports, and then you'll need the latch!
Like most DACs it's current output, so you need to convert it to voltage. In this application with the AD8628 they use a RRIO (Rail-to-Rail I/O) opamp whose specs match the required resolution, but you can use another opamp if you like.
The ADR03 is a precision voltage reference, low drift and such, which for an audio application is overkill. Just make sure that your voltage reference is ripple and noise free!
edit
David rightly comments that this is somewhat older technology, but I thought it is OK since you're using a microcontroller (in lieu of a DSP) and a less-than-perfect class-D amplifier anyway. I picked this for my answer also because it is easy to understand.
David also mentions sigma-delta DACs, which have indeed better performance, but their working principle is a bit more complex, and they're (almost?) without exception serially controlled, for which the AVR doesn't have the hardware.
No comments:
Post a Comment