Using μDMA with the Tiva LaunchPad (ARM Cortex-M4) for Audio Output

I've figured out how to use DMA (direct memory access) on the Tiva LaunchPad (ARM Cortex-M4) microcontroller when using peripherals like an audio output DAC (digital to analog converter).

Tiva Launchpad, Logic Analyzer and DAC Annotated

The DMA controller on the Texas Instruments Tiva LaunchPad is known as "micro-DMA" and is abbreviated as "μDMA". Chapter 9 of the TM4C123G datasheet located here contains a large amount of detailed information concerning μDMA.

Utilizing the DMA controller frees up the CPU from having to do the transferring/receiving operations involved with sending/receiving data from a peripheral or local memory on the microprocessor. This saves precious CPU cycles that can be used for other processing like generating awesome sounding synth or drum tones.

You may recall from an earlier blog post I managed to figure out how to interface my TM4C123G microcontroller with a 16-bit audio DAC. The audio DAC chip I used is the MAXIM MAX541. A circuit diagram for how the MAX541 DAC and Tiva LaunchPad interface is shown below.

MAXIM MAX541 Circuit Diagram

In the earlier example I handled transferring data to the DAC manually (i.e. not using μDMA, but using the CPU to write sample values to the SPI register address assigned to the DAC). I've used my Embedded Artists LabTool to measure the time duration taken for transferring data for each of the two different methods (μDMA and non-μDMA).

Both examples use the same audio; a short snippet of 16 bit digital audio of piano playing recorded at a sample rate of 44.1 KHz. An audio-visual example of this can be seen on the earlier blog post here.

The non-μDMA code transfers a single 16-bit audio sample at a time. It does this 44,100 times per second - matching the audio's 44.1 KHz sample rate. The newer, μDMA code example periodically transfers audio samples into a 256 sample buffer that the μDMA controller uses.

The percentage of CPU time used to transfer samples not using μDMA came to 3.077%. The percentage of CPU time used to transfer samples using the μDMA controller came to 1.418%. Here's a screenshot example of the measurement application used with the LabTool when measuring the non-μDMA method (click to enlarge):

LabTool Measurement Non-DMA

...and a measurement example when using μDMA:

LabTool Measurement DMA

If you're interested in taking a look at the code, feel free to download it here. It's well commented with information from the datasheet as well as explanations from myself. I used TI's Code Composer Studio for development, building and debugging, but the code can be easily viewed with any text editor.

Any questions? Feel free to ask. I'll be happy to discuss.

Date: May 22nd, 2017 at 7:02pm
Author: Terence Darwen
Tags: Embedded, Tiva LaunchPad, TM4C123G, ARM-Cortex-M4, 16 Bit DAC, DMA, micro-DMA

Previous Next