Generate a Touch Project with MPLAB® 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.

 Materials

Hardware Tools

Tool About Purchase
hwtool-50px.png
ATSAMC21N18A
ATSAMC21N18A
hwtool-50px.png
ATSAMC21N18A
Xplained Pro
hwtool-50px.png
QT1 Xplained Pro
Extension Kit

Software Tools

Tool About Installers
Installation
Instructions
Windows Linux Mac OSX
MPLAB® Harmony 1.xx
Integrated Software Framework

 Procedure

1

Open MPLAB X IDE:

Click and select the File > New Project option in MPLAB X IDE.

FileNewProject.PNG

2

Choose Project:

Select 32-bit MPLAB Harmony 3 Project in the Choose Project window and click Next >.

Choose-project.PNG

3

Framework Selection:

Choose the path where the framework is downloaded and click Next >.

Framework-selection.PNG

4

Project Settings:

Enter the location, folder name, and path for the project and click Next >.

Project-settings.PNG

5

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.

Configuration-settings.PNG

6

Launch MPLAB Harmony Configurator (MHC) with Touch Packages:

a

Open MHC

  • An empty project is created. Click on the project and open MHC by clicking on Tools > Embedded > MPLAB Harmony 3 Configurator.
    mhc.PNG

b

Launch MHC
Choose the path where the content is downloaded from and kept in GitHub. Click Launch to launch MHC.

launch.PNG

c

Configure Packages
Choose the packages needed for the project. Make sure the touch box is checked for creating touch projects.

launch2.PNG

7

Add Touch Library Middleware with Needed Components:

Touch Component
From the Touch drop-down, drag and drop Touch Library middleware from the available components list to the Project Graph window.

RTC Component
  • A pop-up window appears asking for auto-activation of RTC component. Click Yes.
    rtc.PNG
  • Another pop-up appears asking for auto-connecting the RTC component. Click Yes.
    rtc2.PNG

8

Launch Touch Configurator:

Touch parameters can be configured via a custom UI in MHC. Launch the Touch Configurator by going to Tools > Touch Configuration.

configurator.PNG

9

Choose Technology and Add Sensor:

The QT1 Mutual Capacitance Xplained Pro Extension Kit has two touch buttons, one wheel sensor and one slider sensor.

a

Choose Technology
Choose Mutual Capacitance Sensing as the sensing technology.

choosetechnology.PNG

b

Add Buttons
Input "2" in the Number of Buttons box.

snsor.PNG

c

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.

ClockSelection.PNG

d

Add Slider
Click on the Slider icon. QT1 slider has 4 channels. Input "4" in the Number of Channels box and click Add.

slider.PNG

e

Add Wheel
Click on the Wheel icon. QT1 wheel has 4 channels. Input "4" in the Number of Channels and click Add.

wheel.PNG

10

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.

PinData.PNG

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.

pin.PNG

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.
matrix.PNG

11

Parameters:

Select the Parameters tab.

a

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).
paramchannel.PNG

b

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.
paramsensor.PNG

c

Acquisition Configuration
Scroll down the sensor page to configure:

  • Scan Rate
  • PTC Interrupt Priority
  • Acquisition Frequency.
paramacq.PNG

d

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.

paramfreq.PNG

e

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.

f

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
sliParam.PNG

12

Notifications

Click on the Notifications tab to check if there are any warnings or guidelines.

notification.PNG

13

Summary

Click on the Summary tab to review the project configuration and find versions of library modules.

summary.PNG
summary2.PNG

 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.

© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.