APPLICATION NOTE Atmel AVR32819: AVR UC3 Touch Selection Guide Atmel QTouch Features • • Overview of the Atmel® QTouch® Library on Atmel AT32UC3 devices Comparative analysis of Atmel UC3L and UC3C based touch solutions Introduction Atmel QTouch Library provides an easy approach for developers to embed capacitive-touch button, slider and rotor/wheel functionality into any Atmel AVR® MCU based applications. QTouch Library support is available for 32-bit Atmel AVR UC3 devices. QTouch Library for AT32UC3L device uses the built-in hardware Capacitive Touch Module (CAT) whereas generic QTouch libraries for other AT32UC3 devices (UC3A, UC3B and UC3C) uses software based touch acquisition. The purpose of this application note is to highlight the features, pros and cons of each approach so as to enable the user to make informed decision on the best approach to incorporate touch solution in their design. The document focuses on the comparative analysis of QTouch and QMatrix solutions available for UC3L and UC3C devices using common benchmarking factors. 42047A−AVR−11/2012 Table of Contents 1. Document overview ............................................................................. 3 2. Atmel QTouch Library support on UC3 ................................................ 3 3. QTouch on Atmel AT32UC3L using CAT module ................................ 3 3.1 QTouch method ................................................................................................ 4 3.2 QMatrix method................................................................................................. 5 3.3 Autonomous QTouch ........................................................................................ 7 4. QTouch on AT32UC3A/B/C ................................................................. 7 4.2 QTouch method ................................................................................................ 8 4.3 QMatrix method................................................................................................. 8 5. Compiler support .................................................................................. 8 6. Firmware implementation ..................................................................... 8 6.1 Flow diagram for the Atmel AT32UC3L device ................................................. 9 6.2 Flow diagram for the Atmel AT32UC3C device ............................................... 10 7. Comparative analysis ......................................................................... 10 7.1 Power consumption......................................................................................... 11 7.1.1 QTouch method ................................................................................ 11 7.1.2 QMatrix method ................................................................................ 12 7.2 Code and Data memory .................................................................................. 13 7.3 Usage of interrupt sources and peripheral modules ........................................ 13 7.4 Sensor channel availability .............................................................................. 14 8. Recommended readings .................................................................... 14 9. Revision history .................................................................................. 15 Atmel AVR32819: AVR UC3 Touch Selection Guide [APPLICATION NOTE] 42047A−AVR−11/2012 2 1. Document overview This document analyzes a touch application consisting of rotor/wheel, slider and buttons for CAT based UC3 device as well as non CAT based UC3 device. The performance of the touch application is evaluated based on the following parameters: • • • • • • • 2. Power consumption Touch acquisition time (at a constant CPU frequency) Data memory (RAM) Code memory (Flash) Number of chip peripherals used such as timers, AST, CAT and analog comparator Interrupt sources Maximum number of channels/sensors supported Atmel QTouch Library support on UC3 QTouch and QMatrix are two different touch measurement methods supported by the QTouch Library. The QTouch method is generally suitable for small number of sensors since it requires 2 physical I/O pins per sensor. The QMatrix method is more appropriate for large number of sensors since it allows X by Y matrix of sensors to be implemented using maximum X+2Y+2 physical I/O pins. Touch sensing using QTouch or QMatrix methods can be added to an application by linking appropriate QTouch Library for the AVR Microcontroller. Using simple set of APIs user can configure sensors and do touch data acquisition. Touch measurement API has to be called periodically to acquire raw signal data. Using the acquired raw signal data; QTouch Library does the post-processing internally to calculate reference, delta and touch status. Table 2-1. Note: 3. QTouch Library support for UC3 devices. Device QTouch QMatrix UC3A YES NO UC3B YES NO UC3C YES YES UC3L YES YES QMatrix library support is not available for UC3A and UC3B devices. This is due to lack of analog comparator on these devices. QTouch on Atmel AT32UC3L using CAT module QTouch Library for UC3L uses the Capacitive Touch module (CAT) for touch data acquisition. Atmel AVR32819: AVR UC3 Touch Selection Guide [APPLICATION NOTE] 42047A−AVR−11/2012 3 Figure 3-1. Overview of the Atmel QTouch Library for UC3L devices. For both QTouch and QMatrix methods user has to configure peripheral DMA channels. Configured DMA channels act as communication medium between CAT module and MCU memory for transferring touch data. In case of QMatrix method, CAT module also uses DMA channels to store appropriate burst length values of all configured channels in burst length register. Touch measurement API initiates touch data acquisition process. During touch acquisition, the CAT module captures raw signal data from the sensors. Configured peripheral DMA Controller stores the acquired touch data in MCU memory. The QTouch Library accesses the touch data from the MCU memory and performs post processing to update touch status. During touch data acquisition the CPU is free to perform other tasks. Specific I/O pins of the MCU as recommended in their respective datasheet have to be selected for CAT module. Alternative functions of these pins should not be enabled. The CAT module can support three different types of touch measurement methods; i.e. QTouch, QMatrix and Autonomous QTouch. 3.1 QTouch method For QTouch method on Atmel AT32UC3L with QTouch Library and CAT module, maximum 17 QTouch channels (sense pairs) can be configured. Sense pairs SP0-SP7 belongs to first burst group, sense pairs SP8-SP15 belongs to second burst group and sense pair SP16 belongs to third burst group. CAT module does parallel bursting on all configured sense pairs only irrespective of the burst group. But the touch data acquisition is done sequentially. This is done for the first burst group, followed by the second and the third burst group. If the design uses sense pairs of only one burst group, then bursting happens only on those sense pairs. The CAT module performs touch data acquisition through a single DMA peripheral channel. Typical CAT clock (CLK_CAT) frequency used in QTouch method for burst timing control operations is 1MHz. Atmel AVR32819: AVR UC3 Touch Selection Guide [APPLICATION NOTE] 42047A−AVR−11/2012 4 In case of QTouch method, the CAT module does not terminate bursting on the sensor channels even after voltage across Cs capacitor reaches Vih. Bursting happens as long as the count value matches with specified maximum acquisition count (QM_MAX_ACQ_COUNT) value. This cause the sense capacitor (Cs) to charge more than necessary and this can lead to unstable measurements. So the QM_MAX_ACQ_COUNT macro value has to be set to few counts higher than the maximum signal value of all enabled sensors. This macro is defined in the “touch_config_at32uc3l.h” file. 3.2 QMatrix method Using QMatrix library and CAT module, it is possible to configure maximum of 17 X-lines and 8Y-Yk pairs (i.e.136 channels). CAT module does parallel bursting on all configured Y-lines of a given X-line. Figure 3-2 explains bursting sequence in case of QMatrix method. First bursting happens on all channels of X0-line as shown in case a. Then bursting happens on all channels of X1-line as shown in case b. This process happens sequentially on all configured Xlines. Figure 3-2. QMatrix bursting sequence. Scanning of sensor channels happens sequentially on each Y-line. Figure 3-3 explains scanning sequence of sensor channels. Figure 3-3. QMatrix sensor channel scanning sequence. For QMatrix method, the CAT module requires two peripheral DMA channels. Typical CAT clock (CLK_CAT) frequency used in QMatrix method for burst timing control operations is 4MHz. QMatrix method also requires generic CAT clock (GCLK_CAT) for accumulation of signal values for each sensor channel. Generic CAT clock must be set to one fourth of the PBA clock for proper QMatrix operation. Atmel AVR32819: AVR UC3 Touch Selection Guide [APPLICATION NOTE] 42047A−AVR−11/2012 5 CAT module on the Atmel AT32UC3L supports three discharge modes for QMatrix method: 1. 2. 3. SMP discharge mode Internal discharge mode External discharge mode Figure 3-4. QMatrix method. In this application note, SMP discharge mode is used. For more details about the QMatrix measurement method, refer to the Atmel QTouch Library User Guide. Atmel AVR32819: AVR UC3 Touch Selection Guide [APPLICATION NOTE] 42047A−AVR−11/2012 6 3.3 Autonomous QTouch CAT module on the Atmel AT32UC3L device supports single autonomous QTouch key. User can use any of the QTouch sense pairs for autonomous QTouch. For this user need to first configure the CAT clock (CLK_CAT). Typical CLK_CAT frequency used for burst timing control operations is 1MHz. Once the autonomous QTouch sensor is enabled, CAT module performs continuous touch measurements on the sensor to detect touch status. CAT module monitors the autonomous QTouch sensor without peripheral DMA and CPU intervention. The inbuilt detection algorithm within the CAT module helps in detecting the sensor status. It updates the host application if there is any change in status. The CAT module is capable to operate autonomous QTouch sensor without necessity of QTouch Library or application software. Thus autonomous QTouch status change interrupt is useful to wake up the device from sleep modes. Autonomous QTouch is recommended to use in applications where sleep mode is activated. Whenever there is touch activity on the sensor, then only the device goes active otherwise it continues to be in sleep state. This helps to achieve lower power consumption values. Figure 3-5. Autonomous QTouch method. When a sleep mode is activated that has disabled CAT clock, configured AST peripheral event works along with autonomous QTouch to detect touch status of sensor. While the CAT clock is disabled and the AST peripheral event is triggered, then a request will be made to enable CAT clock. Once CAT clock is enabled, the CAT module performs one iteration of autonomous touch measurement. If there is any touch activity on the sensor, then it wakes up the device from the sleep otherwise it goes to sleep mode until the next AST peripheral event triggers. 4. QTouch on AT32UC3A/B/C QTouch Library for UC3A/B/C uses CPU for performing touch data measurement and subsequent post processing. Specific port pins of the MCU as recommended in the Atmel QTouch Library Selection Guide have to be used to configure touch functionality in the application. Atmel AVR32819: AVR UC3 Touch Selection Guide [APPLICATION NOTE] 42047A−AVR−11/2012 7 Figure 4-1. Overview of the Atmel QTouch Library API for UC3A/B/C devices. 4.2 QTouch method QTouch library for AT32UC3A/B/C device allows maximum of 32 sensor channels. Inter port and intra port channel configuration is supported by the QTouch library. In case of inter port configuration, SNS and SNSK pins of the sensors are configured on two different ports. All even sensor channels comes under even burst group and all odd sensor channels come under odd burst group. Initially parallel bursting happens for sensor channels on the even burst group and then on the odd burst group. For less than or equal to eight sensor channels, it is recommended to use only one burst group (either even or odd burst group) to improve touch measurement time. In case of intra port configuration, both SNS and SNSK pins are configured on the same port. Using intra port configuration a maximum of 16 sensor channels can be configured on AT32UC3A/B/C device. Bursting sequence is parallel on all configured sensor channels whereas the scanning is done sequentially. 4.3 QMatrix method Using QMatrix library, it is possible to configure a maximum of 64 channels on AT32UC3C device. Both bursting and scanning of all configured sensor channels happens sequentially. More information on QTouch and QMatrix methods is available in the Atmel QTouch Library User Guide. 5. Compiler support For 32-bit Atmel AVR UC3 devices, the QTouch Library support is available for both GCC and IAR™ tool chains. Users can develop touch applications using either of these tool chains. 6. Firmware implementation This section describes how power consumption measurement is done for both QTouch and QMatrix methods. After initialization and configuration of sensors touch data measurement is performed. After completion of this, the device goes in to STATIC sleep mode. AST module is configured to keep track of the real time. AST alarm interrupt wakes up the device from sleep mode after every 40 milliseconds for touch data measurement. The following flow diagrams explain steps to implement touch solution on Atmel AT32UC3L and AT32UC3C devices for power consumption measurement. Atmel AVR32819: AVR UC3 Touch Selection Guide [APPLICATION NOTE] 42047A−AVR−11/2012 8 6.1 Flow diagram for the Atmel AT32UC3L device Atmel AVR32819: AVR UC3 Touch Selection Guide [APPLICATION NOTE] 42047A−AVR−11/2012 9 6.2 Flow diagram for the Atmel AT32UC3C device 7. Comparative analysis Both QTouch and QMatrix measurement methods have been implemented on Atmel AT32UC3L064 as well as on the Atmel AT32UC3C0512 devices. The comparative analysis is made with respect to below parameters: Atmel AVR32819: AVR UC3 Touch Selection Guide [APPLICATION NOTE] 42047A−AVR−11/2012 10 7.1 Power consumption Power consumption data of both Atmel AT32UC3L and AT32UC3C touch solutions is measured with the following clock configurations. • • • Oscillator0 (Osc0) is set to 12MHz and is configured as main clock In case of AT32UC3L device, DFLL is configured as clock source and main clock is set to operate at 48MHz In case of AT32UC3C device, PLL0 is configured as clock source and main clock is set to operate at 48MHz The subsequent sections provide power consumption figures of both QTouch and QMatrix touch solutions. Measurement setup for power consumption consists of: • • • 7.1.1 Atmel STK®600 kit Atmel QTouch and QMatrix sensor boards Multi-meter for current measurement QTouch method For the QTouch method two buttons, one slider and one rotor/wheel are configured using eight sensor channels. Table 7-1 shows the operating conditions of the Atmel AT32UC3L and AT32UC3C setups for the QTouch method. Table 7-1. Operating conditions. Parameter AT32UC3L064 AT32UC30512C Operating voltage(Vdd) 3.3V 3.3V CPU frequency (in MHz) 12 12 PBA clock frequency (in MHz) 12 12 CAT clock frequency (in MHz) 1 Not applicable Sampling capacitance(Cs) value (in nF) 22 22 Series Resistance (Rs) value (in kOhm) 1 1 AT32UC3L064 AT32UC3C0512 Table 7-2. Power consumption values with OSC0. Parameter Toolchain GCC IAR GCC IAR Measurement cycle duration(ms) 40 40 40 40 Active time(ms) 1 0.980 1.4 1.9 4.428 4.306 6.775 6.757 STATIC STATIC STATIC STATIC 39 39.02 38.6 38.1 Sleep current(mA) 0.145 0.145 0.287 0.287 Average current consumption over 1 measurement cycle (mA) 0.252 0.247 0.514 0.594 Active current(mA) Sleep mode Sleep time(ms) Atmel AVR32819: AVR UC3 Touch Selection Guide [APPLICATION NOTE] 42047A−AVR−11/2012 11 Table 7-3. Power consumption values with DFLL/PLL0. Parameter AT32UC3L064 Toolchain GCC IAR GCC IAR Measurement cycle duration (ms) 40 40 40 40 Active time (ms) 1 0.980 1.4 1.9 5.738 5.66 7.174 6.969 STATIC STATIC STATIC STATIC 39 39.02 38.6 38.1 Sleep current (mA) 0.145 0.145 0.287 0.287 Average current consumption over 1 measurement cycle (mA) 0.285 0.280 0.528 0.604 Active current (mA) Sleep mode Sleep time(ms) 7.1.2 AT32UC3C0512 QMatrix method For QMatrix method two buttons, one slider and one rotor/wheel are configured using 10 sensor channels. In this method, we use the SMP mode. Table 7-4 shows the operating conditions of the Atmel AT32UC3L and AT32UC3C setups for QMatrix method. Table 7-4. Operating conditions. Parameter AT32UC3L064 AT32UC30512C Operating voltage(Vdd) 3.3V 3.3V CPU frequency (in MHz) 12 12 PBA clock frequency (in MHz) 12 12 Generic clock for CAT (in MHz) 3 Not applicable CAT clock frequency (in MHz) 3 Not applicable Sampling capacitance(Cs) value (in nF) 10 10 Series Resistance (Rx) value on X-line (in kOhm) 1 1 Series Resistance (Ry) value on Y-line (in kOhm) 1 1 Sample Resistance (Rsmp) value (in kOhm) 470 470 Burst Length Value 64 64 AT32UC3L064 AT32UC3C0512 Table 7-5. Power consumption values with OSC0. Parameter Toolchain GCC IAR GCC IAR Measurement cycle duration(ms) 40 40 40 40 Active time(ms) 2 1.440 7.2 7.2 4.689 4.694 6.949 6.933 STATIC STATIC STATIC STATIC 38 38.56 32.8 32.8 Sleep current(mA) 0.145 0.145 0.287 0.287 Average current consumption over 1 measurement cycle (mA) 0.372 0.309 1.486 1.483 Active current(mA) Sleep mode Sleep time(ms) Atmel AVR32819: AVR UC3 Touch Selection Guide [APPLICATION NOTE] 42047A−AVR−11/2012 12 Table 7-6. Power consumption values with DFLL/PLL0. Parameter AT32UC3L064 Toolchain GCC IAR GCC IAR Measurement cycle duration(ms) 40 40 40 40 Active time (ms) 2 1.440 7.2 7.2 5.928 6.112 7.713 6.973 STATIC STATIC STATIC STATIC 38 38.56 32.8 32.8 Sleep current (mA) 0.145 0.145 0.287 0.287 Average current consumption over 1 measurement cycle (mA) 0.434 0.360 1.624 1.490 Active current (mA) Sleep mode Sleep time(ms) 7.2 AT32UC3C0512 Code and Data memory Atmel QTouch Library requires certain amount of code and data memory of the MCU. QTouch Library API implementation uses code memory whereas data memory is used for storing signals, references, and touch status and sensor information. The amount of data memory required depends upon the number of sensors and number of wheels/sliders configured in the application. Table 7-7 and Table 7-8 shows the code and data memory occupied by the QTouch Library for QTouch and QMatrix method. Table 7-7. Memory requirements – QTouch. Parameter AT32UC3L064 Memory segment Code (in bytes) Data (in bytes) Code (in bytes) Data (in bytes) GCC QTouch Library 6650 356 4328 291 IAR QTouch Library 6222 346 4326 291 Table 7-8. Memory requirements – QMatrix. Parameter 7.3 AT32UC3C0512 AT32UC3L064 AT32UC3C0512 Memory segment Code (in bytes) Data (in bytes) Code (in bytes) Data (in bytes) GCC QMatrix Library 8064 278 5574 566 IAR QMatrix Library 7156 266 5014 562 Usage of interrupt sources and peripheral modules Implementation of QTouch and QMatrix methods on the Atmel AT32UC3L device requires CAT module interrupt source. Also for power consumption measurement other interrupt sources are required. To get optimum power consumption values, clocks for all peripheral modules are disabled except for modules which are necessary. Table 7-9 and Table 7-10 shows configured interrupt sources and peripheral modules: Table 7-9. Configured interrupt sources and peripheral modules – QTouch. Parameter Interrupt source Peripheral module AT32UC3L064 AT32UC3C0512 CAT, AST AST CAT, AST, PDCA, PES AST, PEVC Atmel AVR32819: AVR UC3 Touch Selection Guide [APPLICATION NOTE] 42047A−AVR−11/2012 13 Table 7-10. Configured interrupt sources and peripheral modules – QMatrix. Parameter AT32UC3L064 AT32UC3C0512 CAT, AST AST CAT, AST, PDCA, PES, ACIFB AST, PEVC, ACIFA, TC0 Interrupt source Peripheral module 7.4 Sensor channel availability Table 7-11 shows the maximum number of sensor channels supported by both Atmel AT32UC3L and AT32UC3C devices for QTouch and QMatrix methods. Table 7-11. Sensor channel support. Parameter AT32UC3L064 Measurement method Maximum number of channels supported 8. AT32UC3C0512 QTouch QMatrix QTouch QMatrix 17 136 32 64 Recommended readings • • • Atmel QTouch Library User Guide Atmel AT32UC3L datasheet Atmel AT32UC3C datasheet Atmel AVR32819: AVR UC3 Touch Selection Guide [APPLICATION NOTE] 42047A−AVR−11/2012 14 9. Revision history Doc. Rev. Date Comments 42047A 11/2012 Initial document release Atmel AVR32819: AVR UC3 Touch Selection Guide [APPLICATION NOTE] 42047A−AVR−11/2012 15 Atmel Corporation Atmel Asia Limited Atmel Munich GmbH Atmel Japan G.K. 2325 Orchard Parkway Unit 01-5 & 16, 19F Business Campus 16F Shin-Osaki Kangyo Building San Jose, CA 95131 BEA Tower, Millennium City 5 Parkring 4 1-6-4 Osaki USA 418 Kwun Tong Road D-85748 Garching b. Munich Shinagawa-ku, Tokyo 141-0032 Tel: (+1)(408) 441-0311 Kwun Tong, Kowloon GERMANY JAPAN Fax: (+1)(408) 487-2600 HONG KONG Tel: (+49) 89-31970-0 Tel: (+81)(3) 6417-0300 www.atmel.com Tel: (+852) 2245-6100 Fax: (+49) 89-3194621 Fax: (+81)(3) 6417-0370 Fax: (+852) 2722-1369 © 2012 Atmel Corporation. All rights reserved. / Rev.: 42047A−AVR−11/2012 Atmel®, Atmel logo and combinations thereof, AVR®, Enabling Unlimited Possibilities®, QTouch®, STK®, and others are registered trademarks or trademarks of Atmel Corporation or its subsidiaries. Other terms and product names may be trademarks of others. Disclaimer: The information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to any intellectual property right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN THE ATMEL TERMS AND CONDITIONS OF SALES LOCATED ON THE ATMEL WEBSITE, ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDENTAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS AND PROFITS, BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Atmel makes no representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specifications and products descriptions at any time without notice. Atmel does not make any commitment to update the information contained herein. Unless specifically provided otherwise, Atmel products are not suitable for, and shall not be used in, automotive applications. Atmel products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life.