Intermediate
30 min

Touch the difference with AT42QT1110 and MK64FN1M0VDC12

The future of interaction!

TouchKey 3 Click with Clicker 2 for Kinetis

Published Aug 07, 2023

Click board™

TouchKey 3 Click

Dev Board

Clicker 2 for Kinetis

Compiler

NECTO Studio

MCU

MK64FN1M0VDC12

Incorporate capacitive touch into your projects and witness the transformation of user experience

A

A

Hardware Overview

How does it work?

TouchKey 3 Click uses the AT42QT1110, an 11-key QTouch® Touch Sensor IC from Microchip. It can be configured in several different ways, depending on the application: it can be used to support more or less sensor channels, to support direct outputs for an interrupt triggering on a specific channel, to have its #CHANGE output pin used for triggering one global interrupt whenever one of the sensors detects a touch event, or to improve the power consumption by employing the SYNC input signal for triggering sensing bursts in specific time intervals. TouchKey 3 Click uses seven capacitive sensing channels, with the #CHANGE pin routed to the INT pin of the mikroBUS™, so that an interrupt can be triggered if any of the sensors detect a touch event, for example. This can trigger an SPI read cycle only when the key is pressed, avoiding the need for constant polling of the AT42QT1110’s registers. However, the behavior of the #CHANGE pin is programmable and more information about its functionality can be found in the AT42QT1110 datasheet. The SYNC pin is pulled high and not used, allowing the click board™ to run in the Free Run mode, which enables the fastest key press detection times. #RESET pin of the AT42QT1110 is routed to the RST pin of the mikroBUS™, and it is used to reset the device and reinitialize its working parameters - either with values stored in the EEPROM or the default values that are loaded into the RAM, in case the EEPROM does not contain any saved values. SPI will not be available for 160ms after the RESET event has occurred. This pin should be pulled to a HIGH logic level to reset the device. The AT42QT1110 sensor has internal registers that are used for configuring

the working parameters of the device. The device Mode register is one of the important config registers, and it is used to control the overall operation of the click board™. Bit KEY_AC of the Device Mode register is used to set the detection triggering mode: 0 by SYNC pin or 1 by internal timer (should be set to 1, since the SYNC pin is pulled to a HIGH logic level); MODE bit: 0 for 7, or 1 for 11 channels configuration (should be set to 0 for 7 channels operation); SIGNAL bit:  0 for serial, or 1 for parallel; SYNC bit: 0 for rising edge, or 1 for zero level detect (disregarded, since the KEY_AC is set to 1); REPEAT TIME bit field: these four bits set the repeat time between the scanning intervals. If the REPEAT TIME is set to 0, the new scanning cycle will be performed immediately after the previous cycle, allowing for the fastest touch detection. The value of this bitfield is multiplied by 16ms to get the final repeat time. TouchKey 3 click also features signal processing to provide better button detection. Adjacent Key Suppression (AKS®) technology can be configured on each channel. A group of channels with the AKS® enabled will be processed so that only the detected key remains active, while other sensors will be disregarded. The other sensors with the AKS® enabled will be activated only when the currently active key is released. The sensor channels for which AKS® is not selected will retain the ability to sense touch simultaneously. This technology allows better key accuracy and less false detections in applications requiring key press detection precision. Detection Integration (DI) is another technology used to sense the key press better. When the button is first pressed, a counter is started. If the counter expires

and the sensor channel still detects a key press, that keypress will be declared true. Else it will be disregarded as false. This serves as a kind of debouncing and prevents false detections. DI technology is implemented per sensor. The AT42QT1110 IC has EEPROM memory, which can store current RAM settings. All the registers are kept in RAM, and after the power-on reset event (POR), the values stored in the EEPROM memory will be automatically copied to the registers. Else, the registers will be loaded with the default values. All these functions can be accessed and configured via the SPI bus. The SPI communication can be either in Quick SPI mode or full SPI mode. While working in the Quick SPI mode, the device will send a sequence of 7 bytes containing the essential data, such as the detection and error status of the channels. In this mode, no-host MCU commands are required, and this sequence will be clocked out continuously from the AT42QT1110 IC. Quick SPI mode is enabled by setting the SPI_EN bit in the Comms Options setup register. All the SPI pins and the chip select pin are routed to the appropriate pins on the mikroBUS™. Onboard SMD jumper labeled VCC SEL selects the power supply and logic voltage level. This click board can work with both 3.3V and 5V MCUs. The provided TouchKey 3 Click library contains functions used to configure the device and read touch events comprehensively and intuitively. The included example application demonstrates the usage of these functions, and it can be used as a reference for a custom design.

TouchKey 3 Click top side image
TouchKey 3 Click bottom side image

Features overview

Development board

Clicker 2 for Kinetis is a compact starter development board that brings the flexibility of add-on Click boards™ to your favorite microcontroller, making it a perfect starter kit for implementing your ideas. It comes with an onboard 32-bit ARM Cortex-M4F microcontroller, the MK64FN1M0VDC12 from NXP Semiconductors, two mikroBUS™ sockets for Click board™ connectivity, a USB connector, LED indicators, buttons, a JTAG programmer connector, and two 26-pin headers for interfacing with external electronics. Its compact design with clear and easily recognizable silkscreen markings allows you to build gadgets with unique functionalities and

