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:
- 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.
The hardware for this project uses the chipKIT® Wi-FIRE 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® 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, MPLAB 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 Wi-FIRE is the PIC32MZ2048EFG100.
2
Use the MPLAB Harmony Configurator (MHC) to configure the PIC32 core
3
Use MHC to configure the PIC32 clocks
4
Use MHC to configure the Timer System Service
5
Use MHC to configure the I/O Port Pins
6
Use MHC to generate the code
7
Add application states and variables to your project in app.h
8
Add application-specific configuration constants to the project in system_config.h
9
Add application code to your project
10
Connect the development board to your computer, then select the XC32 compiler version and programmer/debugger for the project
11
Build, program and run your project
Results
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.
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.
Table of Contents
|