CE58957 demonstrates how to implement the fade and toggle feature to the backlight LEDs of CapSense buttons.

Similar documents
The following table lists user modules used in this code example and the hardware resources occupied by each user module.

CE PSoC 4: Time-Stamped ADC Data Transfer Using DMA

Use the Status Register when the firmware needs to query the state of internal digital signals.

PSoC 1 I 2 C Bootloader

This optional pin is present if the Mode parameter is set to SyncMode or PulseMode. Otherwise, the clock input does not show.

Filter_ADC_VDAC_poll Example Project Features. General Description. Development Kit Configuration

Use the Status Register when the firmware needs to query the state of internal digital signals.

Comparator (Comp) Features. General Description. When to use a Comparator 1.60

Writing to Internal Flash in PSoC 3 and PSoC 5

AN SIO Tips and Tricks in PSoC 3 / PSoC 5. Application Note Abstract. Introduction

16-Bit Hardware Density Modulated PWM Data Sheet

CY7C603xx CYWUSB

Cypress HX2VL Configuration Utility Blaster User Guide

Voltage Reference (Vref) Features. General Description. Input/Output Connections. When to Use a Vref Voltage references and supplies

This optional pin is present if the Mode parameter is set to SyncMode or PulseMode. Otherwise, the clock input does not show.

CE56273 Associated Part Families: CY8C38xx/CY8C55xx Software: PSoC Creator Related Hardware: CY8CKIT-001 Author: Anu M D

HX2VL Development Kit Guide. Doc. # Rev. *A

PSoC 4 Low Power Comparator (LPComp) Features. General Description. When to Use a LPComp 2.0. Low input offset. User controlled offset calibration

DMX512 Receiver Datasheet DMX512Rx V 1.0. Features and Overview

HX2VL Development Kit Guide. Doc. # Rev. **

24-Bit Pseudo Random Sequence Generator Data Sheet

Shadow Registers Datasheet ShadowRegs V 1.1. Features and Overview

Programmable Threshold Comparator Data Sheet

LPF (Optional) CY8C24x93. Without LPF and ISR to 3* With LPF only** to 3* With ISR only to 3*

4 to 1 Analog Multiplexer Data Sheet

Reviving Bit-slice Technology in a Programmable Fashion

Cypress HX2VL Configuration Utility Blaster User Guide

THIS SPEC IS OBSOLETE

8 to 1 Analog Multiplexer Datasheet AMux8 V 1.1. Features and Overview

THIS SPEC IS OBSOLETE

For one or more fully configured, functional example projects that use this user module go to

Incremental ADC Data Sheet

Preliminary. Gas Sensor Analog Front End Datasheet GasSensorAFE V Features and Overview. This datasheet contains Preliminary information.

PSoC Creator Component Datasheet

This Application Note demonstrates an SPI-LIN slave bridge using a PSoC device. Demonstration projects are included.

CYClockMaker Programming Kit Guide CY3675. Doc. # Rev. **

THIS SPEC IS OBSOLETE

The color of the Clock component waveform symbol will change based on the clock's domain (as shown in the DWR Clock Editor), as follows:

GPIF II Designer - Quick Start Guide

CY3660-enCoRe V and encore V LV DVK Kit Guide

Clock Programming Kit

AN EZ-USB FX3 I 2 C Boot Option. Application Note Abstract. Introduction. FX3 Boot Options

CYClockMaker Programming Kit Guide CY3675. Doc. # Rev. *C

Programmable Gain Amplifier Datasheet PGA V 3.2. Features and Overview

Supported Devices: CY8C28x13, CY8C28x33, CY8C28x43, CY8C28x45, CY8C28x52, CY8C21x45, CY8C22x45, CY8C24x93. CY8C24x

Use the IDAC8 when a fixed or programmable current source is required in an application.

Base Timer Channel (BT) Features. General Description. When to Use a PDL_BT Component 1.0

FTG Programming Kit CY3670. Spec. # Rev. *C

Next-Generation Hot-Swap Controllers

User Guide. EZ-Click 2.0. Document # Rev *C

AN1090. NoBL : The Fast SRAM Architecture. Introduction. NoBL SRAM Description. Abstract. NoBL SRAM Operation

144-Mbit QDR -II SRAM 2-Word Burst Architecture

PSoC Programmer 3.12 Release Notes

Capable of adjusting detection timings for start bit and data bit

CapSense I 2 C/SPI Timer Flash RAM

PSoC Designer Release Notes

