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:
- One periodic delay is created to execute a callback function. This will toggle LED1 every 500 ms.
- Another periodic delay is created to execute a different callback function. This will toggle LED2 every 1000 ms.
- The third example shows you how to implement delays by reading the Timer System Service values directly. This will toggle LED3 every second.
This project uses the PIC32MZ Embedded Connectivity with FPU (EF) Starter Kit. 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.
|Tool|| About|| Purchase|
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.
| Windows|| Linux|| Mac OSX|
Integrated Development Environment
MPLAB® Harmony 1.xx
Integrated Software Framework
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)
| 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 PIC32MZ EC with FPU (EF) Starter Kit is the PIC32MZ2048EFH144.
Use the MPLAB Harmony Configurator (MHC) to configure the PIC32 core
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.
- LED1 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);
- LED2 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);
- LED3 blinks at the same rate as LED2. This System Tick counter is read every APP_Task loop to determine if one second has passed. If it has, LED3 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.