This code example demonstrates how to use the Microchip Touch Library to interface with a touch 2D touch surface using the PIC32CM PL10 family of microcontrollers. The demonstration uses the Peripheral Touch Controller (PTC) hardware featured on the PL10 MCUs to detect input on a 5x5 2D capacitive touch surface. The touch input is visualized using LEDs and by printing the x and y coordinates of the touch to a terminal emulator.The application uses PIC32CM PL10 Curiosity Nano Board for programming and debugging the PIC32CM6408PL10048 MCU. The nano board acts as a USB-to-Serial bridge, allowing the MCU to communicate with a PC using the Universal Asynchronous Receiver Tranmitter (UART) protocol. The nano board plugs in to a Curiosity Nano Base board, which allows for easy connection of the QT8 2D Surface Sensor board. The QT8 Explained Pro Extension Kit is an evaluation board that makes it easy to try out the capacitive touch capabilities of many of Microchip's touch-capable MCUs. The board consists of a 5x5 array of diamond shaped self-capacitance sensors to make a 2D touch surface. The board has an array of LEDs for visual feedback of the touch sensors that can be controlled using an Inter-Integrated Circuit (I2C) I/O expander. The QT8 board has a connector designed to plug in to any Microchip developement boards with an Xplained Pro Extension header, such as the Curiosity Nano Base board.
- PIC32CM PL10 Data Sheet
- Touch Sensing Online Documentation
- QT8 Explained Pro Hardware User Guide
- Capacitive Touch Sensor Design Guide AN2934
- PIC32CM PL10 Curiosity Nano Evaluation Kit (EV10P22A)
- Curiosity Nano Base For Click Boards™ (AC164162)
- QT8 Xplained Pro Extension Kit (AC164161)
The individual sensor elements of the QT8 board are routed over the Xplained Pro Extenstion connector to the pins on the PIC32CM PL10 click board. One of the sensor elements on the QT8 board, Y-line-0, can be routed to either pin 5 or pin 17 of the Xplained Pro Extension header. In this code example, pin 17 is used to connect Y-line-0 to pin PA07 of the MCU. Refer to the QT8 Xplained Pro Hardware User Guide for details on how to route Y-line-0 to pin 17. Table 1 shows the pin mapping for the QT8, Curiosity Nano Base, and Curiosity Nano boards.
Table 1 Pin Mapping
| QT8 pin | Curiosity Nano Base Pin | Curiosity Nano Pin | Description |
|---|---|---|---|
| 1 | ID | NC | ID Chip Comms |
| 2 | GND | GND | Ground |
| 3 | AN2 | A27 | Horizontal line 3 |
| 4 | AN3 | A19 | Horizontal line 4 |
| 5 | RST2 | B04 | Not Used |
| 6 | RST3 | A24 | Horizontal line 2 |
| 7 | PWM2 | A17 | Horizontal line 1 |
| 8 | PWM3 | A16 | Horizontal line 0 |
| 9 | INT2 | A23 | Vertical line 4 |
| 10 | CS3 | B11 | Vertical line 3 |
| 11 | SDA | A00 | LED Driver SDA |
| 12 | SCL | A01 | LED Driver SCL |
| 13 | NC | NC | NC |
| 14 | NC | NC | NC |
| 15 | CS2 | B10 | Vertical line 1 |
| 16 | MOSI | A04 | Vertical line 2 |
| 17 | MISO | A07 | Vertical line 0 |
| 18 | SCK | A05 | Driven Shield |
| 19 | GND | GND | Ground |
| 20 | VCC | VCC | Target Supply |
MPLAB Tools for VS Code was used for generating software libraries, writing code, and debugging the application. MPLAB Tools for VS Code includes the Microchip Code Configurator (MCC) for generating drivers and libraries for the MCU, making it easy to prototype an application quickly. In this example, the MCC was used to generate the following software components:
-
Microchip Touch Library. This library handles all of the configuration of the peripherals necessary to implement responsive capacitive touch features. On the PIC32CM PL10, this library sets up the Real-Time Clock (RTC), the Analog to Digital (ADC) converter, and the Peripheral Touch Controller (PTC). The Microchip Touch Library provides APIs for implementing capacitive touch buttons, sliders, wheels, and 2D surfaces.
-
SERCOM. The PIC32CM PL10 family has two SERCOM modules that can be used for serial communication. These modules can be used to drive the I2C, Serial Peripheral Interface (SPI), or UART signals. This demonstration uses one SERCOM module configured for UART to send data to the PC using the USB-to-Serial converter on the nano board. The other SERCOM is configured for I2C to drive the LEDs on the QT8 board.
-
SysTick. The SysTick timer is a feature of the Arm® Cortex®-M0+ CPU that is typically used for generating timing for context switching in Real-Time Operating Systems (RTOS). It can be used for general purpose timing, and in this demonstration is used to generate a 1 ms tick for driving a heartbeat signal on the nano board's LED.
-
General Purpose I/O (GPIO). The MCC was used to configure pin PB02 as an output for driving the LED on the nano board.
MPLAB Tools for VS Code comes with MPLAB Data Visualizer. This is a useful debugging tool that can help to visualize real-time data coming from a UART stream. The Data Visualizer can be used with the Microchip Touch Library for debugging and tuning the touch sensors. In this demonstration, the Data Visualizer was used in the intial setup phase for configuring touch sensor parameters. After the touch parameters were determined, the Data Visualizer was used as a terminal emulator for displaying the x an y coordinates when the touch surface is pressed.
To setup the 2D touch sensor, the Touch Configuration Plugin in the MCC is used. When the plugin is opened, the drop-down box should be used to select self-capacitance. The surface icon is then selected and configured to have five vertical segments and five horizontal segments. The button sensor may be selected to configure the on-board cap touch button that is present on the PL10 nano board.
Once the button and the touch surface have been selected, the pins can be selected, and the sensor parameters adjusted in the Configure Tab. The pins for the 2D surface should be configured according to Table 1.
Once the correct pins have been selected, the sensor parameters can be adjusted. To adjust the sensor parameters, choose Sensor Parameters in the right hand pane under the Configure tab. Some of the parameters that can be adjusted are digital gain, analog gain, and detection thresholds. These parameters can be used to fine tune the sensitivity and responsiveness of the touch sensors. More details on how to configure and tune the touch sensors can be found in the Touch Library Online Documentation. For this particular hardware setup, the 2D touch surface sensors were set to have a digital filter gain of 8. All other parameters were left at their default values.
The last step to configure the touch sensors is to configure the driven shield output. Shielding can be very important when designing a touch sensor application to help reduce the sensitivity to Electromagnetic Interference (EMI), suppress unintended touch events, and improve moisture tolerance of the sensors. Shielding can be done passively on a Printed Circuit Board (PCB) using traces that are driven to a DC level; however, these often increase the capacitive load of the sensor which can reduce sensitivity. Another option is to drive a shield electrode with the same waveform as the sensing electrode, which provides the shielding effect without the unwanted capacitive load. The QT8 board has a dedicated driven shield electrode which can be configured in the Touch Library. To enable the driven shield, choose Driven Shield in the right hand pane under the Configure tab. From here, Enable Dedicated Shield Pin can selected on the correct pin (PA05) and can be chosen from the drop-down menu. More details on shielding and sensor design can be found in the Capacitive Touch Sensor Design Guide AN2934.
The demonstration continuously monitors the touch surface and display the x and y coordinates of the touch in the serial terminal. The LEDs on the QT8 surface are lit to display the location of the touch when it is detected. If a touch is detected on the touch button on the PL10 nano board, a message is printed to the serial terminal. Finally, the LED on the nano board is toggled every second as a heartbeat signal.
This code example shows how the various peripherals on PIC32CM PL10 microcontrollers can be used to implement a 2D capacitive touch sensor. With the MCC and MPLAB Tools for VS Code, it is quick and easy to get a capacitive touch prototype running. The PIC32CM PL10 family of Microchip MCUs is a great option for developing a capacitive touch solution when simplicity and low-cost are important.




