Low-Cost mTouch® Evaluation Kit Example

Introduction

This article guides you from start to finish on how to use the MCC mTouch® Sensing Solutions module to create one proximity sensor and five touch buttons on the Low-cost mTouch Evaluation Board. It also guides you through the use of the mTouch library callback Application program interface (API) to obtain touch information.

mtouch_kit.png

1

Create an MPLAB® X 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 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 article.

2

Open MCC in MPLAB X IDE.

openMCC.png

If you don't see the MCC logo as shown above, please check if you have installed the MCC plugin. More information on MCC installation can be found here.

3

Configure system clock.

Select 8MHz_HF for Internal Clock, and enable PLL. 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 the mTouch icon in the Libraries list inside the Device Resources window.

curiosity_deviceResource.png

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

curiosity_projectResource.png

5

Select mTouch sensor.

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

6

Add mTouch button and link to the sensor.

Go to the Buttons configuration view, and click Create New Button five times to create five buttons.

mtouch_kit_createButton.png

Then, click each buton name to go to the Button Settings view, and select the corresponding sensor shown in the above table.

mtouch_kit_linkSensor.png

7

Add mTouch Proximity and link to the sensor.

Similarly to the process of adding the mTouch button, go to the Proximities configuration view, and click Create New Proximity Sensor.

mtouch_kit_createProximity.png

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

mtouch_kit_linkSensor2.png

8

Setup I/O pin to control LED.

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

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 low to turn off the LEDs.

mtouch_kit_renameLED.png

9

Generate Code.

Click the Generate button.

curiosity_generate.png

10

Call mTouch service in main.c

Open up the generated main.c file and place MTOUCH_Service_Mainloop() into the while loop as shown below (highlighted):

Because the PIC16LF1559 has hardware CVD modules, the CVD scan will be automatically triggered by Timer2 so you don't need to enable interrupts for this proejct.

11

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.

To use the API for mTouch button and proximity, mtouch_button.h and mtouch_proximity.h must be included in main.c. We then write the press/release callback functions for button and proximity sensor, and finally pass these function pointers to the setter functions for each event as shown below (highlighted):

12

Use 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 below:

13

Program the board

After you connect the board with a programmer (e.g., PICKit 3 or ICD3), click the Program icon to program the board.

mtouch_kit_programBoard.png
© 2016 Microchip Technology, Inc.
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.