The ability for an embedded system to play audio is becoming a fairly common feature. Audio provides great feedback to a user, but with so much high-fidelity audio available today, using beeps and chirps just no longer cuts it. Developers can certainly get decent audio out of a system using discrete components and a DAC, but audio codecs have become very inexpensive and provide developers with a wide range of features that would otherwise be time consuming and costly to implement. In today’s post, let’s examine a few tips for adding an audio codec to an embedded system.
Tip #1 – Use the Microcontroller as the Master Clock
Audio codecs are typically connected to a system through an I2S (Inter-IC Sound) interface. Many audio codecs provide developers with flexibility for how the clock is generated for the audio codec though. For example, the clock source can be generated by the microcontroller through the I2S bus or by an oscillator connected to the codec. The codec itself can act as a master clock source and send the clock to the microcontroller. However, if a developer wants to minimize bill-of-material (BOM) costs, the simplest method is to set the microcontroller as the master and generate the clock for the codec. This minimizes cost and component count and simplifies the audio playback system.
Tip #2 – Use an External Audio Amplifier
Most audio codecs come with a built-in audio amplifier. These amplifiers can output typically anywhere from 0.5 to 1.5 watts although there are certainly exceptions. If the audio application is simple and does not require a lot of output, it is advantageous to leverage the internal amplifier to save again on BOM costs. However, in most applications that I’ve worked on, I’ve found that the internal amplifier doesn’t provide enough output power or flexibility for the application. For these reasons, I will often use an external audio amplifier that can be tuned for better performance with the speaker output system. In these applications, the audio codec is usually set to bypass the internal audio amplifier since they are typically expecting to drive a 4- or 8-ohm load. The line output is then used to drive the external audio amplifier.
Tip #3 – Leverage the Audio Block to Tune the Speaker
My favorite piece of an audio codec is the digital block that is often included. This digital audio block allows a developer to carefully tune their audio playback system for their application. For example, a typical audio block may contain several programmable low pass and high pass filters along with a multipoint equalizer. These programmable components allow a developer to carefully tune their output system to maximize audio quality while minimizing the number of external components that are needed in the system. How these components are programmed with depend upon the frequency characteristics of the speaker that is used in the end application and the type of audio that will be used such as instrumental music versus human speech.
Tip #4 – Store the Codec Configuration in a Table
The configuration for the audio codec is often transmitted over an I2C bus while the digital audio stream is transmitted over the I2S interface. Most audio codecs have several dozen registers that need to be configured to get the codec to behave the way the application needs it to. A great way to store this configuration information is to save a configuration table in EEPROM or flash and then load that table into RAM during the system initialization. A user can then modify the RAM values if needed to tune the system performance such as adjusting the current volume. The initial configuration can be sent over I2C during initialization prior to enabling the audio playback system. Then individual register updates can be provided as needed.
Tip #5 – Add Spare Capacitor Footprints to the PCB
One problem that I have seen repeated several times in audio applications (and motor applications) is that the capacitance requirements are often underestimated. Capacitance is important because there will be times when the speaker needs to pull a “large” amount of instantaneous energy and capacitor act as that energy reservoir. Too little capacitance and the speaker may not move as it needs to and therefore create audio defects that can be quite audible to the ear. The only way to make sure there is enough is to take measurements running the system. No one wants to waste a PCB spin though to make sure that there is enough, so a good practice is to set the capacitance as you expect it to be but add a few extra parallel footprints in case you need to tune the amount of capacitance needed.
Conclusions
High fidelity audio is becoming a requirement for many systems since it provides users with audible feedback that can be useful for them understanding the state of the system. Audio codecs can seem intimidating the first time that a team works with them. The fact though is that they are not nearly as bad as they may appear from a first glance through a datasheet. Today we reviewed a few tips for adding an audio codec to your system.