Example for 8bit AVR

Table 1. The example below will explain in detail the steps to follow for library selection

Criteria

Selection

Notes

Microcontroller

Atmel Studio

The GCC compiled variant of the libraries for the device selected needs to be used.

Number of Keys required for the application

3

Each key requires 1 QTouch acquisition channel

Rotors and sliders required

Yes

 

Number of Rotors and Sliders required

3

Each rotor / slider will require 3 channels.

Number of Channels required for the application ( should be the sum of all channels required for all the keys ,rotors and sliders used in the design )

12

3 Keys + ( 3 rotors x 3 channels per rotor/slider )  12 channels

Charge cycle time required for the design

1 cycle

Assuming the device is configured with a clock frequency of 4MHz

Number of ports needed

3 ports

This is determined based on the number of channels required and the routing required for the channels SNS and SNSK pins to the ports For this design, 24 pins are required and we need 3 ports to support the sensors.

Choice of ports available for the design

SNS/ SNSK Pair1 ports

SNS1 Port : A

The choice of ports for the port pairs is limited and can be found in the section 5.7.1.5

SNSK1 Port : A

SNS/ SNSK Pair 2 ports

SNS2 Port : B

SNSK2 Port : C

Is there a need for reduced power consumption (and reduced execution time)?

_POWER_ OPTIMIZATION_ = 1

Enabling _POWER_OPTIMIZATION_ will lead to a 40% reduction in power consumed by the library, but at the expense of reduced external noise immunity. When power optimization is enabled, the unused pins within a port used for QTouch, may not be usable for interrupt driven applications. This option is available only for ATtiny and ATmega devices.

SNS1 and SNSK1 pins use the same port.

_SNS1_SNSK1_SAME_PORT_

The _SNS1_SNSK1_SAME_PORT_ symbol needs to be defined as port A is used for both SNS1 and SNSK1 pins.

Given the above requirements for the applications, the first step is to select the right library variant required.

Step 1: Selecting the right library variant

Referring to the library selection guide, we see that there are a few variants of libraries supported for ATmega1280. Since the application requires 12 channels and rotor slider support, one has to select a library variant which supports at least 12 channels or more along with 3 Rotors/Sliders. Hence we select the 12 channel library variant for GCC complier which supports the required number of sensors/channels. This works out to be libavr51g1_12qt_k_3rs.a

Step 2: Defining the constants / symbols in the project space

In the host application file, define the following constants and symbols

#define QTOUCH_
#define QT_NUM_CHANNELS 12
#define SNSK1 A
#define SNS1 A
#define SNSK2 B
#define SNS2 C
#define QT_DELAY_CYCLES 1
#define _POWER_OPTIMIZATION_ 1
#define _SNS1_SNSK1_SAME_PORT_
Note:

The above definitions are available in touch_config.h file. Alternatively, you can define these in your IDE’s project options or have them defined in a separate header file.

Step 3: Usage of library API’s

Now, you can use the touch API’s to create, initialize and perform touch sensing. Refer to the sample applications in section 5.6.11.2 for reference. These sample applications illustrate the usage of the API’s and the sequence of operation.

Step 4: Adding necessary source files for compilation

The source files needed for compiling your application along with the touch library are touch_api.h, touch_config.h and qt_asm_tiny_mega.S.