Generate Touch Project in Harmony
Objective
The following lab shows you how to create a Touch project with the MPLAB® Harmony platform where you can graphically add sensors and configure QTouch® parameters. The resulting project supports the MPLAB XC32 compiler in MPLAB X IDE. This project uses the SAMC21N Xplained Pro board along with the QT1 Mutual Capacitance Xplained Pro Extension Kit.
Reference Materials
- ATSAMC21N18A Xplained Pro
- QT1 Xplained Pro Extension Kit
- MPLAB® Harmony 1.xx Integrated Software Framework
Procedure
Open MPLAB X IDE
Click and select the File > New Project option in MPLAB X IDE.
Choose Project
Select 32-bit MPLAB Harmony 3 Project in the Choose Project window and click Next >.
Framework Selection
Choose the path where the framework is downloaded and click Next >.
Project Settings
Enter the location, folder name, and path for the project and click Next >.
Configuration Settings
Type "SAMC21N-touch" as the configuration name and choose the device.
Type "c21n18a" in the Device Filter box to find the device. Make sure the Target Device is ATSAMC21N18A and click Finish.
Launch MPLAB Harmony Configurator (MHC) with Touch Packages
Open MHC
- An empty project is created. Click on the project and open MHC by clicking on Tools > Embedded > MPLAB Harmony 3 Configurator.
Launch MHC
Choose the path where the content is downloaded from and kept in GitHub. Click Launch to launch MHC.
Configure Packages
Choose the packages needed for the project. Make sure the touch box is checked for creating touch projects.
Add Touch Library Middleware with Needed Components
Touch Component
From the Touch drop-down, drag and drop Touch Library middleware from the list of available components to the Project Graph window.
RTC Component
- A pop-up window appears asking for auto-activation of the RTC component. Click Yes.
- Another pop-up appears asking for auto-connecting the RTC component. Click Yes.
Launch Touch Configurator
Touch parameters can be configured via a custom UI in MHC. Launch the Touch Configurator by going to Tools > Touch Configuration.
Choose Technology and Add Sensor
The QT1 Mutual Capacitance Xplained Pro Extension Kit has two touch buttons, one wheel sensor, and one slider sensor.
Choose Technology
Choose Mutual Capacitance Sensing as the sensing technology.
Add Buttons
Input "2" in the Number of Buttons box.
Configure clocks
Click Yes in the pop-up option to set the proper clock for the touch project. This action will enable the required GCLK for PTC and configure the RTC clocks.
Add Slider
Click on the Slider icon. QT1 slider has 4 channels. Input "4" in the Number of Channels box and click Add.
Add Wheel
Click on the Wheel icon. QT1 wheel has 4 channels. Input "4" in the Number of Channels and click Add.
Pin Assignment
Refer to the following SAMC21N Xplained Pro header and QT1 Mutual Capacitance Xplained Pro documents for connection details.
Based on the design files, the X and Y lines should be selected as follows.
Select the Pins tab and select the correct X and Y lines for buttons.
Click on Table View to switch the view and assign the X, Y pins from the drop-down list for each sensor.
Click on Matrix View to switch the view back.
- Drag and drop the channels to the required combination of X and Y.
- Click on the channel displayed as X(Y) or Y(X) to toggle X to Y or Y to X.
- The Matrix View is only provided in case of mutual capacitance, to quickly drag and drop the sensors and configure the pins.
Parameters
Select the Parameters tab.
Channel
The Channel tab allows you to configure touch channel properties such as:
- Oversamples (filter level)
- Digital Gain
- Analog Gain
- Series Resistor
- CSD (additional cycles)
- Prescaler
- Threshold
- Hysteresis
- AKS_GROUP (adjacent key suppression).
Sensor
Click on the Sensor tab to configure sensor parameters such as:
- Detect Integration
- Away from Touch Recalibration Count
- Away from Touch Recalibration Threshold
- Touch Drift Rate
- Away from Touch Drift Rate
- Drift Hold Time
- Re-burst mode
- Max on Duration.
Acquisition Configuration
Scroll down the sensor page to configure:
- Scan Rate
- PTC Interrupt Priority
- Acquisition Frequency.
Noise Handling
Scroll down the sensor page to configure noise handling. Frequency Hop can be enabled by selecting the Enable Frequency Hop checkbox. You can select up to seven Frequency Steps and then configure the Hop Frequencies from the drop-down list. Hop Frequencies are fixed at compile time in Frequency Hop.
The auto-tune feature can be enabled by selecting the Enable Frequency Auto Tuning checkbox. Hop Frequencies are tuned by the library at run time as per the Auto Tune Parameters thresholds configured during noisy conditions.
Debug Parameters
Enable the datastreamer by selecting the Enable Data Visualizer option. A detailed description on how to configure the datastreamer is provided in the "Configure Datastreamer and Visualize Touch Data using Data Visualizer" page.
Sliders and wheels Parameters
Click on the Sliders and wheels tab to configure the slider sensor and wheel sensor parameters such as:
- Scroller Resolution
- Scroller Deadband
- Scroller Position Hysterisis
- Scroller Detect Threshold
Notifications
Click on the Notifications tab to check if there are any warnings or guidelines.
Summary
Click on the Summary tab to review the project configuration and find versions of library modules.
Results
Once you have finished configuring your project, generate the code. The source files and header files will be added to the project. Check for compilation errors and run it in the board.