Lab1: Audio-Tone Generation Using a Lookup Table with Harmony v2


After completing this lab, you will have an understanding of the fundamental elements, layout, and execution model of an MPLAB® Harmony project. You will also learn how to add features and functionality to your MPLAB Harmony project by using the MPLAB Harmony Configurator (MHC).


In this lab, you will create a simple MPLAB Harmony project from scratch. You will use the MHC to configure the CODEC on the PIC32 Multimedia Expansion Board II. The application streams an audio tone (stored in the form of a lookup table in memory) over the I²S interface which gets played on the audio CODEC. The lab demonstrates basic system initialization and polled state machine design.


Lab Source Files and Solutions:

If you haven't already downloaded all source files for the SD card audio player labs:
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, 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.


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

Part 1: Create project and configure the PIC32MZ

Part 2: Add Application Code

Step 1: Create an MPLAB Harmony project in the MPLAB X IDE

Step 2: With MHC, Select the Board Support Package

Step 3: With MHC, Verify Configuration Bits are correct

Step 4: Verify and Change Oscillator Settings

Step 5: With MHC, Verify I/O pins using the Graphical Pin Manager

Step 6: With MHC, Configure Audio CODEC AK4953, I²C driver and I²S driver

Step 7: Generate Harmony code and build project

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

Step 9: Review the application code

Step 10: Debug your new application


You should be able to hear a sine tone output through the headphone jack on the Multimedia Expansion Board II. If you did not configure the CODEC driver, I²S driver or REFCLOCK properly, you may not hear the audio at all or may hear distorted audio coming out with clicks and pops in the stream.


In this lab, 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 as such was produced statically and stored in the form of a lookup table in an array. The MHC was used to configure the hardware modules. The application was developed in a state-based implementation. In the application, audio buffer management was done by using the buffer queuing support provided by the CODEC driver.


In this lab, you have successfully developed a full-fledged MPLAB Harmony Application. This gives you a fair idea of how MPLAB Harmony eases application development. If you need to add an audio support to any of your existing applications, this lab can be used as a reference. This can also be a starting point for your applications which are audio intensive.

© 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.