Example for 32bit AVR

Based on the application design, 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.

For your design, you would need the following information to select the correct library variant

  1. 1.

    Device to be used for the design (only AT32UC3C0512 supported)

  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 port on which your design permits to have the X lines

    2. 3.2.

      The X lines can be spread on a single port.

  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

After selecting the right library variant, following steps are to be performed

  1. 1.

    Define the constants and symbol names required

    1. 1.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. 1.2.

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

    3. 1.3.

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

      1. 1.3.1.

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

      2. 1.3.2.

        Defined user’s project options.

      3. 1.3.3.

        Modify the defines in a touch_config.h

      Table 1. List of configuration parameters/macros

      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,24,32,64).

      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,3,4,8)

      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,3,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

      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

      PORT_YA

      Any IO port available with the device.

      Receive electrode for touch sensing using QMatrix acquisition

      PORT_YB

      Analog Comparator 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

      SHARED_YAYB

      Possible Values 0 or 1.

      Value should be 0 if Ya and Yb are not on same port else 1 if they are on same port.

    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.

  2. 2.

    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] as given in main.c file.

    Filling Arrays in the main.c file

    According to the pin availability for the touch sensing, initialize the arrays in the main.c file as below:

    x_line_info_t x_line_info[NUM_X_LINES] = {
        FILL_OUT_X_LINE_INFO( 1,0u ),
        FILL_OUT_X_LINE_INFO( 1,2u ),								
        FILL_OUT_X_LINE_INFO( 1,7u ),								
        FILL_OUT_X_LINE_INFO( 1,15u ),
    };

    First argument of FILL_OUT_X_LINE_INFO should always be 1 as X port is only on one port. Second arguments denotes the pins on that particular port.

    y_line_info_t ya_line_info[NUM_Y_LINES] = {
        FILL_OUT_YA_LINE_INFO( 0u ),
        FILL_OUT_YA_LINE_INFO( 5u ),
    };
    
    y_line_info_t yb_line_info[NUM_Y_LINES] = {
        FILL_OUT_YB_LINE_INFO( 7u ),
        FILL_OUT_YB_LINE_INFO( 22u ),
    };

    Yb lines are one of the inputs of the Analog Comparators.

  3. 3.

    Copy the library variant that was selected in step 1 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\include. The assembler files mentioned below could be found at the location C:\Program Files\Atmel\Atmel_QTouch_Libraries_5.x\Generic_QTouch_Libraries\32bit_AVR\UC3\QMatrix\common_files

    1. 3.1.

      qm_asm_uc3c_gcc.x in case of  GCC compiler

    2. 3.2.

      qm_asm_uc3c_iar.s82 in case of IAR compiler.

  4. 4.

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

    1. 4.1.

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

      1. 4.1.1.

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

    2. 4.2.

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

    3. 4.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

  5. 5.

    General application notes

    1. 5.1.

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

    2. 5.2.

      The QMatrix acquisition method libraries for 32 Bit devices internally use TIMER0 with channel0 for their operation.

    3. 5.3.

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