Generate a Touch Project With MPLAB® Code Configurator (MCC) Melody
Objective
The following procedure shows how to create a Touch project with the MPLAB® Code Configurator (MCC) Melody platform, where touch sensors and their parameters can be graphically added and tuned. The resulting project supports the MPLAB XC8 compiler in MPLAB X IDE. The step-by-step procedure for generating a mutual capacitance project using MCC Melody has been provided here. This project uses the ATTINY3217 Xplained Pro board along with the T10 Mutual Capacitance Xplained Pro Extension Kit.
Materials
Hardware Tools
| Tool | About | Purchase |
|---|---|---|
| ATTINY3217 XPRO | ATtiny3217 Xplained Pro | ATTINY3217-XPRO | Microchip Technology. |
| T10 XPRO | T10 Xplained Pro kit | DM320204 | Microchip Technology |
Software Tools
- MPLAB X IDE with MCC installed
Procedure
Open MPLAB®X IDE.
Click and select the File > New Project option in MPLAB X IDE.
Choose the project.
In the New Project window, select Application Project and click Next.
Type "TINY3217" in the Device option and select ATtiny3217.
In the Tool option, select the Attiny3217 Xplained Pro Tool from the drop-down and click Next.
Select the compiler.
In the Select Compiler section, select the XC8 compiler and click Next.
Enter the Project Name, Project Location, and Project Folder for the project and click Finish.
Select MCC from the toolbar.
When the MCC Content Manager window opens, click Next in MCC Melody.
Select the Touch Library content from the Component section and click Finish.
From Touch Configurator, add Touch from the Device Resources tab.
Touch is added to the project graph, as shown in the accompanying image.
Include RTC from Device Resources.
The builder with RTC and Touch is as follows.
Enable Overflow Interrupt in RTC.
Select Mutual-Cap from the drop-down.
Click the Button icon and add 4 buttons.
The Information dialog box opens, indicating that the Sensor pins are auto-assigned on creation. Click Ok.
Now, click the Slider button and select 4 in segments. Click Add.
Now, four buttons and a four-channel slider are added.
A generalized pin assignment for a majority of the Xplained Pros, Curiosity Pros, and MCUs has been provided in the Curiosity Nano Touch Adapter Pin Configuration table.
If the MCU or the XPRO board is not available, then you can assign the pins based on the data sheet/user guide of that particular MCU/XPRO.
Based on the configuration, the X and Y lines should be selected as follows.
| Sensor | Channel ID | X Line | Y Line. |
| Button 0 | 0 | 5 | 2 |
| Button 1 | 1 | 4 | 2 |
| Button 2 | 2 | 1 | 2 |
| Button 3 | 3 | 0 | 2 |
| Slider 0 | 4 | 5 | 3 |
| 5 | 4 | 3 | |
| 6 | 1 | 3 | |
| 7 | 0 | 3 |
The pin assignment can be done in Configure > Sensor Pins. The pins were selected with respect to the above table in Touch Configurator. Once the pins are selected, click Create.

Now the pin assignment can be seen in the Matrix view or Table view, as shown in the accompanying images.
For tuning the Touch parameters, select Config > Sensor Parameters and tune according to the application.
The Sensor Parameters pane allows you to configure touch sensor parameters such as:
- Digital Filter Gain
- Digital Filter Oversampling
- Analog Gain
- Series Resistor
- Addition Charge Share Delay
- PTC Clock
- Sensor Detect Threshold
- Sensor Hysteresis
- Sensor AKS
Here the CPU operating frequency can be set in the GCLK block in MHz as highlighted above.
For tuning the Touch parameters, Configure > Common Parameters and tune according to the application. The Common Parameters pane allows you to configure touch sensor parameters such as:
- Acquisition
- Scan rate
- Peripheral Touch Controller (PTC) interrupt priority
- Acquisition frequency
- Sensor
- Detect integration
- Away from touch recall integration count
- Away from touch recall threshold
- Touch drift rate
- Away from touch drift rate
- Drift hold time
- Re-burst mode
- Max ON duration
Frequency Hop can be enabled by navigating to Configure > Frequency Hop and then sliding the Enable Frequency Hop button. A maximum of seven frequency steps can be selected, which can be individually configured using the drop-down.
Hop Frequencies are fixed at compile time in Frequency Hop.
The auto-tune feature can be enabled by sliding the Enable Frequency Auto tuning button.
A detailed description on how to configure the Frequency Hop and Frequency Hop Auto tune is provided in the "How to Enable Frequency Hop Auto Tuning" page.
Enable the data streamer by selecting the Enable Touch Tuning Data connection option.
A detailed description of how to configure the data streamer is provided in the "Tuning Options for Touch in MPLAB® Code Configurator (MCC) Melody and Harmony" page.
Click on the Summary tab to review the project configuration and find versions of library modules. Check whether all the necessary parameters are enabled and present.
Pin assignments can be checked as configured in the Pin Grid View.
In the Notifications tab, a few hints and warnings have been given for the project to build without any errors.
To clear these hints and warnings, in Touch Configurator, click Important Notes.
A new pop-up with the notifications and a checkbox is displayed. Once all the items in the notifications are checked, the warnings and hints are cleared.
In the Resource management tab, select Interrupt Manager and enable the Global Interrupt as indicated in the hints.
Now click Generate from the Project Resource tab.
The "Generation complete" message is displayed in the output window.
Include touch_process() in the main while(1) loop. Now the project is ready for testing on the kit.