12-Mbit (512 K 24) Static RAM

Programmer User Guide

Comparator (Comp) Features. General Description. When to use a Comparator Low input offset. User controlled offset calibration

EZ-USB FX3 Development Kit Guide

CE95314 PSoC 3, PSoC 4, and PSoC 5LP EZI2C

PSoC Designer Quick Start Guide

PSoC 6 Current Digital to Analog Converter (IDAC7)

PSoC Blocks. CY8C20xx6/6A/6AS/6H/6L, CY8C20xx7/7S, CY7C643xx, CY7C604xx, CYONS2xxx, CYONSxNxxxx, CYRF89x35, CY8C20065, CY8C24x93, CY7C69xxx

Use the Status Register when the firmware needs to query the state of internal digital signals.

This section describes the various input and output connections for the Voltage Fault Detector.

This section describes the various input and output connections for the SysInt Component.

This optional pin is present if the Mode parameter is set to SyncMode or PulseMode. Otherwise, the clock input does not show.

This input determines the next value of the output. The output does not change until the next rising edge of the clock.

Multifunction Serial Interface (PDL_MFS) Features. General Description. When to Use a PDL_MFS Component. Quick Start 1.0

Digital Logic Gates. Features. General Description. Input/Output Connections. When to Use a Logic Gate. Input 1. Input 2. Inputs 3-8 * 1.

Automatic reload of the period to the count register on terminal count

CY8C29/27/24/23/21xxx, CY8CLED02/04/08/16, CY8CLED0xD, CY8CLED0xG, CY8C28x45, CY8CPLC20, CY8CLED16P01, CY8C28xxx. Main UM

Release Notes SRN065 PSoC Programmer Version Release Date: November 9, 2009

W H I T E P A P E R. Timing Uncertainty in High Performance Clock Distribution. Introduction

Use the Status Register when the firmware needs to query the state of internal digital signals.

CE CY8CKIT-042-BLE F-RAM Data Logger

PSoC 4 Current Digital to Analog Converter (IDAC)

32-Bit Counter Datasheet Counter32 V 2.5. Features and Overview

4K x 8 Dual-Port Static RAM and 4K x 8 Dual-Port SRAM with Semaphores

Setting Oscillation Stabilization Wait Time of the main clock (CLKMO) and sub clock (CLKSO)

FM3 MB9B100A/300A/400A/500A Series Inverter Solution GUI User Guide

Bootloader project - project with Bootloader and Communication components

EZ I 2 C Slave. Features. General Description. When to use a EZ I 2 C Slave 1.50

PSoC Programmer Release Notes

PSoC Creator Quick Start Guide

PSoC 4 Voltage Comparator (Comp) Features. General Description. When to Use Comparator Low input offset. User controlled offset calibration

Libraries Guide. Arithmetic Libraries User Guide. Document #: Rev. *A

One 32-bit counter that can be free running or generate periodic interrupts

This section describes the various input and output connections for the Voltage Fault Detector.

Digital Multiplexer and Demultiplexer. Features. General Description. Input/Output Connections. When to Use a Multiplexer. Multiplexer 1.

THIS SPEC IS OBSOLETE

F²MC-8FX Family MB95200H/210H Series Capacitance Touch Sensor

CY3280-BBM Universal CapSense TM Prototyping Module Kit Quick Start

The AMuxSeq is capable of having between 2 and 32 analog inputs. The paired inputs are present when the MuxType parameter is set to "Differential.

PSoC Programmer Release Notes

AN PSoC 3 and PSoC 5 SFF-8485 Serial GPIO (SGPIO) Initiator Interface. Application Note Abstract. Introduction

Optional Pause Pulse for constant frame length of 282 clock ticks

1-Mbit (64K x 16) Static RAM

Voltage Fault Detector (VFD) Features. General Description. Input/Output Connections. When to Use a VFD. Clock Input 2.30

Transcription:

