CE210289 PSoC®4 CapSense® Linear Slider.pdf

CE210289 – PSoC®4 CapSense® Linear Slider
Objective
This code example demonstrates the PSoC® 4 CapSense® linear slider operation.
Overview
This code example shows how to configure and use the CapSense linear slider. In this example, the linear slider sends sensor
data and slider position information to the embedded CapSense Tuner GUI using I2C communication. The code example
demonstrates the use of APIs, which enables quick design creation. The Tuner GUI provides quick and easy device
monitoring.
Requirements
Tool: PSoC Creator™ 3.3 SP2 or higher
Programming Language: C (ARM® GCC 4.9)
Associated Parts: PSoC 4200, PSoC 4200 BLE, and PRoC™ BLE
Related Hardware: CY8CKIT-042 and CY8CKIT-042-BLE
Design
This code example demonstrates the core functionality of the CapSense Component using the CapSense and EZI2C
Components. Figure 1 shows the Component schematics for this project.
The CapSense Component is configured with a 5-segment linear slider widget. The project uses the CapSense Sigma Delta
(CSD) manual tuning mode with IDAC auto-calibration enabled. The EZI2C Component sends sensor data and slider touch
position information to the external host/tuner via I2C. Figure 2 shows the firmware flow chart.
After establishing the I2C communication between the device and Tuner GUI, you can observe the sensor data and detect the
slider position when touching the slider.
Figure 1. Component Schematics
www.cypress.com
Document No. 002-10289 Rev. **
1
PSoC®4 CapSense® Linear Slider
Figure 2. Firmware Flow Chart
Start
1
Initialize EZI2C component
2
Initialize CapSense component
3
Scan all widgets
4
Is CapSense busy?
6
YES
5
Put the device to
sleep
NO
Process all widgets
7
8
Is any widget active?
NO
9
YES
Perform tasks based on scan
result
10
Run the Tuner
11
Start next scan
12
Design Considerations
The code example is designed for the PSoC 4200 family and the associated CY8CKIT-042 kit. The design is easily portable to
other PSoC 4 devices and kits, typically by simply changing the device and pin assignments.
To switch from the CY8CKIT-042 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.
2.
When you select the device, PSoC Creator assigns pins automatically for it in the Design-Wide Resource file.
Note: If the assigned component pins are not as shown in Table 1 or you want to overwrite existing pin assignments,
double-click the project’s Design-Wide Resource file 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-10289 Rev. **
2
PSoC®4 CapSense® Linear Slider
Figure 3. Select Device Selector from Project’s Context Menu
3.
Build the project and ensure that there are no errors or warnings.
Table 1. Pin Assignments for PSoC 4 CapSense Linear Slider Project
Development Kits
Pin Name
www.cypress.com
CY8CKIT-042
(CY8C4245AXI-483)
CY8CKIT-042-BLE
(CY8C4247LQI-BL483)/
(CYBL10563-56LQXI)
\Capsense: Cmod\
P4[2]
P4[0]
\CapSense: Sns[0]\
(LinearSlider0_Sns0)
P1[1]
P2[1]
\CapSense: Sns[1]\
(LinearSlider0_Sns1)
P1[2]
P2[2]
\CapSense: Sns[2]\
(LinearSlider0_Sns2)
P1[3]
P2[3]
\CapSense: Sns[3]\
(LinearSlider0_Sns3)
P1[4]
P2[4]
\CapSense: Sns[4]\
(LinearSlider0_Sns4)
P1[5]
P2[5]
Document No. 002-10289 Rev. **
3
PSoC®4 CapSense® Linear Slider
Development Kits
Pin Name
CY8CKIT-042
(CY8C4245AXI-483)
CY8CKIT-042-BLE
(CY8C4247LQI-BL483)/
(CYBL10563-56LQXI)
\EZI2C: scl\
P3[0]
P3[5]
\EZI2C: sda\
P3[1]
P3[4]
PSoC Creator Components
Table 2 lists the PSoC Creator Components used in this example, as well as the hardware resources used by each.
Table 2. PSoC Creator Components
Component
Hardware Resources
CapSense
CSD fixed blocks, interrupts, and 6 pins
EZI2C
2 pins
Parameter Settings
CapSense Component
Figure 4 and Figure 5 show the settings for the CapSense Component.
Figure 4. CapSense Component Basic Tab
www.cypress.com
Document No. 002-10289 Rev. **
4
PSoC®4 CapSense® Linear Slider
Figure 5. CapSense Component Customizer Advanced Tab (CSD Settings)
EZI2C Component
Figure 6 shows the settings for the EZI2C Component. Select the data rate as 400 kbps, as it is optimum for this application.
Set a sub-address size of 16 bits to allow the master to access data offsets between 0 and 65535.
Figure 6. EZI2C Component Basic Tab
www.cypress.com
Document No. 002-10289 Rev. **
5
PSoC®4 CapSense® Linear Slider
Operation
After you build and install the example in the CY8CKIT-042 kit, test the example by doing the following:
1.
Launch the Tuner GUI. Right-click the CapSense Component, as shown in Figure 7. Then select Launch Tuner in the
menu.
Figure 7. Launch Tuner GUI
2.
Navigate to Tools > Protocol Settings in the Tuner GUI menu to set up I2C communication (Figure 8).
a.
b.
Select the I2C device of the kit.
Set the I2C address, Sub-address size, and I2C Speed as done in the EZI2C configuration (Figure 6).
Figure 8. Setting Up I2C Communication
www.cypress.com
Document No. 002-10289 Rev. **
6
PSoC®4 CapSense® Linear Slider
3.
Click the Connect and then Start buttons (Figure 9).
Figure 9. Starting Communication
4.
After establishing I2C communication between the device and the Tuner GUI, touch the slider to observe the sensor data
and touch position.
The Tuner GUI displays the scanning results for all the sensing elements. Refer to Figure 10 and Figure 11.
Figure 10. Tuner: Widget View
www.cypress.com
Document No. 002-10289 Rev. **
7
PSoC®4 CapSense® Linear Slider
Figure 11. Tuner: Graph View
Related Documents
Table 3 lists relevant the application notes, code examples, PSoC Creator Component datasheets, device documentation, and
DVK documentation.
Table 3. Related Documents
Application Notes
AN79953
Getting Started with PSoC 4
Describes the PSoC 4 device and how to build your first PSoC Creator project
AN85951
PSoC 4 CapSense Design Guide
Shows how to design capacitive touch-sensing applications with PSoC 4
Code Examples
CE210289
PSoC4 CapSense Linear Slider
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
Device Documentation
PSoC 4 Datasheets
PSoC 4 Technical Reference Manuals
DVK Documentation
CY8CKIT-042 PSoC 4 Pioneer Kit
CY8CKIT-042-BLE Bluetooth® Low Energy (BLE) Pioneer Kit
www.cypress.com
Document No. 002-10289 Rev. **
8
PSoC®4 CapSense® Linear Slider
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.

