APPLICATION NOTE Atmel AT03816: QMatrix Control Panel for In-Home Display Atmel QTouch Features • • • • • • Supports up to seven QMatrix® keys SPI slave interface LEDs Provision for touch data ISP programming interface Powered from USB or external supply Introduction The reference design demonstrates implementation of seven QMatrix keys and SPI slave communication on Atmel® ATtiny4313 device. The SPI slave can be interfaced to any SPI master for reading the status of touch keys. The design consists of LED for visual indication. Figure 1. QMatrix Reference Design. 42179A−QTOUCH−09/2013 Table of Contents 1. Hardware ............................................................................................. 3 1.1 QMatrix Sense Circuitry .................................................................................... 4 1.2 LEDs ….. ........................................................................................................... 4 1.3 Communication Interface .................................................................................. 5 1.4 Power Supply .................................................................................................... 5 1.4.1 USB Supply ........................................................................................ 5 1.4.1.1 On-Board Regulator .......................................................... 5 1.4.2 External Supply ................................................................................... 5 1.5 ISP Interface ..................................................................................................... 5 1.6 GPIO Pin Mapping ............................................................................................ 6 2. Touch Data .......................................................................................... 7 3. SPI Communication Interface .............................................................. 8 4. Firmware .............................................................................................. 9 4.1 User Application Code Implementation ............................................................. 9 4.2 User Application Code Requirements ............................................................... 9 4.3 Application Code Flow ...................................................................................... 9 5. Schematic .......................................................................................... 10 6. PCB Layout ........................................................................................ 11 7. Bill of Materials (BOM) ....................................................................... 12 8. References ......................................................................................... 13 9. Revision History ................................................................................. 14 Atmel AT03816: QMatrix Control Panel for In-Home Display [APPLICATION NOTE] 42179A−QTOUCH−09/2013 2 1. Hardware The reference design hardware can be divided into the following major blocks. • • • • • QMatrix sense circuitry Power supply circuitry Communication interface Programming interface LEDs Figure 1-1 shows a block diagram view of the reference design. More details about each block are provided in the next sections. Figure 1-1. System Block Diagram. The reference design can also be configured to work independently in standalone mode without using SPI communication interface. This reference design is ideal for applications like In-home display systems for energy monitoring systems, control panel of a Smart Home system, portable network devices, and similar applications that use dedicated touch MCU. Atmel AT03816: QMatrix Control Panel for In-Home Display [APPLICATION NOTE] 42179A−QTOUCH−09/2013 3 1.1 QMatrix Sense Circuitry QMatrix sensor electrode consists of X-electrode (Transmitter) and Y-electrode (Receiver). To realize X by Y matrix of QMatrix sensors X+2Y+ 2 physical I/O pins are required. Figure 1-2 represents Atmel ATtiny4313 GPIO pin assignment to QMatrix sense circuitry. Figure 1-2. GPIO Pin Assignment. 1.2 LEDs LED D1 is controlled by GPIO PA1 of ATtiny4313 device. It sinks current from PA1-pin. LED D1 is configured to provide indication for sensor touch event detection. PA1 is multiplexed with debug clock (DBG_CLK) pin. Jumper provision on header J4 is given to switch between DBG_CLK and LED D1. So, when Debug functionality is selected in the application the LED indication for touch event does not work. LED D0 acts as power indication for the MCU. This is connected between supply line of the ATtiny4313 device and ground. Atmel AT03816: QMatrix Control Panel for In-Home Display [APPLICATION NOTE] 42179A−QTOUCH−09/2013 4 1.3 Communication Interface The SPI header (J1) on the board has Serial Peripheral Interface (SPI) communication lines. Figure 1-3 shows the communication header available on the PCB. Figure 1-3. Communication Header. SS MOSI MISO SCK 1K 1K 1K 1 R13 2 R15 3 R14 4 J1 SPI 1.4 Power Supply The reference design can be powered by using any of the following power supply sources. 1.4.1 USB Supply The reference board can be powered with the Mini-B USB header (U3) available on the board. The USB also acts as a source of power to the on-board voltage regulator (U1) and LED D1. 1.4.1.1 On-Board Regulator A linear dropout regulator (U1), which is mounted on the board, acts as a regulated power supply source to the Atmel ATtiny4313 device (U2). LED D1 is not powered by this regulator. 1.4.2 External Supply Provision is given on the board to provide supply in the range of 1.8V to 4.5V using external power sources like standard bench supply. Please refer to application note Atmel AT02259: QTouch® Schematic and Layout Checklist for more details on power supply considerations. 1.5 ISP Interface The ATtiny4313 device can be programmed using the ISP interface. The on-board ISP header can be used for programming the device. Figure 1-4 shows the ISP programming header available on the PCB. Figure 1-4. Programming Header. MISO SCK RESET R12 4.7K 1 3 5 J6 2 4 6 MOSI VDD GND ISP VDD Atmel AT03816: QMatrix Control Panel for In-Home Display [APPLICATION NOTE] 42179A−QTOUCH−09/2013 5 1.6 GPIO Pin Mapping Table 1-1. GPIO Pin Mapping. Function ATtiny4313 MCU pin Header - pin Debug Data(DBG_DATA) PA0 J4-Pin3 Debug Clock (DBG_CLK) PA1 J4- Pin2 Touch LED (D1) PA1 J4- Pin1 SS PB4 J1-Pin1 MOSI PB5 J1-Pin2 MISO PB6 J1-Pin3 SCK PB7 J1-Pin4 Note: The QMatrix design should comply with the design guidelines provided in Section 5.6.7.3 of the QTouch Library user guide. Atmel AT03816: QMatrix Control Panel for In-Home Display [APPLICATION NOTE] 42179A−QTOUCH−09/2013 6 2. Touch Data The firmware supports QDebug protocol for analyzing touch data using the QTouch Analyzer. The Atmel QT™600 USB interface board is used for communication interface between the reference board and QTouch Analyzer. Refer Figure 21 for interfacing details between reference board and QTouch Analyzer. Figure 2-1. Block Diagram View of Reference Board Interface with QTouch Analyzer. The reference board sends touch data using one way Bit-Bang SPI. User can only visualize the channel signal, reference and delta values on the QTouch Analyzer. One way Bit-Bang SPI does not allow modifying touch configurable parameters from QTouch Analyzer. GPIO pins PA0, PA1 of the Atmel ATtiny4313 are configured as debug data (DBG_DATA) and debug clock (DBG_CLK) pins respectively. PA1 is multiplexed with LED D1. So, select appropriate jumper settings on header J4 to use PA1 pin for touch data. To analyze touch data, power the reference board through QT600 USB interface board. For interfacing with QTouch Analyzer, necessary connections have to be made between reference board and QT600 USB interface board as shown in Table 2-1. Table 2-1. Connections between Reference Board and QT600 USB Interface Board. Interface Reference board QT600 USB interface board (QTOUCH DATA Header) One way SPI (Bit-Bang) GND (TEST POINT) SS (PIN5) DBG_DATA ( Pin3 of J4 header) MOSI(PIN6) DBG_CLK ( Pin2 of J4 header) SCK(PIN8) GND (Pin1 of J2 header) GND(PIN9) VCC (Pin2 of J2 header) VDD(PIN10) Atmel AT03816: QMatrix Control Panel for In-Home Display [APPLICATION NOTE] 42179A−QTOUCH−09/2013 7 3. SPI Communication Interface The Universal Serial Interface (USI) module on the Atmel ATtiny4313 supports both three-wire mode and two-wire mode. Three-wire mode is compliant to the SPI and it can be configured to work in SPI Mode0 or Mode1. The USI module is configured as SPI slave and operates in SPI Data Mode0 with 1MHz clock. The ATtiny4313 slave device is set to operate at 8MHz. The firmware consists of Slave Select (SS) pin functionality implementation. Figure 3-1 shows the necessary pin connections required between master and slave device for SPI communication. Figure 3-1. ATtiny4313 USI (SPI Slave) Module Connection Details. Atmel AT03816: QMatrix Control Panel for In-Home Display [APPLICATION NOTE] 42179A−QTOUCH−09/2013 8 4. Firmware The firmware for the reference design is only available for IAR™ tool chain. It consists of: • Custom QMatrix library that supports seven keys. The touch library does touch data acquisition and post processing sequentially on all configured sensors • • SPI slave driver to send status of the configured keys to Host device through SPI Interface LED control for LED D1 to indicate touch detection To analyze touch data using QDebug interface, select Debug mode in project configuration settings. 4.1 User Application Code Implementation The Slave Select (SS) functionality is implemented using external pin change interrupt on GPIO PB4. Host MCU periodically requests the slave for touch status by pulling the SS pin low. This will generate an external pin change interrupt. The firmware will update the touch status in SPI data register and enables SPI interrupt. Subsequently the host initiates the SPI data transfer to read the touch status. Host terminates SPI communication by pulling SS pin high. As soon as SS pin is pulled high, slave disables SPI interrupt and initiates touch acquisition process. The periodicity for touch acquisition will depend on how frequently the host MCU will request for touch status. 4.2 User Application Code Requirements 1. 2. 4.3 The touch acquisition periodic interval is set to 50ms using the macro QT_MEASUREMENT_PERIOD_MSEC in touch_config.h file. This macro needs to be adjusted if the SPI communication interval is different than 50ms. The current_time_ms_touch variable is updated based on this interval that is needed for time-based library operations such as drift compensation. This information is passed to the library as an argument to the qt_measure_sensors() API. After power-on reset the first touch acquisition takes around 150ms due to sensor calibration. The first SPI communication by host MCU after device power up should only be initiated after 150ms delay. Application Code Flow Figure 4-1. Application Code Flow. Atmel AT03816: QMatrix Control Panel for In-Home Display [APPLICATION NOTE] 42179A−QTOUCH−09/2013 9 X6 X5 X4 X3 X2 X1 X0 x y x y x y x y x y x y x y Y0 1k R 10 Ke y 7 Ke y 6 Ke y 5 Ke y 4 Ke y 3 Ke y 2 Ke y 1 YA 10nF C4 YB R5 R6 R7 R8 R3 R4 GND 470k R11 X2 X3 X4 X5 X0 X1 SM P RESET 19 1k 20 1k 1 DBG_CLK 2 DBG_DATA 3 1k 4 1k 5 1k 6 1k 7 8 GND 21 PA2(RESET/dw) VCC PD0(RXD) (UCSK/SCL/PCINT7)PB7 PD1(TXD) (MISO/DO/PCINT6)PB6 PA1(XTAL2) (MOSI/DI/PCINT5)PB5 PA0(XTAL1) (OC1B/PCINT4)PB4 PD2(XCK/INT0) (OC1A/PCINT3)PB3 PD3(INT1) (OC0A/PCINT2)PB2 PD4(T0) (AIN1/PCINT1)PB1 PD5(OC0B/T1) (AIN0/PCINT0)PB0 GND (ICP)PD6 PP U2 A T tiny431 3 -M U 18 17 16 15 14 13 12 11 10 9 J4 R9 1 2 3 1k C3 GND D B G_ CL K D B G_ D A T A X6 GND 100nF VDD 1 1 D0 2 Touch LED D1 V CC _5V 1k R1 330R 2 R2 Power LED GND SC K M IS O MOSI SS SM P YA YB GND TP1 J3 32 1 VC C VCC-3.3 C2 4µ7 VCC_5V VC C 0R R16 J5 2 1 GND VOU T _P A D VOUT SS MOSI M IS O SC K VDD R12 4.7K M IS O S CK RE S ET 1 3 5 1K 1K 1K IS P J6 1 2 3 4 5 6 7 8 9 R13 R15 R14 2 4 6 US B M in i B V BU S DD+ ID GND S H IE L D 1 S H IE L D 2 S H IE L D 3 S H IE L D 4 U3 LMS8117AMP-3.3 GND 1 V IN 4 2 1 2 3 4 J1 MOSI GND V CC _5V VCC -3.3 J2 H ead er ********** Provi s io n to co n n ect exte rnal po wer su p p ly J2 2 1 VC C GND VDD 0R R 17 C1 4µ7 VCC J5 H eader ********* F or po w er con sum p tio n me asure me n t VDD V O L TA G E R E G U LA TOR U1 3 F or ex tern al sup p ly: ******************* ‐ C onn ect P in 2& Pin3 ‐ Pr ov id e p owe r on J2 he ad er ‐ Ope n jum pers R16 , R 17 F or vo ltag e regul ato r sup ply: *************************** ‐ C onn ect P in1 & Pin2 J3 H ead er ********** F or U S B Su pp ly : *************** ‐ C onn ect P in2 & Pin3 VCC_5V 5. Schematic Figure 5-1. Schematic. Atmel AT03816: QMatrix Control Panel for In-Home Display [APPLICATION NOTE] 42179A−QTOUCH−09/2013 10 6. PCB Layout Figure 6-1. Top Layer. 1 2 3 4 1 1 2 2 2 3 1 2 1 6 7 10 10 5 3 1 6 4 2 9 1 3 2 1 1 2 1 8 2 Figure 6-2. Bottom Layer. 1 2 2 1 1 2 1 2 2 1 3 2 4 1 2 1 2 1 3 1 2 1 2 1 21 1 2 1 2 2 1 10 2 2 1 1 1 1 1 2 2 2 2 2 4 1 2 1 3 1 1 2 2 1 2 5 3 1 6 4 2 10 1 3 2 1 1 2 Atmel AT03816: QMatrix Control Panel for In-Home Display [APPLICATION NOTE] 42179A−QTOUCH−09/2013 11 Bill of Materials (BOM) 7. Table 7-1. BOM. Description Designator Qty. Value Ceramic capacitor, SMD 0603, X7R, 16V, ±10 % C1, C2 2 4µ7 Ceramic capacitor, SMD 0603, X7R, 50V, ±10 % C3 1 100nf Ceramic capacitor, SMD 0603, X7R, 50V, ±10 % C4 1 10nf LED, red, wave length = 575nm, SMD 0805, ±70° D0 1 Power LED LED, green, wave length = 575nm, SMD 0805, ±70° D1 1 Touch LED 1x4 pin header, 2.54mm pitch, THM J1 1 SPI header 1x2 pin male SMT header (terminal strip), 2.54mm pitch 5.84mm height J2 1 2 pin header 1x2 pin male SMT header (terminal strip), 2.54mm pitch 5.84mm height J5 1 2 pin header 1x3 pin header, 2.54mm pitch, THM J3 1 3 pin header 1x3 pin header, 2.54mm pitch, THM J4 1 3 pin header 2x3 pin header, 2.54 mm pitch, THM J6 1 ISP header Thick film resistor, SMD 0603, 1/10W, 1% R1, R3, R4, R5, R6, R7, R8, R9, R10, R13, R14, R15 12 1kΩ Thick film resistor, SMD 0603, 1/10W, 1% R2 1 330Ω Thick film resistor, SMD 0603, 1/10W, 1% R11 1 470kΩ Thick film resistor, SMD 0603, 1/10W, 1% R12 1 4.7kΩ Thick film resistor, SMD 0603, 1/10W, 1% R16, R17 2 0Ω 0.7mm PTH 1.27mm pad for test pin TP1 1 0.7mm PTH 1.27mm Pad 3.3V 1A low dropout linear regulator SOT223_4 U1 1 LMS8117AMP-3.3 AVR 8-bit RISC MCU U2 1 ATtiny4313-MU USB Mini-AB Connector, SMD U3 1 MUSB-05-F-AB-SM-A ® Atmel AT03816: QMatrix Control Panel for In-Home Display [APPLICATION NOTE] 42179A−QTOUCH−09/2013 12 8. References 1. 2. 3. 4. Atmel ATtiny4313 datasheet Atmel AT02259: QTouch Schematic and Layout Checklist, application note AVR319: Using the USI module for SPI communication on tinyAVR® and megaAVR® devices, application note Atmel QTouch Library User Guide Atmel AT03816: QMatrix Control Panel for In-Home Display [APPLICATION NOTE] 42179A−QTOUCH−09/2013 13 9. Revision History Doc. Rev. Date Comments 42179A 09/2013 Initial document release Atmel AT03816: QMatrix Control Panel for In-Home Display [APPLICATION NOTE] 42179A−QTOUCH−09/2013 14 Atmel Corporation Atmel Asia Limited Atmel Munich GmbH Atmel Japan G.K. 1600 Technology Drive Unit 01-5 & 16, 19F Business Campus 16F Shin-Osaki Kangyo Building San Jose, CA 95110 BEA Tower, Millennium City 5 Parkring 4 1-6-4 Osaki, Shinagawa-ku USA 418 Kwun Tong Road D-85748 Garching b. Munich 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 © 2013 Atmel Corporation. All rights reserved. / Rev.: 42179A−QTOUCH−09/2013 Atmel®, Atmel logo and combinations thereof, AVR®, Enabling Unlimited Possibilities®, megaAVR®, QTouch®, tinyAVR®, 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.