features quickly. Each part of the Clicker 2 for Kinetis development kit contains the components necessary for the most efficient operation of the same board. In addition to the possibility of choosing the Clicker 2 for Kinetis programming method, using a USB HID mikroBootloader or an external mikroProg connector for Kinetis programmer, the Clicker 2 board also includes a clean and regulated power supply module for the development kit. It provides two ways of board-powering; through the USB Micro-B cable, where onboard voltage regulators provide the appropriate voltage levels to each component on the board, or

using a Li-Polymer battery via an onboard battery connector. All communication methods that mikroBUS™ itself supports are on this board, including the well-established mikroBUS™ socket, reset button, and several user-configurable buttons and LED indicators. Clicker 2 for Kinetis is an integral part of the Mikroe ecosystem, allowing you to create a new application in minutes. Natively supported by Mikroe software tools, it covers many aspects of prototyping thanks to a considerable number of different Click boards™ (over a thousand boards), the number of which is growing every day.

Clicker 2 for Kinetis dimensions image

Microcontroller Overview

MCU Card / MCU

default

Architecture

ARM Cortex-M4

MCU Memory (KB)

1024

Silicon Vendor

NXP

Pin count

121

RAM (Bytes)

262144

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
Reset
PB11
RST
SPI Chip Select
PC4
CS
SPI Clock
PC5
SCK
SPI Data OUT
PC7
MISO
SPI Data IN
PC6
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
Interrupt
PB13
INT
NC
NC
TX
NC
NC
RX
NC
NC
SCL
NC
NC
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

TouchKey 3 Click Schematic schematic

Step by step

Project assembly

Clicker 2 for PIC32MZ front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Clicker 2 for Kinetis as your development board.

Clicker 2 for PIC32MZ front image hardware assembly
Buck 22 Click front image hardware assembly
Prog-cut hardware assembly
Micro B Connector Clicker 2 - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
Necto image step 5 hardware assembly
Necto image step 6 hardware assembly
Flip&Click PIC32MZ MCU step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware assembly

Track your results in real time

Application Output

This Click board can be interfaced and monitored in two ways:

  • Application Output - Use the "Application Output" window in Debug mode for real-time data monitoring. Set it up properly by following this tutorial.

Software Support

Library Description

This library contains API for TouchKey 3 Click driver.

Key functions:

  • touchkey3_send_command - This function executes one of the possible commands

  • touchkey3_send_request - This function sends a request command, and returns the response

  • touchkey3_get_data - This function reads from a selected configuration register

Open Source

Code example

The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.

/*!
 * \file 
 * \brief TouchKey3 Click example
 * 
 * # Description
 * This click uses 7 capacitive sensing channels, with the #CHANGE pin routed to the INT pin of the mikroBUS™, 
 * so that an interrupt can be triggered if any of the sensors detect a touch event. 
 * This can be used to trigger an SPI read cycle only when the key is actually pressed, 
 * avoiding the need for constant polling of the sensor registers.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes click driver and performs a soft reset of the click.
 * 
 * ## Application Task  
 * Reads the status of the keys, and outputs a message if a key is touched.
 * 
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "touchkey3.h"


// ------------------------------------------------------------------ VARIABLES

static touchkey3_t touchkey3;
static log_t logger;

static uint8_t return_data[ 2 ];
static uint8_t counter;
static uint8_t temp;
static uint8_t old_state;
static const uint16_t timeout_state = 1000;
static uint16_t timeout_cnt;

// ------------------------------------------------------ APPLICATION FUNCTIONS

uint8_t calculationt_index ( uint8_t data_in )
{
    uint8_t counter = 2;
    
    if ( data_in <= 2 )
    {
        return data_in;
    }
    
    while ( data_in > 2 )
    {
        data_in /= 2;
        counter++;
    }
    
    return counter;
}

void application_init ( void )
{
    log_cfg_t log_cfg;
    touchkey3_cfg_t cfg;

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, "---- Application Init ----" );

    //  Click initialization.

    touchkey3_cfg_setup( &cfg );
    TOUCHKEY3_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    touchkey3_init( &touchkey3, &cfg );

    touchkey3_reset( &touchkey3 );
    touchkey3_send_command( &touchkey3, TOUCHKEY3_CMD_RESET );
    timeout_cnt = timeout_state;
    
    Delay_ms( 300 );
}

void application_task ( void )
{   
    touchkey3_send_request( &touchkey3, TOUCHKEY3_REQ_ALL_KEYS, &return_data );

    for ( counter = 0; counter < 7; counter++ )
    {
        if ( ( return_data[ 1 ] >> counter ) & 0x01 )
        {
            log_printf( &logger, "Touch detected on key %d\r\n", ( uint16_t )(counter+1) );
            Delay_ms( 1000 );
        }
    }
}

void main ( void )
{
    application_init( );

    for ( ; ; )
    {
        application_task( );
    }
}


// ------------------------------------------------------------------------ END

Additional Support

Resources

Love this project?

'Buy This Kit' button takes you directly to the shopping cart where you can easily add or remove products.