Objective CapSense Sigma Delta (CSD) with LED Backlight Fading on CY8C24x94 CE58957 Code Example Name: Example_CSD_BacklightFading_24x94 Programming Language: C Associated Part Families: CY8C24x94 Software Version: PSoC Designer TM 5.1 SP 2 Build 2306 Related Hardware: CY3280-24x94 UCC and CY3280-BSM Author: Arvind M CE58957 demonstrates how to implement the fade and toggle feature to the backlight LEDs of CapSense buttons. Overview The backlight LED of a CapSense button indicates the ON/OFF status of that button. Backlight LED switches ON/OFF alternatively (toggling feature) each time you activate the button. Normal backlight LEDs switch between on and off states immediately. However, it looks stylish when the backlight LED switches from OFF to ON state slowly with smooth increments in brightness (fading feature). If a PWM is used to drive the LEDs, brightness is controlled and the fading effect is seen. This code example implements the toggling and fading feature of backlight LEDs. The code example incorporates CapSense (CSD) and Timer (to generate PWM signal) user modules. You can easily adjust the fading duration and LED ON/OFF state duty cycles. The toggling and fading feature can be added to your code example using the firmware in this code example. User Module List and Placement The following table lists user modules used in this code example and the hardware resources occupied by each user module. User Module CSD (with PRS8 and clock prescaler) Timer8 SHADOWREGS_P0 SHADOWREGS_P1 SHADOWREGS_P2 SHADOWREGS_P3 Placement ACB01, DBB00, and DBB01 DBB01 None None None None User Module Parameter Settings The following tables show the user module parameter settings for each of the user modules used in the code example. CSD Finger Threshold 100 Noise Threshold 40 Baseline Update Threshold 100 Sensors Autoreset Disabled When the Difference Count crosses Finger Threshold plus Hysteresis, the button is in ON condition. If the Difference Count is less than this, it is treated as noise; BaseLine Update Algorithm puts it into the Update Bucket. When the noise increases, the Update Bucket is filled; every time it crosses this threshold, baseline is incremented by 1 and the algorithm continues. When the parameter is set to disabled, the baseline is updated only when raw count and baseline difference is below the Noise Threshold. Hysteresis 15 It takes care of false ON and OFF situations when the button is pressed. Debounce 3 Negative Noise Threshold 20 If the Difference Count is more than Finger Threshold for less than 'Debounce' number of samples, it is not taken as a button press. If the Raw Count is below baseline and the Difference Count is more than this threshold, the baseline does not update. September 12, 2011 Document No. 001-58957 Rev. *B 1

CSD Low Baseline Reset 50 Scanning Speed Normal Decides the speed of scanning process. If the Raw Count is below baseline and Difference Count is more than Negative Noise Threshold for the samples given by this parameter, the baseline is reset to new Raw Count. Resolution 12 Higher the resolution, higher is the sensitivity. Ref Value 2 This parameter sets the comparator reference value. PRS polynomial Short This parameter decides the repeat period of PRS. Prescaler Period 4 This parameter sets the prescaler period register and determines the precharge switch output frequency. Shield Electrode Out None Shield electrode is not used in this code example. Note These parameters for CSD are set to work without overlay on the CapSense buttons. For overlay on CapSense buttons in the board, use the calibration flowchart provided at the end of this document to set the CSD parameters. Timer8 Clock CPU_32_KHz Internal 32 khz oscillator output is selected as clock input to the timer. Capture Low A rising edge on this input causes the Count register to be transferred to the Compare register. This feature is not required in this application and is held at constant low. Terminal Count Out None This is auxiliary counter output. This output is not routed to any pin. Compare Out None This output is also not routed to any pin. Period 3 Compare Value 0 This value is loaded into the Period register. The period is automatically reloaded when the timer reaches zero. This value is loaded into the Compare register and sets the count point in the timer period when a compare event is triggered. Compare Type Less Than Or Equal This parameter sets the compare function type "less than" or "less than or equal". Interrupt Type Terminal Count Terminal Count event is selected as the interrupt trigger source. Clock Sync TC_Pulse Width Sync to SysClk Full Clock This parameter is used to control clock skew and ensure proper operation when reading and writing PSoC block register values. Refer the user module data sheet for more information. This parameter provides the means of specifying whether the terminal count output pulse is one clock cycle wide or one half clock cycle wide. Invert Capture Normal When "Normal" is selected, the capture input is active-high. SHADOWREGS_P0 Shadow Port Port_0 This parameter selects the port for which a shadow register is created. SHADOWREGS_P1 Shadow Port Port_1 This parameter selects the port for which a shadow register is created. SHADOWREGS_P2 Shadow Port Port_2 This parameter selects the port for which a shadow register is created. SHADOWREGS_P3 Shadow Port Port_3 This parameter selects the port for which a shadow register is created. Note Shadow registers are required for all ports in which LEDs are connected. This generates macros to drive the LEDs and avoid changes in the code when changing the LED port pin. September 12, 2011 Document No. 001-58957 Rev. *B 2

