CE210291 – PSoC® 4 CapSense® One Button Objective This example demonstrates how to achieve very low power consumption for a single CapSense® button. Overview This code example showcases a one-button interface that sends sensor data to a host (CapSense-embedded Tuner GUI) using I2C communication and low-level APIs. The low-level APIs represent the lower layer of abstraction. A low-level API enables creating a design optimized for power consumption. Refer to the CapSense Component datasheet for more information on low-level APIs. Requirements Tool: PSoC® Creator™ 3.3 SP2 or higher Programming Language: C (ARM® GCC 4.9) Associated Parts: PSoC 4100, PSoC 4200, PSoC 4200 BLE, PRoC™ BLE, PSoC 4200M, PSoC 4200L, PSoC 4000S, and PSoC 4100S Related Hardware: CY8CKIT-042, CY8CKIT-042-BLE, CY8CKIT-044, CY8CKIT-046, CY8CKIT-041-40xx, and CY8CKIT041-41xx Design The project demonstrates the core functionality of the CapSense Component. This code example uses CapSense, EZI2C, and Global Signal Reference Components. Figure 1 shows the Component schematics of this project. The CapSense Component is configured with a one-button widget. The project uses the CapSense sigma delta (CSD) manual tuning mode with IDAC auto-calibration enabled. The EZI2C Component sends the sensor data and button touch position information to the external host or tuner via I2C. This code example implements two scan modes: Active and Look-for-Touch (LFT). When a touch is detected, the device switches to the Active mode. If a touch is not detected, the device changes the scan mode to LFT. The Global Signal Reference Component is configured as a watchdog timer (WDT), which is used to set the scan rates for Active and LFT modes. The firmware flow chart is shown in Figure 2. After establishing I2C communication between the device and Tuner GUI, you can observe the sensor data and touch detection. www.cypress.com Document No. 002-10291 Rev. ** 1 PSoC® 4 CapSense® One Button Figure 1. Component Schematics Figure 2. Firmware Flow Chart Start Initialize powerState to “SCAN” & scanMode to “Active” Initialize the EZI2C component and CapSense components Configure the button widget and initialize the watchdog timer Switch (powerState) PROCESS_DATA SLEEP SCAN DEEP_SLEEP Set powerState=”DEEP_SLEEP” and Process the Button widget YES Is CapSense Scan in progress? NO Is CapSense Scan in progress? NO Set powerState= ”PROCESS_DATA” Scan configured widget Is scanMode= ”ACTIVE” YES YES Is widget active? NO Is widget active? Set powerState=”SLEEP” Enterdeepsleep mode YES Put the device to sleep NO NO Reset the lftdebouce WDT interrupt occurred? NO YES Decrement the lftdebounce Set powerState=”SCAN” YES Configure WDT Is lftdebounce equal to 0? NO YES Set scanMode = “ACTIVE”and YES Set powerState=”SCAN” www.cypress.com Document No.002-10291 Rev. ** Configure WDT and Set scanMode= “ LFT” 2 PSoC® 4 CapSense® One Button Design Considerations The code example is designed for the PSoC 4000S family and the associated CY8CKIT-041-40xx kit. The design is easily portable to other PSoC 4 devices and kits, typically, by just changing the device and pin assignments. To switch from the CY8CKIT-041-40xx to other PSoC 4 Pioneer kits, follow these steps: 1. Select the appropriate device with a Device Selector called from the project’s context menu (Figure 3). Table 1 lists the device number for each Pioneer kit. Figure 3. Select Device Selector from Project’s Context Menu 2. When you select the device, PSoC Creator assigns pins automatically in the design wide resource file according to the device selected. Note: If the assigned pins are not as shown in Table 1 or you want to overwrite the existing pin assignment, doubleclick the project’s design wide resource file (Figure 4. Figure 4) in the Workspace Explorer window and assign the pins. Refer to the device datasheet for information on pin assignments. www.cypress.com Document No.002-10291 Rev. ** 3 PSoC® 4 CapSense® One Button Figure 4. Change Pin Assignments in Project’s Design Wide Resource File 3. Select 3.3 V as supply by using switch SW5. For other kits, refer to the respective kit user guide. 4. Build the project and ensure that there are no errors or warnings. Table 1. Pin Assignment for the PSoC 4 CapSense One Button Project Development kits CY8CKIT-042 CY8CKIT-042-BLE CY8CKIT-044 CY8CKIT-041-40xx (CY8C4245A XI-483) (CY8C4247LQIBL483) (CY8C4247A ZI-M485) (CY8C4045AZIS423) \Capsense: Cmod\ P4[2] P4[0] P4[2] \CapSense: Sns[0]\ (Button0_Sns0) P1[1] P2[1] \EZI2C: scl\ P3[0] \EZI2C: sda\ P3[1] Pin name www.cypress.com CY8CKIT-041-41xx (CY8C4146AZIS433) CY8CKIT-046 P4[1] P4[1] P4[2] P4[4] P0[1] P0[1] P0[6] P3[5] P4[0] P3[0] P3[0] P4[0] P3[4] P4[1] P3[1] P3[1] P4[1] Document No.002-10291 Rev. ** (CY8C4248B ZI-L489) 4 PSoC® 4 CapSense® One Button PSoC Creator Components Table 2 lists the PSoC Creator Components used in this example, as well as the hardware resources used by each Component. Table 2. List of PSoC Creator Components Component Component Version Hardware Resources CapSense v3.0 CSD block, an interrupt, and two pins EZI2C v2.40 Two pins Parameter Settings CapSense Figure 5 and Figure 6 show the settings for the CapSense Component. Figure 5. CapSense Component’s Basic Tab www.cypress.com Document No.002-10291 Rev. ** 5 PSoC® 4 CapSense® One Button Figure 6. CapSense Component Customizer Advanced Tab (CSD Settings) www.cypress.com Document No.002-10291 Rev. ** 6 PSoC® 4 CapSense® One Button EZI2C Component Figure 7 shows the settings for the EZI2C Component. Figure 7. EZI2C Component’s Basic Tab Operation After you build and install the example in the CY8CKIT-041-40xx kit, test the example by doing the following: Refer to the kit user guide to connect an ammeter to measure the device current. Touch the button and confirm that the device switches from LFT mode to Active mode by observing the increase in average current on the ammeter. Release the finger on the button and wait for a few seconds. Confirm that the device switches back to LFT mode by observing the reduction in average current on the ammeter (< 6 uA). By default, the tuner is disabled in the firmware. Enabling the tuner will execute additional code, which increases power consumption. To enable the tuner, set the macro TUNER_UPDATE_ENABLE to 1 in the main.c file. Then, build the project and program the device. Launch the Tuner GUI. Right-click the CapSense Component, as shown in Figure 8. Then, select Launch Tuner in the menu. www.cypress.com Document No.002-10291 Rev. ** 7 PSoC® 4 CapSense® One Button Figure 8. Launch Tuner GUI Navigate to Tools > Protocol Settings in the Tuner GUI menu to set up the I2C communication (Figure 9). Select the I2C port of the kit Choose the I2C address, sub-address size, and speed similar to the EZI2C configuration (Figure 7). Figure 9. Setting Up I2C Communication Click Connect; then, click Start (Figure 10). www.cypress.com Document No.002-10291 Rev. ** 8 PSoC® 4 CapSense® One Button Figure 10. Starting Communication After establishing I2C communication between the device and Tuner GUI, you can observe the sensor data and the button touch detection. Figure 11 and Figure 12 show scan data for the button sensor. Figure 11. Tuner: Widget View www.cypress.com Document No.002-10291 Rev. ** 9 PSoC® 4 CapSense® One Button Figure 12. Tuner: Graph View In the Active mode, the scan rate is fast (45 Hz), so power consumption will be approximately 30 uA. In LFT mode, the scan rate is slow (8 Hz), so power consumption will be less than 6 uA. When there is no I2C communication after some timeout, you will be able to observe few microampere (< 6 uA) at 25°C. Note: Power consumption is higher when I2C communication is in progress because the CPU is continuously awakened by the I2C transactions. Power consumption may vary depending on the kit. The ILO clock of WDT, which controls the scan rate, can vary ± 50 percent. Power consumption may also vary because temperature affects ILO. It is possible to trim ILO to maintain approximately the same power consumption over all temperatures by using ILO trimming. www.cypress.com Document No.002-10291 Rev. ** 10 PSoC® 4 CapSense® One Button Related Documents Table 3 lists relevant application notes, code examples, device datasheets, and PSoC Creator Component datasheets. Table 3. Related Documents Application Notes AN85951 AN85951 - PSoC 4 CapSense Design Guide Shows how to design capacitive touch sensing applications with the PSoC 4 AN79953 Getting Started with PSoC 4 Describes the PSoC 4, and how to build a first PSoC Creator project Code Examples CE210291 PSoC 4 CapSense One Button PSoC Creator Component Datasheets CapSense Supports various interfaces such as Button, Matrix Buttons, Slider, Touchpad, and Proximity Sensor EZI2C Supports one or two address decoding with independent memory buffers Global Signal Reference Supports watchdog timer configuration Device Documentation PSoC 4 Datasheets PSoC 4 Technical Reference Manuals Development Kit (DVK) Documentation CY8CKIT-041-41xx PSoC 4 S-Series Pioneer Kit CY8CKIT-042 PSoC 4 Pioneer Kit CY8CKIT-042-BLE Bluetooth® Low Energy (BLE) Pioneer Kit CY8CKIT-044 PSoC 4 M-Series Pioneer Kit CY8CKIT-046 PSoC 4 L-Series Pioneer Kit CY8CKIT-041-40xx PSoC 4 S-Series Pioneer Kit PSoC Resources Cypress provides a wealth of data at www.cypress.com to help you select the right PSoC device, and quickly and effectively integrate the device into your design. For a comprehensive list of resources, see KBA86521, How to Design with PSoC 3, PSoC 4, and PSoC 5LP. The following is an abbreviated list for PSoC 4: Overview: PSoC Portfolio, PSoC Roadmap Product Selectors: PSoC 1, PSoC 3, PSoC 4, or PSoC 5LP. In addition, PSoC Creator includes a device selection tool. Technical Reference Manuals (TRM): Provide detailed descriptions of the architecture and registers in each PSoC 4 device family. Development Kits: Datasheets: Describe and provide electrical specifications for the PSoC 4000, PSoC 4000S, PSoC 4100S, PSoC 4100, and PSoC 4200, PSoC 4xx7 BLE, PSoC 4200-M and PSoC Analog Coprocessor device families CapSense® Design Guide: Learn how to design capacitive touch-sensing applications with the PSoC 4 family of devices. Application Notes and Code Examples: Cover a broad range of topics, from basic to advanced level. Many of the application notes include code examples. PSoC Creator provides additional code examples. www.cypress.com CY8CKIT-040, CY8CKIT-041-40xx, CY8CKIT-04141xx, CY8CKIT-042, CY8CKIT-042-BLE, CY8CKIT-044 and CY8CKIT-048 PSoC Pioneer Kits are easy-to-use and inexpensive development platforms. These kits include connectors for Arduino™ compatible shields and Digilent® Pmod™ daughter cards. CY8CKIT-049 is a very low-cost prototyping platform for sampling PSoC 4 devices. CY8CKIT-001 is a common development platform for all PSoC family devices. The MiniProg3 device provides an interface for flash programming and debug Document No.002-10291 Rev. ** 11 PSoC® 4 CapSense® One Button PSoC Creator PSoC Creator is a free Windows-based Integrated Design Environment (IDE). It enables concurrent hardware and firmware design of systems based on PSoC 3, PSoC 4, and PSoC 5LP. See Figure 13. With PSoC Creator, you can: 1. 2. Drag and drop Components to build your hardware system design in the main design workspace 3. Configure Components using configuration tools Explore the library of 100+ Components Codesign your application firmware with the PSoC 5. Review Component datasheets hardware Figure 13. PSoC Creator Features www.cypress.com 4. Document No.002-10291 Rev. ** 12 PSoC® 4 CapSense® One Button Document History Document Title: CE210291 – PSoC® 4 CapSense® One Button Document Number: 002-10291 Revision ECN ** 5144063 www.cypress.com Orig. of Change AKSM Submission Date 02/19/2015 Description of Change New code example Document No.002-10291 Rev. ** 13 PSoC® 4 CapSense® One Button Worldwide Sales and Design Support Cypress maintains a worldwide network of offices, solution centers, manufacturer’s representatives, and distributors. To find the office closest to you, visit us at Cypress Locations. PSoC® Solutions Products ARM® Cortex® Microcontrollers cypress.com/arm cypress.com/psoc Automotive cypress.com/automotive PSoC 1 | PSoC 3 | PSoC 4 | PSoC 5LP Clocks & Buffers cypress.com/clocks Cypress Developer Community Interface cypress.com/interface Lighting & Power Control cypress.com/powerpsoc Memory cypress.com/memory PSoC cypress.com/psoc Touch Sensing cypress.com/touch USB Controllers cypress.com/usb Wireless/RF cypress.com/wireless Community | Forums | Blogs | Video | Training Technical Support cypress.com/support PSoC and CapSense are registered trademarks and PSoC Creator and PRoC 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 Fax Website : 408-943-2600 : 408-943-4730 : www.cypress.com © Cypress Semiconductor Corporation, 2016. This document is the property of Cypress Semiconductor Corporation and its subsidiaries, including Spansion LLC (“Cypress”). This document, including any software or firmware included or referenced in this document (“Software”), is owned by Cypress under the intellectual property laws and treaties of the United States and other countries worldwide. Cypress reserves all rights under such laws and treaties and does not, except as specifically stated in this paragraph, grant any license under its patents, copyrights, trademarks, or other intellectual property rights. If the Software is not accompanied by a license agreement and you do not otherwise have a written agreement with Cypress governing the use of the Software, then Cypress hereby grants you under its copyright rights in the Software, a personal, non-exclusive, nontransferable license (without the right to sublicense) (a) for Software provided in source code form, to modify and reproduce the Software solely for use with Cypress hardware products, only internally within your organization, and (b) to distribute the Software in binary code form externally to end users (either directly or indirectly through resellers and distributors), solely for use on Cypress hardware product units. Cypress also grants you a personal, non-exclusive, nontransferable, license (without the right to sublicense) under those claims of Cypress’s patents that are infringed by the Software (as provided by Cypress, unmodified) to make, use, distribute, and import the Software solely to the minimum extent that is necessary for you to exercise your rights under the copyright license granted in the previous sentence. Any other use, reproduction, modification, translation, or compilation of the Software is prohibited. CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS DOCUMENT OR ANY SOFTWARE, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress reserves the right to make changes to this document without further notice. Cypress does not assume any liability arising out of the application or use of any product or circuit described in this document. Any information provided in this document, including any sample design information or programming code, is provided only for reference purposes. It is the responsibility of the user of this document to properly design, program, and test the functionality and safety of any application made of this information and any resulting product. Cypress products are not designed, intended, or authorized for use as critical components in systems designed or intended for the operation of weapons, weapons systems, nuclear installations, lifesupport devices or systems, other medical devices or systems (including resuscitation equipment and surgical implants), pollution control or hazardous substances management, or other uses where the failure of the device or system could cause personal injury, death, or property damage (“Unintended Uses”). A critical component is any component of a device or system whose failure to perform can be reasonably expected to cause the failure of the device or system, or to affect its safety or effectiveness. Cypress is not liable, in whole or in part, and Company shall and hereby does release Cypress from any claim, damage, or other liability arising from or related to all Unintended Uses of Cypress products. Company shall indemnify and hold Cypress harmless from and against all claims, costs, damages, and other liabilities, including claims for personal injury or death, arising from or related to any Unintended Uses of Cypress products. Cypress, the Cypress logo, Spansion, the Spansion logo, and combinations thereof, PSoC, CapSense, EZ-USB, F-RAM, and Traveo are trademarks or registered trademarks of Cypress in the United States and other countries. For a more complete list of Cypress trademarks, visit cypress.com. Other names and brands may be claimed as property of their respective owners. www.cypress.com Document No.002-10291 Rev. ** 14