Lab 2: Audio-Tone Generation from a Text File Stored in an SD Card with MPLAB® Harmony v3

Last modified by Microchip on 2024/01/29 21:32

Warning: This tutorial uses the old Harmony configuration tool (MPLAB® Harmony Configurator (MHC)). New Harmony projects should use the MPLAB Code Configurator (MCC) instead.

 

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 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 (MEB II) SD card and streams it over the PIC32 I²S 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 MHC, thereby extending its functionality.

Note: 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 function

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 function

Back to Top

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 v5.25
  • MPLAB XC32 Compiler v2.30
  • MPLAB Harmony MHC v3.3.2
  • DEV_PACKS v3.5.0
  • CORE v3.5.0
  • CSP v3.5.0
  • BSP v3.5.0
  • AUDIO v3.4.0
  • USB v3.3.0

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:

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

Back to Top

Procedure

This lab builds off the work you performed in the previous lab. If you did not complete SD card Audio Player Lab 1, please start Lab 2 using the Lab 1 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

Back to Top

Results

As with audio_player_lab1, you should be able to hear a sine tone output through the headphone jack on the MEB 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).

Back to Top

Analysis

You have successfully played a sine tone on the PIC32 microcontroller and heard the audio through the headphones 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 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.

Back to Top

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.

Back to Top