Global Resources Important Global Resources Power Setting [Vcc/SysClk frequency] 5.0V/24 MHz Selects 5V operation and 24 MHz SysClk CPU_Clock SysClk/2 Selects 12 MHz as CPU clock Note Other parameters are left at their default value. Hardware Connections The schematic diagram for the code example is as follows. CY3280-24x94 Universal CapSense Controller board along with CY3280-BSM Simple Button Module Kit is suitable for this code example. Cmod is connected to P0[5] and Rb is connected to p3[1]. CY3280-BSM kit has 10 CapSense buttons with 10 backlight LEDs. All backlight LEDs are active low type. A 560 ohm resistor is connected in series with each CapSense button to reduce RF interference. One Kohm resistor in series with LED limits the current flow. CapSense buttons pin assignment used in this code example: Button 0 P0[3] Button 1 P1[2] Button 2 P2[2] Button 3 P2[7] Button 4 P1[4] Button 5 P0[2] Button 6 P2[1] Button 7 P1[6] Button 8 P0[6] Button 9 P2[0] September 12, 2011 Document No. 001-58957 Rev. *B 3

Backlight LEDs pin assignment used in this code example: LED 0 P0[1] LED 1 P3[3] LED 2 P2[4] LED 3 P2[5] LED 4 P1[3] LED 5 P2[6] LED 6 P2[3] LED 7 P3[0] LED 8 P0[4] LED 9 P3[2] Operation On reset, all hardware settings from the device configuration are loaded into the device and main.c is executed. The following operations are performed by firmware. Initialization In the beginning of main(), the global interrupt is enabled; then CapSense user module is initialized. FadingStart() function is called which declares various variables and starts the timer required for fading. Infinite while loop After initialization, in an infinite while loop all CapSense buttons are scanned, baselines are updated, and the UpdateFading() function is called. The UpdateFading() function checks the status of all CapSense buttons and calculates status (ON/OFF) of all the backlight LEDs. Then it calculates the duty cycles of all LEDs and determines which LED must be faded. It loads the calculated duty cycles into an array called bdcycle[]. This array is used by timer ISR to generate the PWM signals on all LED port pins. Only one LED fades at a time. For example, when you touch a CapSense button, its backlight LED starts fading. While it is fading, if you touch another button, the previous LED immediately goes to end of fading and the current LED starts fading. PWM generation using timer ISR Initially all LED output pins are set to high (assuming active low LEDs). The FadeTimer generates interrupts periodically at every 125 µs interval. Each time the interrupt is generated, execution jumps to an ISR. In the ISR, a variable named bdcctr is incremented by one. Eventually, when the variable value reaches 100, it is reinitialized back to zero. Each time bdcctr is incremented, its value is compared with all the elements of bdcycle[] array. If any array element is equal to bdcctr, the corresponding LED output pin is set to low. This generates different PWMs on different pins. Controlling fading parameters Duty cycle of LEDs during ON/OFF state is set using HIGHDC and LOWDC parameters. For example, if HIGHDC = 80 and LOWDC = 5, all LED outputs are at 5% duty cycle initially. When a CapSense button is touched, its backlight LED output fades from 5% to 80% duty cycle and vice versa when the button is touched again. These two parameters are found in BackLightControl.h file of code example. When fading, the duty cycle changes in steps. The step size can be changed to change the fading time. Lower the step size, longer is the fading time. Lesser step size has smoother fading. The step size parameters are found in BackLightControl.h file. You can also set the fade time by setting the time period of a step (in multiples of 12.5 ms). Higher step time causes longer fading time. Step time parameter is found in BackLightControl.inc file. You can select whether the LEDs are active high or active low type. This parameter is located in BackLightControl.inc file. September 12, 2011 Document No. 001-58957 Rev. *B 4