CY8CKIT-040, CY8CKIT-041-40xx, CY8CKIT041-41xx, 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.

CY8CKIT-002 – The MiniProg3 device provides an
interface for flash programming and debugging.
PSoC Creator
PSoC Creator is a free, Windows-based Integrated Design Environment (IDE) that enables the concurrent hardware and
firmware design of systems based on PSoC 3, PSoC 4, and PSoC 5LP. See Figure 12. 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 12. PSoC Creator Features
www.cypress.com
4.
Document No. 002-10289 Rev. **
9
PSoC®4 CapSense® Linear Slider
Document History
Document Title: CE210289 - PSoC®4 CapSense® Linear Slider
Document Number: 002-10289
Revision
ECN
**
5142891
www.cypress.com
Orig. of
Change
AKSM
Submission
Date
02/22/2016
Description of Change
New code example.
Document No. 002-10289 Rev. **
10
PSoC®4 CapSense® Linear Slider
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
Automotive
cypress.com/go/automotive
psoc.cypress.com/solutions
Clocks & Buffers
cypress.com/go/clocks
PSoC 1 | PSoC 3 | PSoC 4 | PSoC 5LP
Interface
cypress.com/go/interface
Lighting & Power Control
cypress.com/go/powerpsoc
Memory
cypress.com/go/memory
PSoC
cypress.com/go/psoc
Touch Sensing
cypress.com/go/touch
USB Controllers
cypress.com/go/usb
Wireless/RF
cypress.com/go/wireless
Cypress Developer Community
Community | Forums | Blogs | Video | Training
Technical Support
cypress.com/go/support
CapSense and PSoC are registered trademarks and PRoC and PSoC Creator 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-10289 Rev. **
11