MPLAB® Harmony v2 Timer Static Driver Project Using chipKIT® WF32 (step-by-step)

Step-by-Step Instructions

These step-by-step instructions were used to create a project in which timer1 is set up with a static driver and set to toggle LED3 at a 1/2 second period. The target hardware is the chipKIT® WF32 development board from Digilent® Inc.

1 Create a new MPLAB Harmony Project

a

Install the MPLAB® Harmony Configurator (MHC)

Before you create a new MPLAB® Harmony project, you must install the MPLAB Harmony Configurator (MHC) graphical user interface. This GUI enables easy addition and configuration of the Harmony library files needed for your application. It also allows MPLAB X IDE to create a new MPLAB Harmony project.

Instructions for installing the MHC plugin

b

Create a New MPLAB Harmony Project

  1. In the MPLAB X IDE, select File > New Project
    (or click Main_New_Project.png in the toolbar).
  2. Select the Microchip Embedded category if it is not already selected.
  3. From the Projects list, select MPLAB Harmony Project.
  4. Click Next >.

If you do not see MPLAB Harmony Project option, you have not installed the MHC. Click here for instructions on installing the MHC plugin.

new_proj_1.png

The next window should have the default Harmony Path, Project Location, and Project Path already selected for you. Remember the MPLAB Harmony framework expects to find specific files in specific locations. Do not change these default paths because the project may not build.

  1. Set the Harmony installation path.
  2. Set the project location.
  3. Enter the project name you would like to use.
  4. Change the project configuration name or just use default (optional).
  5. Select the target device from the drop-down window (Which PIC32 is on my board?).
  6. Click Finish.
name_location.png

After you click Finish, your new project will be opened.

new_proj_3.png
 
MPLAB® Harmony Project Wizard Details
Learn more >

Before creating an MPLAB Harmony Project, the MHC plugin must be installed into the MPLAB X IDE. Click here for instructions on how to install the MHC plugin.

This video will show you how to create an MPLAB Harmony Project in the MPLAB X IDE. For details on how an MPLAB Harmony Project differs from a typical standalone project, click here.

2 Use MPLAB Harmony Configurator (MHC) to configure the PIC32 core

open_mhc.png

1

Open the MPLAB Harmony Configurator by clicking:
Tools ▶ Embedded ▶ MPLAB® Harmony Configurator

core_config.png

2

Expand the Device and Project Configuration and PIC32… Device Configuration menus to see the Device Configuration Register menus.

Expand the DEVCFG1 register menu and change the setting as shown in this graphic.


DEVCFG1:
Watchdog Timer Enable:
FWDTEN = OFF

3 Use MHC to configure the PIC32 Clocks

clock_tab.png

1

Click on the MPLAB Harmony Clock Configuration tab.

clock_config.png

2

Modify the clock configuration as shown:


System PLL Input Divider:
FPLLIDIV = DIV_2
System PLL Multiplier:
FPLLMULT = MUL_20
System PLL Output Clock Divider:
FPLLODIV = DIV_1



Primary Oscillator Configuration:
POSCMOD = XT
Secondary Oscillator Enable:
FSOSCEN = OFF
Oscillator Selection Bits:
FNOSC = PRIPLL
Peripheral Bus Divider Selection Bits:
FPBDIV = DIV_1


See the "PIC32MX Oscillator" page for more detail on the PIC32MX oscillator system.

auto_calc2.png
auto_calc.png

Here's a tip: The System PLL can be automatically configured to generate a specific output frequency.
In this example we are using an external 8MHz crystal oscillator to drive the PIC32.

  1. Enter the external clock frequency.
  2. Select the primary oscillator with PLL module (PRIPLL) to drive the system clock (SYSCLK).
  3. Click Auto-Calculate.
  4. Enter the desired System Clock frequency.
  5. Click Apply.

4 Use MHC to create a Static Timer Driver

timer1.png

Expand the Harmony Framework Configuration ▶ Drivers ▶ Timer menus to see the Timer Driver selections.

Configure the Timer Driver as shown in this graphic.

Note we have configured this Timer Driver to use Timer2 (TMR_ID_2) in 32 bit mode.

timer2.png



We want to configure this timer to generate an interrupt every 1/2 second. To do this, we have calculated the Timer Period to be 156,250.

A note on the hardware:
When Timer2 (16 bit native timer) is in 32 bit mode, it steals the extra bits it needs from Timer3. This combined 32 bit timer is configured using the Timer2 configuration registers. When Timer2 generates an interrupt in 32 bit mode, the interrupt source comes from Timer3.

5 Configure the I/O pin connected to the LED to be an output

pin_tab.png

1

Click on the MPLAB Harmony Pin Diagram and MPLAB Harmony Pin Table tabs.


The pin table can be sorted by pin number or port pin name. Right click anywhere in the pin table and select: view ▶ pins or
view ▶ ports.

2

flag1.png

Click on the Flags button to open the Pin Flags window. Click on the buttons in this window to configure the PIC32 I/O Port pins per the table below.

flag2.png
PIC32 Pin Configuration chipKIT WF32
Function
RA0 Output LED3

6 Generate the Project Code

generate1.png

Click on the MPLAB Harmony Configurator Options tab, then click the Generate button.

generate2.png

Click the Save and Generate buttons on the following windows.

7 Complete the ISR Function

system_int.c.png

Click here to copy this code

Service the Interrupt Service Routine (ISR) and toggle the LED.

8 Add Code to Start Timer Driver Instance 0

app.c.png

Start Timer Driver instance '0'. You used MHC to select Timer2 (in 32-bit mode) to drive this driver instance.

9 Build, program and run your project

Click the Run icon to build, program, and run your project. See the "Build a Project For Release" page for more details.

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