Curiosity Development Board Example

Introduction

This article guides you from start to finish on how to use the MPLAB® Code Configurator (MCC) mTouch® Sensing Solutions module to create a single touch button on the 8-bit Curiosity Board. It also guides you through the use of the mTouch library API to obtain button information.

Curiosity.jpg

1

Create an MPLAB X IDE project for the Curiosity Board.

The Curiosity Board supports a wide range of 8-bit PIC® microcontrollers; in this example, the default PIC16F1619 is used.

curiosity_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 as shown above, 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 system clock.

Select '8MHz_HF' for Internal Clock, and enable 'PLL'. This will result in a 32 MHz system clock.

curiosity_fosc.png

To ensure the performance of mTouch button/proximity, an 8 MHz system clock is required. 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 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, the available mTouch sensor pin will be shown in the 'Pin Manager'.
Select pin RC1 as the mTouch sensor, which is connected to the mTouch Button on the Curiosity board.

curiosity_selectSensor_2.png

6

Add mTouch button and link to the sensor.

Go to the Buttons configuration view, and click on Create New Button, then the input text box will let you input how many buttons to be created. Input 1 for this project and click Add.

curiosity_createButton_2.png

Then, click on the 'Button0' icon to go to the Button Settings view, and select 'Sensor_AN5 sensor' for Button0.

curiosity_linkSensor_2.png

7

Enable Timer Interrupt.

Because the PIC16F1619 uses a software CVD implementation, the Automatic Frequency Adaptation (AFA) requires using a timer interrupt to schedule a CVD scan.

For mTouch library v2.00 or higher, the interrupt will be automatically enabled if AFA is enabled. Please skip this step.

For previous versions, open the 'Interrupt Module' and enable the corresponding timer interrupt; in this example TMR2 is selected as the AFA timer.

curiosity_enableInterrupt.png

If the corresponding timer interrupt is not enabled, there will be a warning issued in the Notification window.

cuirosity_timerInterrupt.png

8

Setup I/O pin to control LED.

LED D7 is used to provide visual feedback for the button state.
Select the RC5 pin, which is connected to LED D7, as an output in the 'Pin Manager'.

curiosity_selectLEDpin.png

Go to 'Pin Module', and rename the pin as LED.

curiosity_renameLED.png

9

Generate Code.

Click the Generate button.

curiosity_generate_2.png

10

Call mTouch service in main.c

Open up the generated main.c file, and enable the global and peripheral interrupts by uncommenting the two macros: INTERRUPT_GlobalInterruptEnable() and INTERRUPT_PeripheralInterruptEnable().

Place MTOUCH_Service_Mainloop() in the while loop, as shown below (highlighted):

11

Use mTouch button to control LED D7.

The mTouch button provides an API: bool MTOUCH_Button_isPressed(enum mtouch_button_names button) to obtain the button state.

In this example, there is only one button, so 'Button0' or '0' is provided as the argument for this API. The goal is to turn on the LED D7 (which is active high) when the button is pressed and turn the LED off when the button is released. The application code that you need to write is shown in the highlighted lines below:

12

Program the board and test the code.

Click on the Program icon to program the board.

programboard.png

Once finished, press the mTouch Button and the LED D7 should turn on.

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