Example for 8bit AVR

Based on the application design needs, the user needs to select the right library variant and the configuration to be used along with the variant. This section illustrates the steps required to select the right QMatrix acquisition method library variant and configuration for your application. QMatrix acquisition method library Variants are offered for IAR and AVR-GCC tool chains. First step is to select the compiler tool chain for which the libraries are required.

There are specific library variants distributed for each microcontroller. For your design, you would need the following information to select the correct library variant

  1. 1.

    Device to be used for the design

  2. 2.

    The number of touch sensing channels needed by the application – Then identify the Maximum number of channels required for the design that are supported by the library.

  3. 3.

    Number of X lines to be used in the design

    1. 3.1.

      The ports on which your design permits to have the X lines.

    2. 3.2.

      The X lines can be spread on a maximum of three ports, the more ports used the more is the code memory requirement by the library.

  4. 4.

    Number of Y lines to be used in the design

    1. 4.1.

      The port-pins ports on which your design permits to have the Y lines.

  5. 5.

    Do you need support for Rotors and/or Sliders in your design

    1. 5.1.

      If yes, how many rotors/sliders would be needed?

    2. 5.2.

      Based on a) above, identify the maximum number of rotors sliders that the library supports.

  6. 6.

    Which compiler platform you intend to use to integrate the libraries – IAR or AVR -GCC

