Lab1: Audio-Tone Generation Using a Lookup Table


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 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 I2S 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

Because we regularly update our tools, occasionally you may discover an issue while using newer versions. If you suspect that to be the case, we recommend that you double check using the same versions that the project was tested with.

Archived versions of our tools can be found on the following Microchip websites:
MPLAB Harmony (see "Archived Downloads" tab)
MPLAB X IDE and XC32 Compiler (see "Downloads Archive" tab)
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 (BSP)

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, I2C driver and I2S 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, I2S 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-bit, at a 48000 sampling rate. The tone as such was produced statically and stored in the form of a lookup table in an array. MHC (MPLAB Harmony Composer) 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 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.

© 2016 Microchip Technology, Inc.
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.