Timer System Service Example Using chipKIT™ WF32


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.

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.


Hardware Tools

Tool About Purchase
chipKIT™ WF32
Development Board

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, MPLAB® Harmony v1.07

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
Windows Linux Mac OSX
Integrated Development Environment
C/C++ Compiler
MPLAB® Harmony
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
Windows Linux Mac OSX
Project and Source Files


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.


Create a new MPLAB® Harmony project

The Target Device used on the chipKIT™ WF32 is the PIC32MX695F512L.


Use MHC to configure the PIC32 clocks


Use MHC to configure the Timer System Service


Use MHC to configure the I/O Port Pins


Use MHC to generate the code


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


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


Add application code to your project


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


Build, program and run your project


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.


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.

© 2016 Microchip Technology, Inc.
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.