MPLAB® Harmony v2 Ports Project Using chipKIT® WF32

 Objective

This example project detects a button press to enable and disable a blinking LED. A push-button switch on the evaluation board is connected to an I/O Port pin on the PIC32.

Two Timer System Service objects are used in this project. One creates a delay (100 ms) used to poll the I/O Port pin connected to the switch. The other creates a delay (50 ms) used to debounce the switch and blink the LED. The Timer System Service object used to poll the switch is always active. The Timer System Service object used to blink the LED and debounce the switch only exists when switch debouncing and LED blinking is needed. This provides an example of how a delay (and its corresponding resources) can be created and deleted during run time.

The code you will add to this example project (as described in the following steps) implements the state machine shown in the diagram below.

objective2.png

You may also be interested in another example project that shows how to blink LEDs at a constant rate:
Learn more here.

The "Project and Source Files" download (see below) contains a fully functional project. It can be used as an example and requires no modifications. To gain a deeper understanding of how to use the MPLAB® Harmony framework, we recommend you generate the project and source files yourself by following the step-by-step procedure below.

 Materials

Hardware Tools

Tool About Purchase
chipkit-wifire-50px.png
chipKIT™ WF32
Development Board
hwtool-50px.png
chipKIT®** PGM**
Programmer/Debugger

Software Tools

This project has been verified to work with the following versions of software tools:
MPLAB X IDE v3.25, MPLABXC32 Compiler v1.40, MPLAB Harmony v1.07.01

Note: 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.

Tool About Installers
Installation
Instructions
Windows Linux Mac OSX
MPLAB® X
Integrated Development Environment
MPLAB® XC32
C/C++ Compiler
MPLAB® Harmony 1.xx
Integrated Software Framework

Exercise Files

The contents of the following .zip file need to be placed in this directory. If this is not done, the MPLAB® X IDE will not be able to find all source files, and the project will not build successfully.

<Harmony install path>/apps/training
(example Harmony install path = c:/microchip/harmony/v1_07_01)

File Download
Installation
Instructions
Windows Linux Mac OSX
Project and Source Files

 Procedure

The "Project and Source Files" download provides a fully functional project. It can be used as an example and requires no modifications. The following steps below provide instruction on how this project was created.

1

Create a new MPLAB Harmony project

The Target Device used on the chipKIT® WF32 is the PIC32MX695F512.

2

Use the BSP to load appropriate default values for the PIC32 core, clocks, and I/O port pins.

3

Use MHC to enable and configure the Timer System Service

4

Use MHC to generate the code

5

Add application states and variables to your project in app.h.

6

Add application-specific configuration constants to the project in system_config.h.

7

Create the callback functions used by the Timer System Service.

8

Create the application initialization function.

9

Add application code to your project:

  • Create two delays using the Timer System Service (one 50 ms and one 100 ms).
  • Create a state machine to perform the following functions:
    • Debounce a switch press
    • Debounce a switch release
    • Blink the LED
    • Enable and disable the blinking LED

10

Connect the development board and programmer/debugger to your computer, then select the XC32 compiler version and programmer/debugger for the project

11

Build, program and run your project

Click the Run icon Main_Run_Project.png to build, program and run your project.

 Results

After successfully programming the device, the LED will start blinking. Press Switch 1 (labeled BTN2) on the board to stop the blinking. Press it again to restart the blinking.

 Conclusions

This example project demonstrates much more than configuring, monitoring, and controlling PIC32 I/O Port pins. You've also learned the basic program architecture common to all MPLAB Harmony projects.

You may be thinking that this a lot of code to monitor a switch and blink an LED. This is true. An 8-bit device can perform this task for less cost and less code. The assumption is you will want to integrate this code into a larger project that may already implement the Timer System Service (e.g. the Harmony TCP/IP stack). This code will work cooperatively with other Harmony library modules, and it will efficiently share PIC32 resources. It can also be easily reused in other PIC32 projects and frees you from needing to learn details of how the underlying hardware works.

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