Adding Backlight Fading Feature to a New Code Example If you have your application code example already developed and you intend to include backlight fading, then follow the below procedure Prerequisites: The CapSense User Module should be placed and renamed as Capsense. CapSense buttons should be assigned to pins using the CapSense wizard. Number of CapSense buttons should not exceed 16. The Capsense User Module should be tuned. Procedure: Place a Timer8 User Module and rename it as FadeTimer. Set the parameters of FadeTimer to the following values: Clock = CPU_32_KHz Capture = Low TerminalCountOut = None CompareOut = None Period = 3 CompareValue = 0 CompareType = Less Than Or Equal InterruptType = Terminal Count Clock Sync = Sync To SysClk TC_PulseWidth = Full Clock InvertCapture = Normal In the Pinout window in device editor, set all the pins that are used for backlight LED output to Strong drive mode. Rename the LED port pins as LED0, LED1, LED2, and so on. For example, consider that there are four CapSense buttons: SW0, SW1, and SW3 have backlight LEDs, but SW2 does not have backlight LED. Then, rename the three LED port pins as LED0, LED1, and LED3. Place SHADOWREGS user modules to all LED ports. For example, if the three LEDs are connected to P1[3], P0[5], and P1[7] then SHADOWREGS must be placed for port1 and port0. Create four new files and include in the code example: BackLightFadingINT.asm, BackLightFading.c, BackLightControl.inc, and BackLightControl.h Copy the contents of these four files from Example_CSD_BacklightFading_Toggle_24x94 code example and paste them into your code example. In main.c file of your code example include BackLightControl.h (#include BackLightControl.h ). In main(), after calling Capsense_Start() API call the function FadingStart() to initialize the timer and other variables used for fading. In while(1) loop, after calling Capsense_ScanAllSensors() and Capsense_UpdateAllBaselines() APIs, call the function UpdateFading(). Now generate the code example. Open FadeTimerINT.asm file. Under _FadeTimer_ISR: type an assembly language instruction Ljmp Fading. Build the code example and download it to the device. September 12, 2011 Document No. 001-58957 Rev. *B 5

CSD Calibration For optimum performance, the CSD parameters must be tuned with the actual CapSense hardware and overlay. The following flowchart shows the steps for calibrating CSD. 1. Start with the default settings of the CSD User Module. 2. Using I 2 C-USB bridge or UART and the actual hardware and overlay, capture the raw counts, baseline, and difference counts for the sensors. 3. Coarse Tuning: Check if the Signal-to-Noise Ratio (SNR) is greater than 5. If SNR is less than 5, increase SNR by following recommended PCB guidelines, increasing the CSD resolution and reducing its scan speed. For PCB guidelines, refer application note AN2394, CapSense Best Practices. For details about SNR, refer application note AN2403, Capacitance Sensing - Signal-to-Noise Ratio Requirement for CapSense Applications. 4. Fine Tuning: Check if SNR is greater than 8. If less than 8, reduce the Ref Value parameter to increase SNR. 5. Check if total scan time for all sensors meet the requirement. Otherwise, reduce resolution and/or increase scan speed. These parameters also affect SNR, so go back to step 3. With a couple of passes, arrive at the optimum resolution and scan speed parameters that produce the best SNR and the desired scan time. 6. Capture the difference counts when the button is activated. Set the finger threshold parameter to 75% of the peak. 7. Set the noise threshold to 40% of the peak value. 8. Set the negative noise threshold to half the noise threshold. 9. Set finger thresholds for individual sensors, if necessary. To do this, write to the CSD_baBtnFThreshold array in firmware. September 12, 2011 Document No. 001-58957 Rev. *B 6

10. Set the baseline update threshold according to requirements. The frequency to update the baseline must be determined based on the code example. The baseline must be a slow moving reference that helps to reduce the affects of noise and temperature on the capacitive sensor. Fast update baseline rates: This can create problems if a user moves a finger SLOWLY to the button. This is called Baselining out the finger. Slow update baseline rates: This can leave the buttons vulnerable to temperature fluctuations and can lead to Button Lock. 11. Set AutoReset and Debounce parameters as required. Refer the CSD User Module data sheet for details of these parameters. 12. For all other parameters, refer the user module data sheet. September 12, 2011 Document No. 001-58957 Rev. *B 7

Document History Document Title: CapSense Sigma Delta (CSD) with LED Backlight Fading on CY8C24x94 CE58957 Document Number: 001-58957 Revision ECN Orig. of Change Submission Date ** 2858737 ARVM 02/05/2010 New example project Description of Change *A 3135773 ARVM 01/12/2011 Changes made in the example project 1) Added more comments to the f/w code 2) Updated to work with latest PD version Changes made in the document 1) Changed software version to "PD5.1 (FCS) Build 1875" 2) Minor modifications in "Adding Backlight Fading Feature to a New Project" section. *B 3368905 ZINE 09/12/2011 Updated software version to PSoC Designer TM 5.1 SP 2 Build 2306. Changed all example project to code example. PSoC is a registered trademark of Cypress Semiconductor Corp. "Programmable System-on-Chip" and 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, 2010-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. September 12, 2011 Document No. 001-58957 Rev. *B 8