This example project uses the Timer Driver Library (Dynamic implementation) to execute timer interrupts. The period of these interrupts, and the number of interrupts to count for a given alarm period, are calculated for you. Every 500 ms, a callback function will be executed to toggle LED 3.
You will use the MPLAB® Harmony Configurator (MHC) to create a Timer Driver instance using the PIC32 Timer1 peripheral (16-bit) with interrupts enabled. You will then add the following code to the project:
- Create the timer alarm initialization function.
- Calculates the timer period used to generate interrupts.
- Calculates the number of timer interrupts needed for a specific alarm period.
- Open a Timer Driver, register a callback function with it, then start the Timer Driver.
- Create the callback function to change the state of the I/O Port pin connected to LED 3 at the end of an alarm period.
The hardware for this project uses the chipKIT™ WF32 board from Digilent Inc.
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 chipKIT™ WF32 is the PIC32MX695F512L.
Use MHC to configure the PIC32 clocks
Use MHC to configure the Timer Driver
Use MHC to configure the I/O Port Pins
Use MHC to generate the code
Add application variables to your project in app.h
Add application-specific configuration constants to the project in system_config.h.
Create the callback function
Initialize the Timer1 period and number of interrupts to count to implement the timer alarm period
Initialize other application variables
Open the Timer Driver, register a timer alarm, and start the timer.
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 LED 3 blink (on/off) once a second (on 500 ms, off 500 ms). Change the APP_ALARM_PERIOD macro you created in system_config.h (near line #144) to modify the LED blink rate.
You have successfully used the MPLAB Harmony Timer Driver Library to create a periodic delay. You can experiment by changing this to a single (one-shot) delay, or by creating another Timer Driver to blink a different LED.