Follow the steps listed below to arrive at the right library variant

  1. 1.

    Select the device from the list of supported devices

  2. 2.

    Select the right library variant for the device selected  from the selection guide available in C:\ Program Files\Atmel\Atmel_QTouch_Libraries_5.x\Library_Selection_Guide.xls

    Each variant supports

    1. 2.1.

      a specific number of channels,

    2. 2.2.

      Supports a specific configuration of X x Y matrix pins ( eg 4 x 2 for 4 - X pins & 2 - Y pins )

    3. 2.3.

      has support for Rotor / Slider ( either supported or not )

    4. 2.4.

      support is available for IAR and/or GCC compiler tool chain

    5. 2.5.

      support for specific number of rotors sliders.

  3. 3.

    Define the constants and symbol names required

    1. 3.1.

      The next step is to define certain constants and symbols required in the host application files where the touch API is going to be used. These values are derived from the parameters defined in step 2 for your application.

    2. 3.2.

      The constant/symbol names are as listed in the table below

    3. 3.3.

      The constant/symbol definitions can be placed in any of the following

      1. 3.3.1.

        In the user’s ‘C’ file prior to include touch_api.h in the file.

      2. 3.3.2.

        Modifying the defines in a touch_config.h available in the project folder.

    Table 1. List of configurable parameters for touch library usage

    Symbol / Constant name

    Range of values

    Comments

    _QMATRIX_

    Symbol defined to indicate QMatrix acquisition method is required

    Define this symbol to indicate QMatrix acquisition method is required

    QT_NUM_CHANNELS

    The number of channels the library supports.( Possible values:4,8,16,32,56,64).

    Note: 56 channel for only ATxmega Devices.

    Value should be same as the number of channels that the library supports

    NUM_X_LINES

    The number of X lines the library supports.( Possible values:4,8)

    Value should be same as the number of X lines that the library supports. Refer to library selection guide

    NUM_Y_LINES

    The number of Y lines the library supports.( Possible values:1,2,4,7,8)

    Note: 7 Y-lines for only ATxmega Devices)

    Value should be same as the number of Y lines that the library supports. Refer to library selection guide

    _ROTOR_SLIDER_

    Symbol defined if Rotor and/or slider is required

    Needs to be added in case user needs to configure ROTOR/SLIDER

    Needs to be removed for ALL KEYS configuration

    QT_MAX_NUM_ROTORS_SLIDERS

    Maximum number of rotors/sliders the library supports( possible values:0,2,4,8)

    Subject to support for rotors/sliders in the library selected.

    QT_DELAY_CYCLES

    Possible values :1,2,3,4,5,10,25,50

    NUM_X_PORTS

    Number of ports on which the X lines needs to be spread.

    (Possible values 1,2,3)

    Maximum number of ports that the X lines can spread is 3.

    Note: Code memory required increases with the increase in NUM_X_PORTS

    PORT_X_1

    First IO port for configuring the X lines.Any IO port available with the device.

    Drive electrode for touch sensing using QMatrix acquisition

    Valid when NUM_X_PORTS =1,2,3

    PORT_NUM_1

    1

    Do not edit this macro

    Valid when NUM_X_PORTS =1,2,3

    PORT_X_2

    Second IO port for configuring the X lines. Any IO port available with the device.

    Drive electrode for touch sensing using QMatrix acquisition

    Valid when NUM_X_PORTS =2,3

    PORT_NUM_2

    2

    Do not edit this macro

    Valid when NUM_X_PORTS =2,3

    PORT_X_3

    Third IO port for configuring the X lines. Any IO port available with the device.

    Drive electrode for touch sensing using QMatrix acquisition

    Valid when NUM_X_PORTS =3

    PORT_NUM_3

    3

    Do not edit this macro

    Valid when NUM_X_PORTS =3

    PORT_YA

    Any IO port available with the device.

    Receive electrode for touch sensing using QMatrix acquisition

    PORT_YB

    ADC port available for the device.

    Receive electrode for touch sensing using QMatrix acquisition

    PORT_SMP

    Any IO port available with the device.

    Port of the Sampling pin for touch sensing using QMatrix acquisition

    SMP_PIN

    Any IO port available with the device.

    Sampling pin for touch sensing using QMatrix acquisition

    _ATXMEGA_

    Symbol defined if an ATxmega Device is used for QMatrix sensing technology

    Needs to be added if the device to be supported is ATxmegaxxxx

    SHARED_YAYB

    Possible values: 0 or 1

    #define SHARED_YAYB 1 in case YA and YB are on same port else 0.

    Once you have selected the right library variant and configuration parameters for the application, follow the steps outlined below to integrate the library variant in your application.

  4. 4.

    Fill in the arrays x_line_info_t x_line_info[NUM_X_LINES] y_line_info_t ya_line_info[NUM_Y_LINES] and y_line_info_t yb_line_info[NUM_Y_LINES] using the pin configuration wizard provided by the QTouch Studio.

  5. 5.

    Copy the library variant that was selected in step one to your project’s working directory or update your project to point to the library selected.

    Include the “touch_api.h” header file and assembler source file from the QTouch library in your application. The touch_api.h can be found in the release package at C:\Program Files\Atmel\Atmel_QTouch_Libraries_5.x\ Generic_QTouch_Libraries \AVR_Tiny_Mega_XMega\QMatrix\common_files. The assembler files mentioned below could be found at the location C:\Program Files\Atmel\Atmel_QTouch_Libraries_5.x\ Generic_QTouch_Libraries \AVR_Tiny_Mega_XMega\QMatrix\common_ files

    1. 5.1.

      qm_asm_tiny_mega.S in case of  ATtiny and ATmega devices.

    2. 5.2.

      qm_asm_xmega.S in case of ATxmega devices.

    3. 5.3.

      qm_asm_m8535_m16.S in case of ATmega8535 and ATmega16 devices.

  6. 6.

    Initialize/create and use the touch api’s in your application

    1. 6.1.

      In your application, create, initialize and configure the sensors.

      1. 6.1.1.

        The APIs of interest are qt_enable_key/rotor/slider()

    2. 6.2.

      configure the global configuration parameters valid for all the sensors in the  library

    3. 6.3.

      Provide timing for the QTouch libraries to operate. i,e. the QTouch libraries do not use any timer resources of the microcontroller. The Host application has to provide the required timing and also call the API’s at the appropriate intervals to perform touch sense detect operations

  7. 7.

    General application notes

    1. 7.1.

      The clock, host application and other peripherals needed by the host application needs to be initialized.

    2. 7.2.

      The QMatrix acquisition method libraries internally use TIMER1 for their operation.

    3. 7.3.

      Ensure that there are no conflicts between the resources used by the touch library and the host application

    4. 7.4.

      Ensure that the stack size is adjusted to factor in the stack depth required for the operation of the touch libraries.