USB Audio Speaker Tutorial: Step 1

Step 1.1: Create an MPLAB® Harmony Project

1

Create a folder under the Harmony installation to place this lab. Navigate to
<Harmony-Installation-Path>/apps and create the folder structure,training/middleware.

Extract theZIP file you downloaded to thetraining/middleware/ folder. A description of the files and folders found in this ZIP file can be found on the"MPLAB Harmony v2 USB Audio Speaker Tutorial" page.

2

Navigate to<Harmony-Installation-Path>/apps/training/middleware and create the folder structure,dev/usb_speaker. The lab will be developed in thedev/usb_speaker folder. MPLAB X IDE will create theusb_speaker_lab sub-folder insidedev/usb_speaker.

3

Start MPLAB X IDE and create a new project by selectingFile > New Project.

4

In theCategories pane of theNew Project dialog, selectMicrochip Embedded.

5

In theProjects pane, select32-bit MPLAB Harmony Project, and then clickNext.

image_3.png

6

Specify the following in theNew Project dialog (see below):
• Harmony Path:<Harmony Install Path>
• Project Location:
<Harmony Install Path>/apps/training/middleware/dev/usb_speaker
• Enter Project Name: "usb_speaker_lab"
• Configuration Name: "pic32mz_ef_sk_meb2" (this is optional)
• Target Device:PIC32MZ2048EFH144

image_4.png

7

After clicking theFinish button, the project will be created and opened. You will see the MPLAB Harmony Configurator (MHC) window along with the integrated Harmony Help file.

If you close the MHC window, you can re-open it by clicking onTools > Embedded > MPLAB Harmony Configurator.

Step 1.2: Select the Board Support Package (BSP)

1

Click on theOptions tab in theMPLAB® Harmony Configurator main window to select and configure the Harmony Framework in a graphical tree-based format.

2

Expand theBSP Configuration tree, and then selectPIC32MZ EF Starter Kit w\ Multimedia Expansion Board (MEB) II

step2_1.PNG

If a Board Support Package (BSP) exists for your development board you will want to use it. Choosing a BSP lets the MPLAB Harmony Configurator (MHC) know about the hardware you will use for the project.

By selecting a BSP, MHC can automatically control the following settings for you:

  • PIC32 core configuration (Watchdog Timer and debugger channel)
  • PIC32 oscillator configuration (including external clock/crystal)
  • PIC32 I/O Port pin connections to LEDs and switches

In addition to configuring hardware options for you, the BSP comes with a small group of library functions that allow you to more easily interface with LEDs and switches. In this lab, you will observe the selections the BSP makes for you. This will show you how to make these selections manually in case a BSP does not exist for the board you want to use.

Step 1.3: Verify Configuration Bits are Correct

1

In the central window under theMPLAB Harmony Configurator tab, click on theOptions sub-tab, to view the MPLAB Harmony & Application Configuration tree selections.

2

Expand theDevice & Project Configuration tree then expand thePIC32MZ2048EFH144 Device Configuration.

The BSP you selected has properly configured these selections for you. This step shows you how to make changes to these selections if needed.

  • DEVCFG3 and DEVCFG2 – No change
  • DEVCFG1 – No change, but verify the Watchdog Timer Enable (FWDTEN) is OFF
  • DEVCFG0 – No change

In case you are wondering where these cryptic selection names come from, they correspond with the PIC32 core configuration registers and bit names. Please see the device datasheet for details.

step3_1.PNG
step3_2.PNG

Before moving to the next step, you may want to collapse theDevice & Project Configuration tree.

Step 1.4: Verify and Change Oscillator Settings

Select theClock Diagram tab to display theClock Configurator window.

1

Verify the following clock parameters:

  • POSCMOD set toEC
  • FNOSC set toSPLL
  • FPLLIDIV set toDIV_3
  • FPLLMULT set toMUL_50
  • FPLLODIV set toDIV_2
step4_1.PNG

Experiment with other clock settings. Did you notice how some selections producered values? These indicate a bad clock configuration. If you mouse over them, a pop-up window will tell you what the problem is.

The PIC32 is connected to a 24 MHz external clock input. You are not using the internal PIC32 oscillator.

When you change the configured clocks away from the default values on the graphical interface, they are reflected as a shaded field in the Options Configuration Bits. Since the BSP selected the default values, there should be no shading. To illustrate this, notice when the FPLL DIV is changed to a Divide By 1 instead of 3 in the CLOCK DIAGRAM graphical interface, the Options tab will reflect the changes in DEVCFG1 with Shading. You can configure the clocks using the tree selections, but it is much easier to do graphically!

step4_2.PNG
step4_3.PNG

The BSP has already configured the Phase Locked Loop (PLL) using the selections for the PIC32MZ EF Starter kit \w Multimedia Expansion Board II. For custom boards without a BSP, you can use the PLL’s Auto Calculate feature to determine and set the PLL to multiply and divide values (FPLLIDIV, FPLLMULT, and FPLLODIV). You can see how this works by going back to the Clock Configurator window (Clock Diagram tab).

2

Change the PIC32 clock frequency to 198 MHz.

This development board can run at a maximum frequency of 200 MHz (selected by default by the BSP). You are using the audio CODEC on the board, so you need to configure the system frequency to 198 MHz. The reason for this specific frequency is described in the "Configure Audio CODEC" step.

  • In the MHC Clock Diagram tab, find the System PLL block and selectAuto Calculate
  • Change the Desired System Frequency from200 MHz to198 MHz.
  • SelectApply

Verify the output to the PLL is now set to 198 MHz.

step4_4.PNG

Step 1.5: Use the Graphical Pin Manager to Verify I/O Pins

1

Open the Graphical Pin Manager by clicking on thePin Diagram tab.

step5_1.PNG

2

Verify the BSP (selected in a previous step above) has properly configured the PIC32 pins based on the external devices connected to them. You will be using the Audio CODEC AK4953, LCD Display, LEDs, and Switches. Select thePin Table tab in the MHC output pane (see the following screenshot).

step5_2.PNG

If this window is minimized, it can be found on the bottom left part of the MPLAB X IDE. Click on it to maximize it.

step5_3.PNG
  • Notice that PINs 43, 44, 45, 67, and 84 have LED_n selected on them.
step5_4.PNG
  • Notice that PINs 59, 60, 61, and 22 have Switch_n selected on them.
step5_5.PNG
  • Notice that the PIN 46 has Power down enable/disable for the CODEC AK4953 selected on it.
step5_6.PNG
  • Notice that the PINs 26, 35, 39, 57, 117, and 133 are selected to interface with the Graphics LCD.
step5_7.PNG
step5_8.PNG


Next Step >