9.6 Touch Peripheral
Add the Capacitive Voltage Divider (CVD), also known as the Touch peripheral module, to
the application by following these steps.
- Download and install the Harmony 3 Dependencies, which include the touch library required for configuration and code generation related to the Touch peripheral module. For more details, refer to Install Harmony 3 Dependencies from Related Links section.
- In the Project Graph tab,
the user must add the Touch component.Note: The user can adjust the available settings for the touch library and any related components as per the requirement.
- Upon code generation, the user can access the code generated for the touch library and related components.
- The BLE Transparent UART with
Touch peripheral application example is available in the
wireless_apps_pic32_bz6/apps/ble/peripheral_applications/touch_peripheral_trp_uart
. For more details, see BLE and Touch Transparent UART from Related Links. - For the touch parameter tuning, refer to Touch Sensing Online Documentation in Reference Documentation from Related Links.
MCC Component Addition
The following are the steps to add the Touch library to any Bluetooth® Low Energy.
- Add Touch Library middleware with
needed components:
- Touch Component: From the “Touch” drop-down, click + (green plus) symbol next to the Touch Library middleware from the available resource list.
- The configurator adds
Touch Library to the project graph, making it available for
configuration and code generation.
Figure 9-25. Adding Touch Component - RTC Component: A
pop-up window appears asking for auto-activation of RTC component. Click
Yes.
Figure 9-26. RTC Component Auto-Activation - ADCHS Component: A
pop-up window appears asking for auto-activation of ADC component and
components automatic connection. Click Yes.
Figure 9-27. ADC Component Auto-Activation
- The project graph contains Touch
Library, RTC and ADCHS.
- Launch Touch Configurator:
The user can configure Touch parameters via a custom User Interface (UI) in MCC.
To launch the Touch Configurator, perform the following steps:
- From the “Plugins:”
drop-down list, select Touch Configuration.
Figure 9-28. Selecting Touch Configuration - The following Touch
Configuration pop-up window appears.
Figure 9-29. Touch Configuration Window
- From the “Plugins:”
drop-down list, select Touch Configuration.
- Choose Technology and Add
Sensor: For this example QT7 Touch Xplained Pro board is considered. QT7
Self Capacitance Xplained Pro Extension Kit has two touch buttons and one slider
sensor.
- The technology in use is the self capacitance sensing technology.
- In the Create tab,
enter 1 in the “Buttons” field.
Figure 9-30. Adding Buttons Note: This example uses only one button available on QT7 Touch Xplained Pro board. - Add Slider: Click the Slider icon. QT7 Touch Xplained Pro slider has 3 channels.
- In the Create tab,
enter 3 in the “Segments” field. Click Add.
Figure 9-31. Create Tab – Segments Field
- Click the Configure tab
which allows to configure touch properties such as:
- Sensor Pins:Tip: Refer to the Curiosity board XPRO extension and QT7 Xplained Pro documents for connection details.
- For more details, refer to the PIC32-BZ6 Curiosity Board User's Guide (DS00006006) in Reference Documentation from Related Links.
- QT7 Xplained Pro Design Files. For more details on the design files, refer to the ATQT7-XPRO QT7 Xplained Pro Extension Kit in Reference Documentation from Related Links.
- According on the design files, the user must select the correct
Y-Signals lines for buttons and slider as follows.
Figure 9-32. Selection of Signals Lines - Sensor Parameter
tab allows to configure touch channel properties such as:
- Oversamples (filter level)
- Digital Gain
- Analog Gain
- Series Resistor
- CSD (additional cycles)
- Prescaler
- Threshold
- Hysteresis
- AKS_GROUP (adjacent key suppression)
Figure 9-33. Sensor Parameters - Common Parameters
tab allows to configure the following:
- Acquisition tab allows the following configuration
changes:
- Scan Rate
- Acquisition Frequency
- Sensor: tab allows to configure sensor parameters such
as:
- Detect Integration
- Away from Touch Recalibration Count
- Away from Touch Recalibration Threshold
- Touch Drift Rate
- Away from Touch Drift Rate
- Drift Hold Time
- Re-burst mode
- Max on Duration
Figure 9-34. Acquisition and Sensor Parameters
- Acquisition tab allows the following configuration
changes:
- Driven Shield tab
allows to configure the following:
Figure 9-35. Driven Shield Window
- Sensor Pins:
For more details on different Touch configuration parameters, refer to the QTouch Modular Library Peripheral Touch Controller User’s Guide (DS40001986) in Reference Documentation from Related Links.
Application Development
The MCC code generation generates the touch_example.c
, which includes
the sample application implementation. The touch_mainloop_example()
API
implements the periodic touch measurement initiation. The task handler in
app.c
needs to call this API .
The following are the steps to include touch application functionality:
- In order to go in sync with
wireless task and application task, post a touch message in the application task
queue whenever the periodic RTC timerhanlder triggers. Add the highlighted code
in
touch_timer_handler()
oftouch.c
.void touch_timer_handler(void) { APP_Msg_T appMsg; time_to_measure_touch_var = 1u; qtm_update_qtlib_timer(DEF_TOUCH_MEASUREMENT_PERIOD_MS); appMsg.msgId = APP_MSG_TOUCH_MEAS; OSAL_QUEUE_SendISR(&appData.appQueue, &appMsg); }
- Add the
APP_MSG_TOUCH_MEAS
message ID inAPP_MsgId_T
ofapp.h
.typedef enum APP_MsgId_T { APP_MSG_BLE_STACK_EVT, APP_MSG_TOUCH_MEAS, APP_MSG_STACK_END } APP_MsgId_T;
- The application task needs to
call the
touch_mainloop_example()
API to perform periodic measurement of touch inputs.case APP_STATE_SERVICE_TASKS: { if (OSAL_QUEUE_Receive(&appData.appQueue, &appMsg, OSAL_WAIT_FOREVER)) { if(p_appMsg->msgId==APP_MSG_BLE_STACK_EVT) { // Pass BLE Stack Event Message to User Application for handling APP_BleStackEvtHandler((STACK_Event_T *)p_appMsg->msgData); } else if(p_appMsg->msgId== APP_MSG_TOUCH_MEAS) { Touch_MainLoop() }
- The user can customize the
Touch_Mainloop
to perform the needed functions by reading the touch input status when themeasurement_done_touch
is set.