Lab 1: Audio-Tone Generation Using a Lookup Table With MPLAB® Harmony v3
Purpose
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 MPLAB Harmony Configurator (MHC).
Overview
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 I²S interface which gets played on the audio codec. The lab demonstrates basic system initialization and polled state machine design.
App_Tasks()
PP_TONE_LOOKUP_TABLE_Tasks()
Reference Materials
Download the lab source files and solutions for the SD card audio player labs.
Procedure
All steps must be completed before you will be ready to build, download, and run the application.
Part 1: Create a Project and Configure the PIC32MZ
- Step 1: Create an MPLAB Harmony Project in MPLAB X IDE
- Step 2: Using MHC, Select the Board Support Package (BSP)
- Step 3: Using MHC, Verify Configuration Bits are Correct
- Step 4: Using MHC, Verify and Change Oscillator Settings
- Step 5: With MHC, Verify I/O Pins Using the Graphical Pin Manager
- Step 6: Using MHC, Configure the Audio Codec AK4953, I²C Driver, and I²S Driver
- Step 7: Generate Harmony Code and Build Project
Part 2: Add Application Code
- Step 8: Include Application-specific Source Files and Add Required Code
- Step 9: Review the Application Code
- Step 10: Debug Your New Application
Results
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.
Analysis
In this lab, you have successfully played a sine tone on the PIC32 microcontroller and heard the audio through the headphone jack 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. 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.
Conclusions
In this lab, you have successfully developed a full-fledged MPLAB Harmony Application. This gives you a fair idea of how MPLAB Harmony helps 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.