Which embedded system software codec or hardware solution is best for your application?

Jacob Beningo

May 4, 2021

5 Min Read
AdobeStock_187437231.jpeg
Adobe Stock

The capability of an embedded system to play audio is becoming a fairly common feature in today’s devices. 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 undoubtedly get decent audio out of a system using discrete components and a digital-to-analog-converter (DAC). Still, 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. 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. For example, the clock source can be generated by the microcontroller through the I2S bus or by an oscillator connected to the codec. Conversely, 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.

Related:Basics of the Python Programming Environment

Tip #2 – Use an external audio amplifier

Most audio codecs come with a built-in audio amplifier. These amplifiers typically output 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 power, it is advantageous to leverage the internal amplifier to save 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 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 typically expect 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 tune their audio playback system for their application carefully. 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 needed in the system. How these components are programmed depends on the speaker frequency characteristics used in the end application and the type of audio used, such as instrumental music versus human speech.

Related:5 Tips to Improve C Code Readability and Robustness

Tip #4 – Store the codec configuration in a table

The audio codec configuration 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 memory and then load it 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 before 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. Since the capacitor acts as an energy reservoir, too little capacitance may not drive the speaker enough thus creating audio defects that can be quite audible. The only way to make sure there is enough is to take measurements while the system is running. No one wants to waste a PCB iteration to ensure that there is enough capacitance. 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 adjust the amount of capacitance required. 

Conclusions

High fidelity audio is becoming a requirement for many systems since it provides users with audible feedback about the system. Audio codecs can seem intimidating the first time that a team works with them. But 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.

Jacob Beningo is an embedded software consultant who currently works with clients in more than a dozen countries to dramatically transform their businesses by improving product quality, cost and time to market. He has published more than 200 articles on embedded software development techniques, is a sought-after speaker and technical trainer, and holds three degrees, including a Master of Engineering from the University of Michigan. Feel free to contact him at [email protected] at his website www.beningo.com, and sign-up for his monthly Embedded Bytes Newsletter.

About the Author(s)

Jacob Beningo

Jacob Beningo is an embedded software consultant who currently works with clients in more than a dozen countries to dramatically transform their businesses by improving product quality, cost and time to market. He has published more than 300 articles on embedded software development techniques, has published several books, is a sought-after speaker and technical trainer and holds three degrees which include a Masters of Engineering from the University of Michigan.

Sign up for the Design News Daily newsletter.

You May Also Like