Low-Cost mTouch® Evaluation Kit Example

Introduction

This article explains how to use the MPLAB® Code Configurator (MCC) mTouch® Sensing Solutions module to create one proximity sensor and five touch buttons on the Low-Cost mTouch Evaluation board. You will learn how to set up and use Data Visualizer, a useful tool for tuning a touch application. This article also guides you through the mTouch library callback Application Program Interface (API) to obtain touch information.

mtouch_kit.png

 Materials

Hardware

Software

 Procedure

1

Create an MPLAB X IDE Project for the Low-Cost mTouch Eval Board

The Low-Cost mTouch Eval Board uses the PIC16LF1559. This 8-bit microcontroller has two 10-bit Analog-to-Digital Converters (ADCs) with automated hardware Capacitive Voltage Divider (CVD) modules.

mtouch_kit_example.png

If you are not familiar with MPLAB X IDE, please visit the "MPLAB® X IDE" Developer Help page.

2

Open MCC in MPLAB X IDE

openMCC.png

If you don't see the MCC logo, please check that you have installed the MCC plugin. More information on MCC installation can be found on the "Install MPLAB Code Configurator (MCC)" page.

3

Configure the System Clock

Select 8MHz_HF for Internal Clock, and check Software PLL Enabled. This will result in a 32 MHz system clock.

mtouch_kit_fosc.png

To ensure the performance of mTouch button/proximity, the system clock is required to be at least 8 MHz. If you select a system clock slower than 8 MHz, the mTouch module will generate a warning in the notification window.

4

Load mTouch Module

Double click on the mTouch button in the Libraries list inside the Device Resources window.

curiosity_deviceResource.png

After loading the module, the mTouch button will appear in the Project Resources pane.

curiosity_projectResource.png

5

Select mTouch Sensor

After loading the mTouch module, all available mTouch sensor pins will be shown in the Pin Manager pane. You will need to select the physical sensors and guard based on the sensor pinout information in Table 1.
Pin Name Function
RC6 Proximity Sensor
RB4 Button0
RC1 Button1
RC0 Button2
RA2 Button3
RA5 Button4
RC4 Guard
Table 1
mtouch_kit_selectSensor_2.png

6

Add the mTouch Button and Link to the Sensor

Go to the Buttons configuration view, click Create New Button. Type "5" into the Number of Button text box, then click Add.

mtouch_kit_createButton_2.png

Then, click each button name to go to the Button Settings view and select the corresponding sensor shown in Table 1.

mtouch_kit_linkSensor_2.png

7

Add mTouch Proximity and Link to the Sensor

Similar to the process of adding the mTouch button, go to the Proximities configuration view, click Create New Proximity Sensor, keep "1" as the Number of Proximity Sensor and click Add.

mtouch_kit_createProximity_2.png

Then, click the proximity sensor name to go to the Proximity Settings view, and select Sensor_AN14 : RC6 / AN14 to link to Proximity0.

mtouch_kit_linkSensor2_2.png

8

Enable Debugging with Data Visualizer and Configure EUSART Module

Go to the Debug tab within the mTouch module. Check the Enable Debug box and select Data Visualizer as the debug method.

8_DebugConfig.png

After enabling debugging, the EUSART module will be automatically added to the project and should appear in the project resources window.

8_EUSARTmodule.png

Check that the RX and TX pins are properly selected in the Pin Manager: Grid View.

8_PinManager.png

Click on the EUSART module in the Project Resources window and set the baud rate to 57600.

8_eusartConfig.png

9

Setup I/O Pin to Control LED

There are six LEDs on this board and we want to use them to indicate the proximity sensor and button state. The pinout is shown in Table 2:
Pin Name Function
RC2 LED0
RC3 LED1
RC7 LED2
RC5 LED3
RA1 LED4
RA0 LED5
Table 2

Use the Pin Manager: Grid View to select the LED pins based on the pinout table.

mtouch_kit_selectLEDpin.png

Go to the Pin Module and rename the pin as "LEDx". Because the LEDs are active low, we need to setup the pin starting high to turn off the LEDs.

mtouch_kit_renameLED.png

10

Generate Code

Click on the Generate button.

curiosity_generate.png

11

Call mTouch Service in main.c

Open up the generated main.c file and place MTOUCH_Service_Mainloop() into the while loop as shown in the following code block (highlighted).

Because the PIC16LF1559 has hardware CVD modules, the CVD scan will be automatically triggered by Timer2, so interrupts are not required for touch functionality alone. However, you will need to enable interrupts since the EUSART module uses them. This is done by removing the comments from the interrupt enable functions as shown in the following code block (highlighted).

12

Set Up Your Own Callback Function

We have seen how to use the polling method to obtain the button/proximity state in the Curiosity Board example. In this example, we will use callback functions. The mTouch library allows you to set your own callback function when a press/release event happens by passing the function pointer to the setter function.

First, we implement the press/release callback functions for button and proximity sensor and then pass these function pointers to the setter functions for each event as shown in the following code block (highlighted):

13

Use the mTouch Button and Proximity to Control LEDs

Once you have setup the callback functions, you will need to implement the logic to control the LEDs based on the event from different proximity/button. The complete main.c code is shown in the following code block:

14

Program the Board

After you connect the board with a programmer (e.g., PICKit™ 4 or MPLAB® ICD 4 In-Circuit Debugger), click the Program button to program the board.

mtouch_kit_programBoard.png

15

Connect to Data Visualizer

Connect the MCP2221 Breakout Module to the PICkit™ serial header on the mTouch Eval Board and connect to your PC with USB.

15_MCP_connected.png

Open Data Visualizer and select the appropriate COM port in the drop-down box in the Serial Port Control Panel window. Then, click on the Autodetect protocols link to select the folder within the project where the protocol files are located.

15_dvCOMselect.png

The protocol files should be located in the mtouch folder within the mcc_generated_files folder. You can check this by locating the files of type DB, DS, and SC.

15_SelectPath.png

Now, click the Connect button. When a successful connection is established, you will see the live touch data appear in the mTouch Data Visualizer window. This data can be useful for debugging and tuning a touch project.

15_buttondata.png
15_proximitydata.png
© 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.