THIS SPEC IS OBSOLETE Spec Number: 001-41442 Spec Title: Capacitance Sensing - PC-Compatible USB CapSense Matrix Keyboard Sunset Owner: ANBA Replaced By: NONE Capacitance Sensing - PC-Compatible USB CapSense Matrix Keyboard AN2407 Author: Michael Macovetskyi, Ruslan Bachynskyy, Ryshtun Andrij Associated Project: Yes Associated Part Family: CY8C21434-24LKXI GET FREE SAMPLES HERE Software Version: PSoC Designer™ 4.3 SP2 Associated Application Notes: AN2233a, AN2292, AN2318, AN2352, AN2355 PSoC Application Notes Index Application Note Abstract This Application Note discusses construction, firmware communication, and considerations for a capacitive sensing matrixed keyboard using PSoC® CapSense. Table 1. Matrix Keyboard Specification Introduction Capacitive sensor keyboards are widely used in modern compact devices. Keyboard sensors can be connected to the microcontroller pin individually. However, such a connection scheme limits the number of sensors to the number of available sensing pins. For applications with only a small number of sensors, this is not an issue. For keyboards with many sensors, a new connection scheme must be devised to maximize the number of sensors while maintaining a small pin count. Creating a matrix of sensors can drastically raise the number of sensors in an application without increasing the pin overhead needed to control them. Characteristic Total Keys Quantity 69 (64 matrix + 5 separated) Matrix Structure 8x8 Sensor Dimension 11x11 mm Communication Interface I2C™ Overlay Thickness 1-6 mm PC Interface USB, via I2C-USB bridge Power Supply Voltage From USB 5 ± 0.25V PC Implementation Standard HID keyboard, no additional GUI required Figure 1. CapSense Matrix Keyboard Usage CapSense Matrix Keyboard I2C I2C-USB Bridge Keys Matrix Structure USB CY-3240-I2CUSB Laptop or PC This Application Note presents an example scheme for a matrixed capacitive sensing keyboard. A system block diagram is shown in Figure 1. Technical specifications for the matrixed presented here are listed in Table 1. October 14, 2011 Value keyboard Keyboard keys are organized into two groups. The first group is comprised of special function keys such as Shift, Ctrl, Alt keys. These keys are connected to PSoC pins individually and are scanned separately. The rest of the keys are organized in a rectangular 8-row, 8-column matrix. The 64 keys in this matrix represent alphanumeric keys as well as special keys such as WIN and EXC. Shift, Ctrl, Alt and some other keys can be activated at the same time as other keys. Scanning these keys separately allows correct detection of simultaneous sensor activation of these and keys in the general matrix. Document No. 001-41442 Rev. *A 1 AN2407 The sensor design implemented on the demonstration board increases the reliability of sensor activation detection. Each key consists of four segments. Segments opposite each other are connected to each other, creating two interwoven yet electrically distinct sensors for each key; there is a row sensor and column sensor for each key. Figure 2 illustrates the row (gray) and column (white) construction in two colors. This interwoven key structure means that a key represents activation on a row and a column at the same time. Figure 3. Key Press/Sensor Activation Examples Sensors COL1 Keys COL2 ROW1 ROW2 Figure 2. Matrix Keys Structure COL1 COL2 COL3 Key1 Key2 Key3 Key4 Key1 Key2 Key3 Key4 Key1 Key2 Key3 Key4 Key1 Key2 Key3 Key4 a) COL1 ROW1 COL2 ROW1 ROW2 ROW2 ROW3 b) COL1 COL2 ROW1 Firmware for activation detection completed an analysis of the row=column intersections. This method works well when only one key (one row and one column) is pressed at a time. If more than one key is pressed, false activations can occur due to multiple row-column activations. Figures 3a shows the activation scheme for a single pressed key. Figure 3b shows the activation scheme for a simultaneous-key press that can be detected by the controller. Figures 3c and 3d show different simultaneouskey presses that exhibit the same activation state and cannot be distinguished. Two keys that do not show either a row or a column sensor, when pressed, are viewed as four active keys. To avoid this phenomenon, keyboard design logic allows only one key to register as pressed by selecting only one row and column sensor at a time. The selected sensor is determined by using a sorting algorithm for signals. ROW2 c) COL1 COL2 ROW1 ROW2 d) Legend: Activated Row Sensor Detected as Not Pressed Activated Column Sensor Non-activated Row Sensor Detected as Pressed Non-activated Column Sensor Touched Sensor October 14, 2011 Document No. 001-41442 Rev. *A 2 AN2407 Keyboard Schematic and PCB Keyboard Firmware The proposed keyboard uses minimal external components and no mechanical keys. All the keys are capacitive sensors implemented on the PCB as copper pads. The proposed keyboard consists of a PSoC and several resistors and capacitors. The keyboard schematic is shown in Appendix A. Series resistors are placed on each sensing trace and close to the PSoC. These resistors decrease the influence of the RF noise caused by cell phones, microwave ovens, etc. For more information on this, see AN2292, “Layout Guidelines for PSoC CapSense” and AN3218, “EMC Considerations for PSoC CapSense.” The PSoC Designer project for this Application Note uses the CapSense Sigma Delta (CSD) User Module (UM) for capacitive sensing and the EzI2C UM to transmit the 2 results of the capacitive scans to the host though an I C interface. The firmware scans the individual and matrix sensors and sends the key codes to the I2C-USB bridge. Keys activation detection logic and sound generation is implemented in the firmware of the PSoC, not in the host or GUI. The CSD UM parameters are shown in Figure 4. Figure 4. CSD UM Parameters When multiple sensing elements are connected in parallel (sensors in rows and columns) the parasitic capacitance increases. A shield electrode is added behind the sensors to reduce this parasitic capacitance. The shield electrode is located on the bottom PCB layer. Some sensors (Space, Enter) have much larger area than other sensors. This difference causes large sensor-tosensor raw count variation, yielding different optimal modulator feedback resistor, R32 values. To balance raw counts for different sensors, resistor R27 is connected in parallel to the modulator capacitor when large area sensors are scanned. This connection is done in the firmware. For details on the modulator resistor and its impact on raw counts in CSD capacitive sensing, see AN2233a, “Capacitive Sensing Switch Scan/Theory and Operation.” For information on how to determine the value of R32 for other applications, see AN2355, “Calibrating CapSense Applications.” Speaker LS1 is used to emulate the „click‟ of a mechanical button. When key press is detected, PSoC generates a click signal on port P1[7] using a pulse width modulator (PWM). This signal is amplified through VT1 and played via speaker LS1. Connector J3 is used for ISSP and for I2C data transfer. The following requirements should be applied to board layout for optimal matrix keyboard performance. Reduce spacing between row and column sensors for each button (8-12 mill/0.2-0.3 mm). Keep the size and spacing of sensors consistent when possible. Use the physical key structure to determine the connection matrix structure for simplified layout. The Enter and Space keys are not special function keys as are Ctrl, Shift and Alt. But they are very large by the mechanical design. Therefore, these keys have individual PSoC pins and are scanned with individual threshold parameters. October 14, 2011 A sorting algorithm is used to detect which buttons are really pressed when multiple keys are active. When a finger is near a key, non-zero signals exist on several neighboring key row and column elements at the same time. The activation may be on a particular key (row and column), but other rows and columns exhibit some signal as well. The most upper element is used to detect which element is really being pressed by the sensor when multiple sensors show possible activation. After the active row and column are determined, the internal-use key code is derived using the following formula KeyCode=(RowMaxSenNum<<3)+ColMaxSenNum[15]-8; For Shift, Ctrl, Alt, Space, and Return key activation detection, CSD high-level APIs are used. After, the scanning key state is read from the CSD_baSnsOnMask[2] array. Document No. 001-41442 Rev. *A 3 AN2407 When finger is between two keys, false activation is possible. To avoid this, an additional selection algorithm and hysteresis are used. A key pressed event is detected only when the signal from this key is two times or more greater than the signal from neighboring keys. If it is not, the key activation state is not changed. Figure 7. HID Report Description USB HID Device To test and demonstrate the matrix keyboard unit, we use special firmware that was developed for Cypress, I2C to USB Bridge Kit CY3240-I2USB. The PC operating system detects the I2C-USB bridge as an HID keyboard. The bridge firmware converts internal key code to HID key codes. We used two different PSoC devices for sensor scanning (CY8C21434-24LKXI) and USB communication (CY8C24894-24LFXI). It is possible to implement this design using a single CY8C24784-24LKXI, which supports both CSD capacitive sensing and USB communication. When a user holds a finger on the button for a long time, the PC operating system automatically runs character auto-repeat. This is implemented by the operating system, not the I2C-USB bridge. The USB HID keyboard endpoint descriptors and HID report description are shown in Figure 5 and Figure 7. The Windows device manager screen is shown in Figure 6. Figure 5. USB HID Keyboard Endpoint Descriptors The sample text in Figure 8 was typed using the USB CapSense Matrix Keyboard. Figure 8. Sample Text Figure 6. Windows Device Manager The matrix keyboard PCB pictures are shown in Appendix B. Gerber files are included in the project archive for reference. The CapSense matrix keyboard with I2C-USB bridge photo is shown in Appendix C. October 14, 2011 Document No. 001-41442 Rev. *A 4 AN2407 Appendix A. Keyboard Schematic C_1 C_2 R16 200 C_3 R17 200 C_4 R18 200 C_5 R19 200 C_6 R20 200 C_7 R21 200 C_8 R23 200 R22 200 R8 200 1 ! 1 2 K1 1 @ 2 2 K2 1 # 3 2 K3 1 $ 4 2 K4 1 % 5 2 K5 4 3 4 3 4 3 4 3 4 3 4 1 Esc R10 200 3 4 3 4 3 R_1 1 ^ 6 2 K6 1 & 7 2 K7 2 K8 1 ~ 1 T 1 U 2 K13 4 3 1 Y 2 K12 4 3 4 1 R 2 K11 3 1 E 2 K10 4 3 4 1 W 2 K17 3 4 1 Q 2 R9 200 3 4 3 4 3 R_2 2 K14 2 K15 K16 1 TAB 1 G 1 J 2 K21 4 3 1 H 2 K20 4 3 4 1 F 2 K19 3 1 D 2 K18 4 3 4 1 S 2 K9 3 4 1 A 2 R12 200 3 4 3 4 3 R_3 2 K22 2 K23 K24 1 BACK 1 B 1 M 2 K29 4 3 1 N 2 K28 4 3 4 1 V 2 K27 3 1 C 2 K26 4 3 4 1 X 2 K41 3 4 1 Z 2 R14 200 3 4 3 4 3 R_4 2 K30 2 K31 K32 1 * 8 R11 200 1 ( 9 2 K36 1 ) 0 2 K37 1 __ _ 2 K38 1 + = 2 K39 1 PRINT 2 2 K40 1 Scroll Lock 2 K70 4 3 4 3 4 3 4 3 4 3 4 3 4 3 4 3 R_5 1 PAUSE 2 K71 K72 1 I 1 { [ 2 K45 K46 1 } ] 2 K47 1 Insert 1 2 K48 1 Home 2 4 3 4 3 4 3 4 3 4 1 P 2 K44 3 4 1 O 2 R13 200 3 4 3 4 3 R_6 PUp 2 K64 2 K65 K67 1 K K53 2 K54 1 " ' 1 | \ 2 K55 1 DELETE 1 PDown 2 K56 1 End 2 4 3 4 3 4 3 4 3 4 1 : ; 2 K52 3 4 1 L 2 R24 200 3 4 3 4 3 R_7 2 K42 2 K66 K68 K60 K61 1 2 2 K73 1 1 < 2 2 K43 4 3 4 3 4 3 4 3 4 1 1 K49 1 > > K59 ? / 2 3 4 1 > . 2 < 1 < , 3 4 3 4 3 R_8 2 2 K50 K51 ENTER SPACE SHIFT VCC R5 200 ALT1 ALT2 ALT R6 200 C3 0.1uF + C4 4.7uF SHIFT SHIFT1 SHIFT2 R7 200 R15 200 R26 200 SPACE SPACE ENTER CTRL Vss P0[3] P0[5] P0[7] Vdd P0[6] P0[4] P0[2] CTRL1 CTRL2 32 31 30 29 28 27 26 25 ENTER C_7 C_8 C_6 C_5 C_4 SHILD SPK LS1 C2 4.7uF R25 VT1 BC807-40 T/R SPK U1 CY 8C21434 P0[0] P2[6] P2[4] P2[2] P2[0] P3[2] P3[0] XRES 24 23 22 21 20 19 18 17 R_1 R_2 R_3 R_4 R_5 R_6 R_7 R_8 CTRL ALT C_1 C_2 C_3 1k 9 10 11 12 13 14 15 16 R1 5K1 VCC P0[1] P2[7] P2[5] P2[3] P2[1] P3[3] P3[1] P1[7] P1[5] P1[3] P1[1] Vss P1[0] P1[2] P1[4] P1[6] CEM-1206S 1 2 3 4 5 6 7 8 R3 2K2 VD1 STPS340U R27 6K2 C1 10nF J3 1 2 3 4 5 VCC ISSP/DATA October 14, 2011 Document No. 001-41442 Rev. *A 5 AN2407 Appendix B. Keyboard Layout Figure 9. PCB Top. Scale 50% Figure 10. PCB Bottom. Scale 50% Figure 10. PCB Silk Screen Top. Scale 50% October 14, 2011 Document No. 001-41442 Rev. *A 6 AN2407 Appendix C. Device Photo Figure 12. CapSense Matrix Keyboard with I2C-USB Bridge Photo October 14, 2011 Document No. 001-41442 Rev. *A 7 AN2407 Document History Document Title: Capacitance Sensing - PC-Compatible USB CapSense Matrix Keyboard – AN2407 Document Number: 001-41442 Revision ECN Orig. of Change Description of Change Submission Date ** 1541809 ANBA 10/04/2007 New spec. *A 3407058 ZINE 10/14/2011 Obsolete spec. In March of 2007, Cypress recataloged all of its Application Notes using a new documentation number and revision code. This new documentation number and revision code (001-xxxxx, beginning with rev. **), located in the footer of the document, will be used in all subsequent revisions. PSoC is a registered trademark of Cypress Semiconductor Corp. "Programmable System-on-Chip," PSoC Designer are trademarks of Cypress Semiconductor Corp. All other trademarks or registered trademarks referenced herein are the property of their respective owners. Cypress Semiconductor 198 Champion Court San Jose, CA 95134-1709 Phone: 408-943-2600 Fax: 408-943-4730 http://www.cypress.com/ © Cypress Semiconductor Corporation, 2007-2011. The information contained herein is subject to change without notice. Cypress Semiconductor Corporation assumes no responsibility for the use of any circuitry other than circuitry embodied in a Cypress product. Nor does it convey or imply any license under patent or other rights. Cypress products are not warranted nor intended to be used for medical, life support, life saving, critical control or safety applications, unless pursuant to an express written agreement with Cypress. Furthermore, Cypress does not authorize its products for use as critical components in life-support systems where a malfunction or failure may reasonably be expected to result in significant injury to the user. The inclusion of Cypress products in life-support systems application implies that the manufacturer assumes all risk of such use and in doing so indemnifies Cypress against all charges. This Source Code (software and/or firmware) is owned by Cypress Semiconductor Corporation (Cypress) and is protected by and subject to worldwide patent protection (United States and foreign), United States copyright laws and international treaty provisions. Cypress hereby grants to licensee a personal, non-exclusive, non-transferable license to copy, use, modify, create derivative works of, and compile the Cypress Source Code and derivative works for the sole purpose of creating custom software and or firmware in support of licensee product to be used only in conjunction with a Cypress integrated circuit as specified in the applicable agreement. Any reproduction, modification, translation, compilation, or representation of this Source Code except as specified above is prohibited without the express written permission of Cypress. Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress reserves the right to make changes without further notice to the materials described herein. Cypress does not assume any liability arising out of the application or use of any product or circuit described herein. Cypress does not authorize its products for use as critical components in life-support systems where a malfunction or failure may reasonably be expected to result in significant injury to the user. The inclusion of Cypress‟ product in a life-support systems application implies that the manufacturer assumes all risk of such use and in doing so indemnifies Cypress against all charges. Use may be limited by and subject to the applicable Cypress software license agreement. October 14, 2011 Document No. 001-41442 Rev. *A 8