Lab2: Audio-Tone Generation from a Text File Stored in an SD Card with Harmony v2

Purpose

After completing this lab, you will have an understanding of configuring and adding multiple modules (SD card driver, Serial Peripheral Interface (SPI) driver, and Files System Service) using the MPLAB® Harmony Configurator (MHC). You will also learn how to integrate these modules into the MPLAB Harmony project. This lab should really start to show you the power of Harmony!

Overview

This lab adds to the previous one. The audio_player_lab2 application reads an audio text file from the PIC32 Multimedia Expansion Board II SD card and streams it over the PIC32 I2S interface to the audio CODEC. The audio file is saved as a .txt file with comma-separated left and right channel audio data. The audio_player_lab2 application demonstrates the configuration and integration of the additional modules to audio_player_lab1 using the MHC, thereby extending its functionality.

The naming of functions and variables used in audio_player_lab1 has been changed from APP_TONE_LOOKUP_TABLE_ to APP_TONE_TEXTFILE_SDCARD_. Otherwise the basic application flow remains the same.

App_Tasks()
APP_Tasks.PNG
APP_TONE_TEXTFILE_SDCARD_Tasks()

APP_TONE_TEXTFILE_SDCARD_Tasks() adds four new states to the audio_player_lab1 state machine. These states are related to mounting the file system on the SD card, opening and reading the audio text file, and parsing the text file before the audio data is passed to the audio CODEC.

APP_TONE_TEXTFILE_SDCARD_Tasks.png
Click image to enlarge.

Lab Source Files and Solutions:

If you haven't already, download the lab source files and solutions.

This project has been verified to work with the following versions of software tools:

  • MPLAB X IDE v3.26,
  • MPLAB XC32 Compiler v1.40, and
  • MPLAB Harmony v1.08.


As the tools are regularly updated, there may be occasional issues while using newer versions. If that is the case, we recommend using the same version as specified in the project.

The archived versions of our tools can be found below:
MPLAB Harmony
MPLAB X IDE and XC32 Compiler

Note that multiple versions of all these tools can co-exist on the same computer.

Procedure:

This lab builds off the work you performed in the previous lab. If you did not perform SD card Audio Player Lab1, please start Lab2 using the Lab1 solution project (found under the firmware folder). Verify that it works as expected before continuing with this lab.

All steps must be completed before you will be ready to build, download, and run the application.

Lab Index

Step 1: Copy source files and rename project for Lab2

Step 2: With MHC, Configure the SD card driver, SPI driver, and File System

Step 3: Generate Harmony code and build project

Step 4: Include application specific source files and add required code

Step 5: Review the application code

Step 6: Debug your application

 Results

As with audio_player_lab1, you should be able to hear a sine tone output through the headphone jack on the Multimedia Expansion Board II. There could be issues with the audio output if you did not configure the SD card driver or File System Service properly (the audio data is read from the text file stored in the SD card).

 Analysis

You have successfully played a sine tone on the PIC32 microcontroller and heard the audio through the headphone on the development board. The sine tone produced is 16-bits, at a 48000 sampling rate. The tone was produced statically and stored in a text file on the SD card mounted on the board. The existing configuration from audio_player_lab1 was enhanced using the MHC to configure the SD card driver and File System Service to access the audio text file stored on the SD card. The application state machine was enhanced to add new steps to read audio data from the text file.

 Conclusions

In this lab, you have extended the audio_player_lab1 to add another level of complexity. Now you should be in a position to appreciate how easy it was to add new modules (driver/system service) to an existing application. This lab can also be used as a reference for dealing with File Systems and SD card memory management.

© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.