MPLAB® Harmony v2 Timer System Service Example Using chipKIT® WF32

 Objective

This example project uses the Timer System Service Library to execute functions after a specified period of time. The MPLAB® Harmony Configurator (MHC) is used to configure the Timer System Service. Three examples of using the Timer System Service are provided:

  1. One periodic delay is created to execute a callback function. This will toggle LED3 every 500 ms.
  2. Another periodic delay is created to execute a different callback function. This will toggle LED4 every 1000 ms.
  3. The third example shows you how to implement delays by reading the Timer System Service values directly. This will toggle LED5 every second.
objective1.png

The hardware for this project uses the chipKIT® WF32 board from Digilent® Inc. The three LEDs on the board are connected to PIC32 General Purpose I/O Port pins. The Ports Peripheral Library Pin toggle function is used to change the state of the LEDs.

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, MPLAB XC32 Compiler v1.40, MPLAP Harmony v1.07.

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)

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

2

Use MHC to configure the PIC32 clocks

3

Use MHC to configure the Timer System Service

4

Use MHC to configure the I/O Port Pins

5

Use MHC to generate the code

6

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

7

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

8

Add application code to your project

9

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

10

Build, program and run your project

 Results

After successfully building your project and programming your development board, you will see three LEDs blinking.

  • LED3 turns on for 500 ms, then off for 500 ms. This corresponds to the first delay period created by our application using the following line of code in app.c:

appData.sysTimerClientHandle1 = SYS_TMR_CallbackPeriodic(500, 0, APP_SysTimerCallback1);

  • LED4 turns on for 1 second, then off for 1 second. This corresponds to the second delay period created by our application using the following line of code in app.c:

appData.sysTimerClientHandle2 = SYS_TMR_CallbackPeriodic(1000, 0, APP_SysTimerCallback2);

  • LED5 blinks at the same rate as LED4. This System Tick counter is read every APP_Task loop to determine if one second has passed. If it has, LED5 is toggled.

 Conclusions

You have successfully used two implementations of the Timer System Service. Both create periodic delays. There are other Timer System Service implementations that allow one-shot (single) alarm delay periods.

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