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.
b
Create a New MPLAB Harmony Project
- In the MPLAB X IDE, select File > New Project
(or click in the toolbar). - Select the Microchip Embedded category if it is not already selected.
- From the Projects list, select MPLAB Harmony Project.
- 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.
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.
- Set the Harmony installation path.
- Set the project location.
- Enter the project name you would like to use.
- Change the project configuration name or just use default (optional).
- Select the target device from the drop-down window (Which PIC32 is on my board?).
- Click Finish.
After you click Finish, your new project will be opened.
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
1
Open the MPLAB Harmony Configurator by clicking:
Tools ▶ Embedded ▶ MPLAB® Harmony Configurator
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
1
Click on the MPLAB Harmony Clock Configuration tab.
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.
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.
- Enter the external clock frequency.
- Select the primary oscillator with PLL module (PRIPLL) to drive the system clock (SYSCLK).
- Click Auto-Calculate.
- Enter the desired System Clock frequency.
- Click Apply.
4 Use MHC to create a Static Timer Driver
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.
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
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
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.
PIC32 Pin | Configuration | chipKIT WF32 Function |
---|---|---|
RA0 | Output | LED3 |
6 Generate the Project Code
Click on the MPLAB Harmony Configurator Options tab, then click the Generate button.
Click the Save and Generate buttons on the following windows.
7 Complete the ISR Function
Service the Interrupt Service Routine (ISR) and toggle the LED.
8 Add Code to Start Timer Driver Instance 0
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.