In this installment of the Smart Analog Combo application series, I would like to discuss the realization of low-cost audio playback using the digital-to-analog converter (DAC) in Smart Analog Combo in MSP430FR2355 microcontroller (MCU).
Some situations may need simple audio playback for sound cues or alarms. In most cases, adding an extra external audio chip for this simple function only adds cost and complexity. It’s much more reasonable to use MCU on-chip peripherals.
Designers generally use one of two approaches to obtain simple audio playback: pulse width modulation (PWM) or a digital-to-analog converter (DAC). Both methods convert a series of digital sound data into an analog electrical signal at a sound sample frequency, which drives a loudspeaker through an audio amplifier to produce sound.
The DAC generates an analog output that is proportional to the digital input it receives. The output voltage of the DAC keeps a constant value at every period, shown in Figure 1. The performance of a DAC is mainly determined by its resolution and settling time.
Figure 1: DAC output waveform
The PWM is a popular technique to implement DAC functionality in MCUs that don’t have an integrated DAC module. The PWM DAC approach is not new, but performance limitations have historically confined its use to low-resolution, low-bandwidth applications. PWM commonly generates a series of pulses with a period equal to a signal sample period and a duty cycle equal to a digital signal value using an MCU timer module. After going through a low-pass filter, the output analog voltage is proportional to the pulse duty-cycle shown in Figure 2. Because of the limitation of low-pass filter, the PWM output signal has intrinsic ripple which can’t be eliminated compared to DAC.
Figure 2: PWM DAC implementation
The PWM DAC resolution depends on the harmonic ripple generated by the low-pass filter and the duty-cycle resolution. Therefore, PWM duty-cycle resolution directly represents the DAC resolution. Equation 1 expresses the relationship between the frequency of the timer clock source used as a timer tick to increase the timer counter and the PWM signal frequency :
where N is the duty-cycle resolution of the PWM DAC in bits.
Equation 1 shows that higher resolutions need a higher timer clock source frequency, which will reach MCU clock limitations and increase power consumption.
You can now make several conclusions about the advantages and weaknesses of the PWM and DAC methods:
PWM audio playback is easy to implement using an MCU without an on-chip DAC.
The waveform generated by the DAC is smoother than PWM, which has intrinsic ripple.
For the PWM method, higher resolution needs a higher timer clock frequency, which increases power consumption.
The PWM method needs an extra low-pass filter.
It’s possible to configure one of the four Smart Analog Combos in the MSP430FR2355 to DAC buffer mode and implement audio playback functionality.
Figure 3 shows the block diagram of an audio application using a Smart Analog Combo DAC configuration. There are two steps to implementing audio playback: the download stage and the playback stage. In the download stage, you need a computer program to parse audio files and pass the 8-/16-bit data to the MCU through a universal asynchronous receiver transmitter (UART) for storage in external flash memory. In the playback stage, the MCU reads the raw audio data from external flash memory and the DAC converts it to an analog sound wave at an audio sample frequency. Audio files are usually recorded and played at 22.05 kHz or 44.1 kHz.
Figure 3: Audio application using the MSP430 Smart Analog Combo
The main format used on Microsoft Windows systems for raw and typically uncompressed audio bit stream storage is the .wav format. It is an application of the Resource Interchange File Format (RIFF) bit stream format method for storing data in “chunks.” The usual bit stream encoding is in linear pulse-code modulation (LPCM) format.
Figure 4 shows the storage structure of a .wav format file, which includes raw audio data and sample information such as sample rate, number of channels and bits per sample.
Figure 4: .wav file format structure
Figure 5 illustrates the configuration of the Smart Analog Combo when implementing an audio application using the MSP430FR2355 MCU. The Smart Analog Combo is configured in DAC buffer mode. An extra timer is necessary in order to trigger the DAC data update at an audio sample rate. After updating the DAC data register, the MCU with ACLK as the timer clock source can enter LPM3 mode to save power consumption. The MCU can only enter LPM0 mode if you’re using the PWM method because the timer module is using SMCLK as a clock source. The power consumption in LPM0 is significantly higher than LPM3.
Figure 5: Smart Analog Combo DAC mode
For more details about how to configure Smart Analog Combo in your design, see the application report, “How to Use the Smart Analog Combo in MSP430™ MCUs.”
Evaluate the MSP430FR2355 LaunchPad™ development kit.
Check out the Voice Band Audio Playback Using a PWM DAC reference design.
Read the application report, “PWM DAC Using MSP430 High-Resolution Timer.”
Read the white paper, “Smart Analog Combo Enables Tomorrow’s MCU-Based Sensing and Measurement Applications.”
All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.
TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs andembedded processors, along with software, tools and the industry’s largest sales/support staff.