This example project uses the ADC in the PIC32 to convert an analog voltage to digital, and display the magnitude of the result on the 4 LEDs found on the Digilent chipKITTM WF32 development board.
The MPLAB® Harmony ADC Driver and Peripheral Libraries are used to achieve this. The MPLAB Harmony Configurator (MHC) is used to configure the ADC Driver to generate an interrupt after acquiring and converting 16 samples. The interrupt service routine calls a function to read and average the results from the ADC results buffer. It also sets the "dataReady" flag indicating it's time to update the LEDs with the new ADC result.
The code you will add to this example project (as described in the following steps) implements the state machine shown in the diagram below.
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.01
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
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_01)
| 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 the BSP to load appropriate default values for the PIC32 core, clocks, and I/O port pins.
Use MHC to enable and configure the ADC Driver
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 code to the ADC Interrupt Service Routine.
Create the callback function called by the ADC Interrupt Service Routine.
Create the function to display the ADC average on the LEDs.
Create the application initialization function.
Create the APP_Tasks() function to implement the application's state machine.
Connect the development board and programmer/debugger to your computer, then select the XC32 compiler version and programmer/debugger for the project
Build, program and run your projectClick the "Run" icon to build, program and run your project.
After successfully programming the device, at least one LED will turn on. Turning the POT all the way to the left will light a single LED. As you turn the POT to the right, more LEDs will turn on (similar to a volume indicator).
This example project demonstrates much more than configuring, monitoring, and controlling PIC32 ADC. You've also learned the basic program architecture common to all MPLAB Harmony projects.