Generate Touch Project in Harmony

Last modified by Microchip on 2023/11/10 11:18

Warning: This tutorial uses the old Harmony configuration tool (MPLAB® Harmony Configurator (MHC)). New Harmony projects should use the MPLAB Code Configurator (MCC) instead.

 

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

Procedure

Open MPLAB X IDE

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

MPLAB X View: File > New Project

Back to Top


Choose Project

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

MPLAB X View:  Select 32-bit MPLAB Harmony 3 Project in the Choose Project window

Back to Top


Framework Selection

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

MPLAB X View: Choose the path and click Next

Back to Top


Project Settings

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

MPLAB X View: Enter the location, folder name, and path and click Next

Back to Top


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.

MPLAB X View: Target Device is ATSAMC21N18A and click Finish.

Back to Top


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.

    MPLAB X View: 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.

MPLAB Harmony Launcher:  Click Launch

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

Select Packages Window

Back to Top


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.

    Window requesting auto-activation of RTC component. Click Yes.

  • Another pop-up appears asking for auto-connecting the RTC component. Click Yes.

    Message requestintg auto-connecting the RTC component. Click Yes.

Back to Top


Launch Touch Configurator

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

Launch Touch Configurator:  Tools > Touch Configuration

Back to Top


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.

Touch Configurator View: Choose Technology then Choose Mutual Capacitance Sensing

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

Harmony Configuratore View: 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.

Warning Message: Click Yes

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

Touch Configurator View: Click on the Slider icon. Input "4" in the Number of Channels box. Click Add.

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

Touch Configurator View: Click on the Wheel icon. Input "4" in the Number of Channels box. Click Add.

Back to Top


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.

X and Y lines should be selected as indicated

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.

Touch Configurator Table View

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.

Touch Configurator Matrix View

Back to Top


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

Touch Configurator Channel tab

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.

Touch Configurator Sensor tab

Acquisition Configuration
Scroll down the sensor page to configure:
  • Scan Rate
  • PTC Interrupt Priority
  • Acquisition Frequency.

Touch Configurator: Acquisition Configuration on Sensor Tab

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.

Select Enable Frequency Hop checkbox and Frequency Auto Tuning checkbox

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

Sliders and wheels tab:  Xonfigure the slider sensor and wheel sensor parameters

Back to Top


Notifications

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

Notifications tab

Back to Top


Summary

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

PTC Manager: Summary tab

PTC Manager: Summary tab


Back to Top

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.

Back to Top