Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Capacitance Sensing - Migrating from
                                                                                    C...
AN2393




                                                                 Figure 1. CSA Block Diagram

                 ...
AN2393




BaselineUpdateRate                                                      Figure 3. CSA Waveform seen at CMod wit...
AN2393




                                              Figure 4. CSA Block Diagram of Phase 1

                         ...
AN2393




                                                Figure 6. CSA Block Diagram with Equivalent Resistor

         ...
AN2393




Region 2                                                                      counts exceeds the finger thresho...
AN2393




                                                                           Converting/Creating a Project with C...
AN2393




BaselineUpdateThreshold                                           Hysteresis
CSA uses a quot;bucketquot; method...
AN2393




LowBaselineReset                                                   Table 3. CSR and CSA UM APIs (Continued)
   ...
AN2393




                                                                    External Components
The CSA_bIsAnySensorAct...
AN2393




Summary
The PSoC Mixed-Signal Array is a configurable array of digital and analog resources, Flash memory and R...
AN2393




Appendix A
Quick Migration Guide
This appendix documents the changes needed to convert a CSR CapSense project t...
AN2393




5.   Software changes:

            Description                                      CSR                       ...
AN2393




Appendix B
CSR and CSA Code Size
This appendix documents the RAM and ROM code size for CSR and CSA APIs and var...
AN2393




About the Author
 Name:                       Ted Tsui
 Title:                      Applications Engineer Sr
 C...
Upcoming SlideShare
Loading in …5
×

Capacitance Sensing - Migrating from CSR to CSA

1,775 views

Published on

This application note describes migrating from the CapSense Relaxation Oscillator (CSR) User Module (UM) to the CapSense
Successive Approximation (CSA) UM.

Published in: Technology
  • This is an interesting article, if you are looking for detail information you can check out http://www.cypress.com/
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

Capacitance Sensing - Migrating from CSR to CSA

  1. 1. Capacitance Sensing - Migrating from CSR to CSA AN2393 Author: Ted Tsui Associated Project: No Associated Part Family: CY8C20x34, CY8C21x34, CY8C24x94 GET FREE SAMPLES HERE Software Version: PSoC Designer™ 4.34 Associated Application Notes: AN2041, AN2233b, AN2292, AN2355, AN2403, AN14459 PSoC Application Notes Index Application Note Abstract This application note describes migrating from the CapSense Relaxation Oscillator (CSR) User Module (UM) to the CapSense Successive Approximation (CSA) UM. Introduction Change Summary The CSA UM uses a fundamentally different front-end algo- The CSA method uses a different front end from the earlier rithm for capacitive sensing than the CSR UM. Circuit and implementation of CSR. Other differences include improve- algorithm changes have yielded improvements over CSR in ments to the UM parameters and APIs to make the operation noise immunity, sensitivity, and API usability. This Application of the UM more flexible and code development more intuitive. Note describes the differences between CSA and CSR and For increased sensitivity an additional external capacitor can provides instructions for migrating CapSense projects from be used in CSA operation. CSR to CSA. Methodology For more detail on capacitive sensing theory and operation, The biggest difference between CSA and CSR user modules including details and equations for CSA that are not pre- is that the CSR uses a relaxation oscillator for capacitive sented here, see AN2233b, quot;Capacitive Sensing Theory and sensing and the CSA uses a switched capacitor. Both meth- Operationquot; and the CSA UM data sheet in PSoC Designer. ods connect a sensor capacitor onto the analog global bus to For comparative information on the capacitive sensing meth- scan for capacitance changes. The technique for the scan is ods supported by PSoC® and their associated UMs, see where the two methodologies differ. In addition to the sensor AN14459, quot;Capacitive Sensing Method and Device Selector capacitor, the CSA uses an internal capacitor (CInternal) and Guide.quot; an optional external modification capacitor (CMod). The block diagrams of CSA and CSR appear in Figure 1 and Figure 2 For more detail on calibration and tuning of the CSA UM, on page 2, respectively. including hardware and software parameters, see AN2355, quot;Calibration of Capacitive Sensing using PSoC CapSense Devices.quot; More explanation of APIs, parameters, and example code is available in the CSA UM data sheet included with the latest version of PSoC Designer. Be sure to update PSoC Designer by visiting the quot;Software and Driversquot; section of www.cypress.com. November 28, 2007 Document No. 001-15237 Rev. *A 1 [+] Feedback
  2. 2. AN2393 Figure 1. CSA Block Diagram VDD LPF VREF EN 16-Bit Data Ø1 Counter Processing CX Ø2 CMod CInternal Oscillator Figure 2. CSR Block Diagram VDD EN 8-Bit PWM 16-Bit Data VREF EN Timer Processing CX SW1 Oscillator For more information on the relaxation oscillator, see Applica- FingerThreshold tion Note AN2233b, quot;Capacitive Sensing Theory and Opera- The particulars of FingerThreshold parameter use has tion.quot; changed in the CSA UM. However, the purpose has remained the same. A higher threshold value requires more Hardware capacitance change to affect a change in the sensor's activa- An additional external capacitor may be used by CSA. The tion status. extra capacitor improves sensitivity and lowers the noise sus- The Hysteresis parameter provides smoother operation of the ceptibility of the sensing method over CSR, which does not FingerThreshold parameter by supplying different thresholds require any external components for sensing. for activation and deactivation. The Hysteresis parameter is The pins for the capacitor, CMOD, are selectable through the discussed on page 6 of this document. UM parameters in the Device Editor. NoiseThreshold Schematic changes accommodating the external capacitor may require layout changes. See AN2292, quot;Layout Consider- The CSA UM adds extra UM parameters to achieve the same ations for CapSense Applicationsquot; for guidance. function of the NoiseThreshold parameter in CSR. NoiseTh- reshold applies only to the positive noise level in the CSA User Module Parameters UM. Functions and values previously controlled by the Changes to user module parameters were necessary to NoiseThreshold parameter, such as negative noise and hys- accommodate the new sensing algorithm and to provide bet- teresis, are controlled by new parameters, NegativeNoiseTh- ter control over CapSense performance. Listed below are the reshold and Hysteresis, respectively. four UM parameters in CSR and how they are changed in CSA. A complete list of parameters is on page 6. For detailed information on each parameter and how to determine its value, refer the quot;Parametersquot; section of the CSA UM data sheet. 2 November 28, 2007 Document No. 001-15237 Rev. *A [+] Feedback
  3. 3. AN2393 BaselineUpdateRate Figure 3. CSA Waveform seen at CMod with No Finger Present BaselineUpdateRate has been removed and replaced by BaselineUpdateThreshold. While the scheme for each parameter's use is slightly different, the purpose for selecting the value of each is the same. Larger values for BaselineUp- dateRate and BaselineUpdateThreshold yield slower update rates. Smaller values yield faster update rates. ESD Debounce ESD Debounce in CSR has been changed to quot;Debouncequot; in CSA. In CSR, enabling the ESD Debounce added a number of functions to UpdateBaseline for detecting fingers present at startup, ESD events, and other non-periodic noise events. The Debounce parameter no longer carries the overhead that ESD Debounce did. The Debounce parameter adds a counter for counting active scans. The counter triggers a baseline reset once its threshold is reached. Nega- tiveNoiseThreshold and LowBaselineReset now perform functions that were integrated into ESD Debounce in CSR. APIs Significant changes have occurred with the APIs. Some APIs were no longer necessary due to the scheme for the new Table 1. CSA Waveform Regions. algorithm. Others were changed or added to make code gen- eration more intuitive and easier to explain. Region Description Listed below are some highlights of these changes. A com- 1 Sensor capacitor is connected on and off of the bus until voltage on the bus settles to plete list of new and old APIs is available on pages 7 and 8 of VStart. The Device Editor parameter Set- this document. For more details on each API in the CSA UM, tlingTime sets the amount of time provided including its use and example code, see section quot;APIquot; of the for this voltage to settle. CSA UM data sheet. 2 Sensor capacitor is disconnected from the bus. The bus is charged by the iDAC until SetDACCurrent the voltage exceeds VRef and the compara- SetDACCurrent is not required for CSA. The iDAC is used in tor trips. The current specified by the Device the CSA front end and is automatically calibrated in the Editor parameter IDACSetting is used here. CSA_Start routine. 3 The sensor scan is complete and the iDAC is turned off. Voltage on the bus decreases UpdateBaseline as charge dissipates by leakage currents The CSR UM used the UpdateBaseline API to process most inside the PSoC and by the parallel resis- of the information in capacitive sensing. This made code gen- tance added by the oscilloscope probe until eration fairly simple but not intuitive. To improve the usability the next scan begins. The amount of time and understanding of critical CapSense functions, the that this voltage decreases is strictly depen- UpdateBaseline API is now separated into several constitu- dent upon the firmware between each scan ent APIs, listed in the APIs section of this document. and the CPU clock speed. Scanning Sensors Region 1 The CSR UM used the UpdateBaseline API to scan the sen- In Region 1 of the CSA waveform the sensor capacitor (CX) is sors. This has been changed in the CSA UM to provide more connected to the analog global bus, and then grounded in transparent code generation and incremental control of pro- alternating phases. gram execution. During phase 1, CX is connected to the analog global bus Waveform Analysis putting it in parallel with CMod and CInternal. The block dia- To understand how CSA functions, it is useful to look at the actual waveforms of CSA. Figure 3 shows the CSA waveform gram of phase 1 is shown in Figure 4 on page 4. CInternal and seen by probing CMod in a project with a single sensor and no CMod share charge with CX. Charge continues to flow onto finger present. Three regions can be seen in the CSA wave- CMod and CInternal from the iDAC current source. form. Table 1 describes the regions that can be seen in Fig- ure 3. Each region is described in the following sections. 3 November 28, 2007 Document No. 001-15237 Rev. *A [+] Feedback
  4. 4. AN2393 Figure 4. CSA Block Diagram of Phase 1 VDD LPF VREF EN 16-Bit Data Ø1 Counter Processing CX Ø2 CMod CInternal Oscillator Phase 2 disconnects CX from the analog global bus and discharges CX by connecting it to ground, leaving only CMod and CInter- nal connected. This is shown in Figure 5. Figure 5. CSA Block Diagram of Phase 2 VDD LPF VREF EN 16-Bit Data Ø1 Counter Processing CX Ø2 CMod CInternal Oscillator The switching of phases 1 and 2 causes CX to effectively act as a resistance to ground, resulting in the CSA block diagram shown in Figure 6 on page 5. The equivalent resistance is found with the following equation. 1 REquivalent = fS CX Equation 1 ■ fs is the switching frequency of phases 1 and 2. ■ CX is the sensor capacitance. ■ The constant iDAC current flows through this resistance resulting in a voltage, VStart. You can calculate VStart with the following equation. This voltage is across the parallel capacitance of CMod and CInternal. 1 VStart = I DAC fS CX Equation 2 ■ IDAC is the iDAC current. 4 November 28, 2007 Document No. 001-15237 Rev. *A [+] Feedback
  5. 5. AN2393 Figure 6. CSA Block Diagram with Equivalent Resistor VDD LPF EN 16-Bit Data VREF Timer Processing REquivalent CMod CInternal Oscillator For detailed explanation of the use of switched capacitors in the CSA UM, see the CSA UM data sheet inside PSoC Designer. For a comprehensive derivation of switched capacitor equations, see AN2041, quot;Understanding Switched Capacitor Analog Blocks,quot; or reference Design With Operational Amplifiers And Analog Integrated Circuits, by Sergio Franco. Initialization/Calibration The VStart voltage is set just below VRef as CX is switched between phases 1 and 2 when the CSA UM starts by calling the CSA_Start() routine. CSA_Start() adjusts the iDAC using a successive approximation (SA) technique. The SA technique adjusts the iDAC using a binary search until the voltage on the bus reaches VStart. After the bus is charged to VStart, the iDAC current setting that was used is stored, and the process is repeated for each sensor in the project. This sequence is executed at the start of the CSA UM, and not performed with each scan of the sensors. It is similar to the calibration of the iDAC in the CSR UM to set the desired frequency of RO oscillations. Figure 7. Successive Approximation of iDAC Current   iDA C 80h 60h 58h 56h 55h V REF 54h 50h 40h VStar t 0 Time 5 November 28, 2007 Document No. 001-15237 Rev. *A [+] Feedback
  6. 6. AN2393 Region 2 counts exceeds the finger threshold, then sensor activation is detected. After the voltage on CMod and CInternal settles to VStart, the measurement sequence begins. A counter clocked by the The presence of a finger on a sensor increases the capaci- Internal Main Oscillator (IMO) is enabled. As the counter tance of the sensor, which decreases the equivalent resis- runs, the iDAC charges CMod and CInternal until the voltage tance formed by the switching of phases 1 and 2. This is evident in Code 1. The lower resistance results in a smaller on the capacitors increases to VRef, tripping the comparator voltage, VFinger, on the bus when CX is connected in parallel. and disabling the counter. The iDAC value used to charge the Thus, it takes longer for the iDAC to charge the voltage on bus, is the value specified in the UM parameters. The raw the bus from VFinger to VRef than it does from VStart to VRef. number of counts on the counter determines if a finger is present on a sensor. The raw counts are taken after each This results in increased counts on the counter, and enables measurement sequence and then compared to a stored detection of a conductive object present on a sensor. A baseline number of counts with no finger present on the sen- graphical representation of the charge time on the bus with a sor. If the difference between the raw counts and the baseline finger present and not present is shown in Figure 8. Figure 8. Voltage on Bus with Finger and No Finger Present On Comparator Threshold VRef Voltage VStart / No Finger VFinger Time Counted IMO No Finger Present Finger Present The waveform in Figure 9 shows the CSA waveform with a finger present, and verifies the longer count time by the counter. In Figure 9, the starting voltage in Region 1 has dropped due to a decrease in equivalent resistance as a result of the finger capac- itance added in parallel with the CX capacitance. The charge time in Region 2 on page 6 is longer resulting in increased counts on the counter compared to no finger present on the sensor. An increase in charge time is seen by comparing Figure 3 on page 3 and Figure 9. Figure 9. CSA Waveform Seen at CMod with Finger Present 6 November 28, 2007 Document No. 001-15237 Rev. *A [+] Feedback
  7. 7. AN2393 Converting/Creating a Project with CSA Region 3 In Region 3 of the waveform the scan is complete and the 1. Select quot;CSAquot; UM from quot;Cap Sensors.quot; iDAC is turned off. The voltage on the bus begins to drop due 2. Select Global Parameters. to charge dissipation by the parallel resistance added by the oscilloscope probe and leakage currents inside the PSoC. 3. Select UM Parameters. This voltage continues to decrease until the next scan 4. Define CapSense Pin Connections sequence and the voltage is again set to VStart. The amount 5. Generate Project Code with new APIs. of time the voltage spends decreasing depends upon the firmware executed between each scan and the CPU clock 6. Select Values for External Components (CMod). frequency. A faster CPU clock frequency results in a smaller decrease in the voltage on the bus in Region 3. Device Editor Parameters The flow diagram in Figure 10 summarizes the CSA scan The CSA UM implements new Device Editor parameters that process. do not exist in the CSR UM. Table 2 lists the UM parameters in CSA and CSR. UM parameters that share a row share the Figure 10. CSA Scan Process Flowchart function. Parameters in CSA that do not have equivalent functions in CSR are denoted by '-'. These parameters are described briefly in this document. For detailed information, CSA UM Start see the CSA UM data sheet. Table 2. CSR and CSA UM Parameters Initialization/ CSR CSA Calibration: SA of iDAC current until bus FingerThreshold FingerThreshold voltage reaches V Start while C X switches NoiseThreshold NoiseThreshold between phases 1 and 2. Hysteresis BaselineUpdateRate BaselineUpdateThreshold ESD Debounce Debounce Start Sensor NegativeNoiseTreshold Scan LowBaselineReset - SettlingTime Region - IDACSetting 1: switches CX between - ExternalCap phases 1 and 2 until voltage . on bus settles to - Sensors Autoreset VStart - Clock FingerThreshold Region 2: iDAC charges C Internal and CMod until The amount of change in capacitance (measured by counts) comparator that is necessary to detect a finger or other activating element trips. on a sensor is determined by the FingerThreshold parameter. This is fundamentally the same as it is in the CSR UM. Region A general rule of thumb is that the finger threshold plus hys- 3: Voltage drops on bus teresis must be equal to 80% of a light finger touch. until next scan begins. NoiseThreshold The NoiseThreshold parameter sets the positive value above the baseline. Raw counts below this value and above the Update Baseline baseline are used to update the baseline. Raw counts greater than Baseline+NoiseThreshold are not part of the baseline update scheme and are ignored. Perform Other User Code 7 November 28, 2007 Document No. 001-15237 Rev. *A [+] Feedback
  8. 8. AN2393 BaselineUpdateThreshold Hysteresis CSA uses a quot;bucketquot; method to update the baseline count. The Hysteresis parameter sets the number of counts used for Half the difference between the raw count value and the hysteresis levels above and below the finger threshold. If the baseline count is added to the quot;bucketquot; when: sensor is off, the difference count must overcome the finger threshold plus hysteresis to turn on. If the sensor is on, the 1. the raw count value returned from a scan is above the difference count must go below the finger threshold minus current baseline and hysteresis to turn off. Hysteresis adds debounce and quot;sticki- 2. the difference between the raw count value and the base- nessquot; to the finger detection algorithm. line count is below the noise threshold. Note Figure titles are always centered above the figure. Fig- The BaselineUpdateThreshold sets the value that the ures are centered in the column or on the page if the figure is quot;bucketquot; must reach for the baseline count to be incremented. large. SettlingTime The setting must be lower than the finger threshold. The hys- teresis level must be set to slightly larger than the noise The SettlingTime parameter sets the length of a software threshold so that noise in the system does not turn a sensor delay enabling the voltage on the bus to stabilize to VStart on and off when a finger is present. Figure 11 shows a dia- before the beginning of each scan. This delay directly gram of a finger press with hysteresis implemented. depends on the CPU clock speed. The SettlingTime parame- ter corresponds with Region 1 in Figure 3 on page 3 and Figure 11. Hysteresis Diagram Figure 9 on page 6. Each SettlingTime unit is equivalent to nine CPU cycles. A CPU clock speed of 12 MHz is recom- mended for CSA CapSense projects. For a CPU clock speed FingerTreshold+Hysteresis of 12 MHz, a SettlingTime value of 160 units is suggested. FingerThreshold Counts IDACSetting FingerThreshold-Hysteresis The IDACSetting parameter sets the iDAC current to charge the bus during Region 2 on page 6 of the scanning process. NoiseTreshold This parameter ultimately controls the sensitivity of the sen- Baseline sors. A decrease in the iDAC setting results in higher sensi- OFF ON OFF tivity but longer scan times, and an increase in the IDACSetting results in the opposite. An IDACSetting of greater than three units must be used when no external Debounce capacitor is used. A setting of greater than 20 must be used The Debounce parameter adds a debounce counter to the when an external capacitor is used. Each IDACSetting unit is sensor active transition. For the sensor to transition from approximately 0.16 µA. inactive to active, the difference count value must stay above ExternalCap the [FingerThreshold+Hysteresis] for the number of samples specified by this parameter. The debounce counter is incre- The ExternalCap parameter chooses the PSoC port pin to mented by the bIsSensorActive or bIsAnySensorActive API which the optional CMod external capacitor is connected: functions. P0[0], P0[3], or none. The CMod capacitor provides additional noise immunity for the capacitance-to-voltage conversion. Possible values are 1 to 255. A setting of '1' provides no Larger capacitors provide better noise immunity and debouncing. In the CSR UM, a setting of '0' provided no ESD increased sensitivity. Larger capacitors also increase scan debounce. time. The CMod capacitor must be used to increase sensitivity NegativeNoiseThreshold when a signal-to-noise ratio of 5:1 cannot be achieved. See The NegativeNoiseThreshold parameter sets a value below AN2403, quot;Signal-to-Noise Ratio Requirement for CapSense the baseline. Counts above this value and below the baseline Applications,quot; for more information on signal-to-noise ratio trigger an automatic update of the baseline to the raw count requirements. value. Raw counts less than The recommended CMod capacitor size is approximately [Baseline - NegativeNoiseThreshold] are ignored until the 1000 pF, and must have low temperature dependence, e.g., LowBaselineReset value is reached on a counter. C0G. 8 November 28, 2007 Document No. 001-15237 Rev. *A [+] Feedback
  9. 9. AN2393 LowBaselineReset Table 3. CSR and CSA UM APIs (Continued) CSR CSA The LowBaselineReset parameter works together with the NegativeNoiseThreshold parameter to count the number of CSR_bUpdateBaseline CSA_UpdateSensorBaseline abnormally low samples required to reset the baseline. If the CSA_UpdateAllBaselines count value is less than Baseline-NegativeNoiseTreshold for CSA_bIsSensorActive the number of samples set by LowBaselineReset, the base- CSA_bIsAnySensorActive line is set to the new raw count value. LowBaselineReset is CSA_SetDefaultFingerThresho generally used to correct a finger-on-at-startup condition. lds Clock CSA_InitialiseSensorBaseline CSA_InitializeBaselines The Clock parameter is used to increase the amount of effec- tive resistance of the sensor. If the sensor area is large, the CSR_bGetScanStatus - effective resistance may be too high for the auto calibration of CSR_wGetCentroidPosition CSA_wGetCentroidPosition the switched capacitor circuit. Touchpad rows or columns, or large proximity sensors may encounter decreased sensitivity. APIs with functions and labels that have not changed are not In this case, the settling voltage is too far beneath the com- described here. APIs that have been changed, removed, or parator threshold. Setting a larger divider of the IMO added are described briefly. For more details on the APIs of increases the effective resistance, compensating for the high the CSA UM, including example code and settings, see the capacitance. Normally, this parameter must be left at the quot;APIquot; section of the CSA UM data sheet. default IMO setting. Removed APIs APIs The StopScan(), SetDacCurrent(), SetScanSpeed() and CSA uses many routines that are similar to those in CSR. bGetScanStatus() function calls are not used with CSA. Several new algorithms have been added to improve CSA Initialization usability. Table 3 lists the UM APIs for CSR and CSA. APIs that have been maintained or have equivalent function share CSA requires that the finger thresholds set in the Device Edi- a row. APIs that have been eliminated or removed do not tor first be loaded with CSA_SetDefaultFingerThresholds(), have equivalents and are marked by quot;-quot; in the alternate UM's and that all the baselines be set to the current count with column. CSA_InitializeBaselines(). Loading the default finger thresh- olds provides the CSA algorithms with a reference to deter- Table 3. CSR and CSA UM APIs mine if the current value of the raw count is representative of a finger press. CSR CSA If no reference is provided, the CSA algorithms cannot detect CSR_Start CSA_Start a finger press properly. Finger thresholds can also be directly CSR_Stop CSA_Stop set by modifying the CSA_baBtnFThreshold array. This CSR_StartScan CSA_ScanSensor enables different thresholds for each individual sensor in the CSA_ScanAllSensors design, where CSA_SetDefaultFingerThresholds() applies CSR_StopScan - the same threshold to all sensors. CSR_ClearSensors CSA_ClearSensors Baselining CSR_wReadSensor CSA_wReadSensor In CSA, the CSA_UpdateAllBaselines() routine strictly CSR_wGetPortPin CSA_wGetPortPin updates the baseline. Unlike CSR, this routine does not cal- CSR_EnableSensor CSA_EnableSensor culate difference counts, determine if a sensor is on or off, CSR_DisableSensor CSA_DisableSensor detect ESD events, or perform many of the other high-level CSR_SetDacCurrent - functions that were handled by the corresponding API in CSR_SetScanSpeed - CSR. Individual sensor baselines can be updated by using the CSA_UpdateSensorBaseline(BYTE bSensor) routine. Scanning Sensors CSA eliminates the need to write firmware to scan through each sensor as required in CSR. The CSA_ScanAllSensors() routine scans through all the sensors that are configured in the project. CSA_ScanSensor(BYTE bSensor) enables scan- ning of individual sensors. 9 November 28, 2007 Document No. 001-15237 Rev. *A [+] Feedback
  10. 10. AN2393 External Components The CSA_bIsAnySensorActive() routine returns true if any sensor is active and the CSA_bIsSensorActive(BYTE bSen- The new sensing front end of the CSA UM has an optional sor) routine returns true if a particular sensor is active. These external component that was not needed with CSR. two functions update the CSA_baSnsOnMask, which has CMOD been renamed from CSR_baSnsOnMask in CSR. Example Code 1 is sample code of a CSA project for the The addition of capacitance from CMod increases sensitivity CapSense Successive Approximation (CSA) Training Kit by increasing the charge time during Region 2 of the CSA CY3203A-CAPSENSE. The CY3203A-CAPSENSE kit scan. The CMod capacitor must be used to increase sensitiv- includes an evaluation board made up of eight sensors, a ity when a signal-to-noise ratio of 5:1 cannot be achieved. slider, and an LCD. This code checks to see if any sensors See AN2403, quot;Signal-to-Noise Ratio Requirement for are active in the project. If any sensor is active, the corre- CapSense Applications,quot; for more information on signal-to- sponding sensor number is then written to the LCD. noise ratio requirements. Code 1. Example The recommended CMod capacitor size is approximately 1000 pF, and must have low temperature dependence, e.g., #include <m8c.h> C0G. #include quot;PSoCAPI.hquot; //Define white space to clear LCD screen Increasing the value of CMod beyond 1000 pF can further #define CLRLCD quot; quot; increase sensitivity and reduce noise. Sensitivity is limited by int i; void main() the amount of time it takes to complete a sensor scan { because the addition of CMod increases the charge time dur- LCD_Start(); ing Region 2 on page 6 of a scan. Noise reduction is limited //Clear LCD Screen to the noise that is inherent to the system. LCD_Position(0,0); LCD_PrCString(CLRLCD); CMod also reduces noise by acting as a bypass capacitor, LCD_Position(1,0); preventing large voltage changes on the input of the compar- LCD_PrCString(CLRLCD); ator. M8C_EnableGInt; CSA_Start(); CSA_SetDefaultFingerThresholds(); CSA Hardware Improvements CSA_InitializeBaselines(); The CSA hardware gives it a higher noise immunity resulting while(1) { in greater sensitivity when compared to CSR. The reduction CSA_ScanAllSensors(); of noise allows for greater sensitivity in CSA, since sensitivity CSA_UpdateAllBaselines(); //Were any sensors pressed? is based on the ratio of signal-to-noise ratio (SNR) levels. The if(CSA_bIsAnySensorActive()){ switching of the sensor capacitor in CSA reduces outside //Loop through sensors noise sources on the sensor capacitor that can be coupled for(i=0; i<CSA_ButtonCount; directly into the CSA system. The sensor capacitor in CSR is i++){ constantly connected to the analog global bus during a scan. //Was this sensor active? During phase 2 of the switched capacitor operation in CSA, if(CSA_bIsSensorActive(i)){ any noise introduced on the sensor capacitor is shorted //Write sensor to LCD directly to ground. In addition, the grounding of the sensor LCD_Position(0,0); capacitor reduces the input impedance of the CSA system LCD_PrHexInt(i); } when compared to CSR. The smaller input impedance results } in smaller voltages entering the CSA system as a result of } any noise current. //No sensor active clear LCD The input of the comparator for CSA also includes an internal else{ LCD_Position(0,0); LPF to reduce the effect of high frequency noise on sensor LCD_PrCString(CLRLCD); scans. LCD_Position(1,0); LCD_PrCString(CLRLCD); } }//End of normal operating loop }//End of main 10 November 28, 2007 Document No. 001-15237 Rev. *A [+] Feedback
  11. 11. AN2393 Summary The PSoC Mixed-Signal Array is a configurable array of digital and analog resources, Flash memory and RAM, an 8-bit micro- controller, and several other features. These features enable PSoC to implement innovative capacitive sensing techniques in its CapSense portfolio. The CSA CapSense method exhibits exceptional sensitivity enabling the detection of smaller capacitive changes than in CSR, operation in wet environments, as well as noise immunity from RF sources that can cause false button presses in a capacitive sensing system. New APIs also make it easier for the user to set up a CSA project, making CSA an improved method over CSR for capacitive sensing using Cypress' PSoC Mixed-Signal Array devices. 11 November 28, 2007 Document No. 001-15237 Rev. *A [+] Feedback
  12. 12. AN2393 Appendix A Quick Migration Guide This appendix documents the changes needed to convert a CSR CapSense project to CSA. 1. Add CMod if used. 2. Add the CSA UM in the Device Editor. 3. Update the Wizard for the sensor layout of the CapSense evaluation board. 4. Fill in user module parameters for CSA: UM Parameter Value Comments Finger Threshold 40 Noise Threshold 20 Dependent upon desired baseline update rate and noise amplitude in the system. BaselineUpdateThreshold 200 120 units for 12 MHz CPU speed and IMO Clock Setting. See Clock parameter. SettlingTime 120 >3 if no external capacitor is used. >20 if an external capacitor is used. IDACSetting 25 A 1000 pF capacitor is recommended for the CY3203A- CAPSENSE evaluation board. ExternalCap Select GPIO pin used (Finger Threshold - Noise Threshold) < Hysteresis. Hysteresis 10 Debounce 1/Disabled Negative Noise Threshold 20 LowBaselineReset 10 SensorsAutoreset Disabled Clock IMO 12 November 28, 2007 Document No. 001-15237 Rev. *A [+] Feedback
  13. 13. AN2393 5. Software changes: Description CSR CSA Finger thresholds and baseline CSR_Start(); M8C_EnableGInt; M8C_EnableGInt; CSA_Start(); need to be initialized for CSA after CSA_SetDefaultFingerThresholds(); starting the UM. CSA_InitializeBaselines(); Looping through all the sensors in for (i=0; i<NUM_SWITCHES; i++){ CSA_ScanAllSensors(); CSR_SetDacCurrent(bDACcurrent[i],0); CSA_UpdateAllBaselines(); CSR and setting individual iDAC CSR_SetScanSpeed(3); current, scanspeed, and polling for CSR_StartScan(i,1,0); the scan to complete is no longer while(!(CSR_GetScanStatus()& needed. CSR_SCAN_SET_COMPLETE)); } In CSA only the CSA_ScanAllSensors() and CSA_UpdateAllBaselines() rou- tines need to be called. In CSA the UpdateBaseline routine if(CSR_bUpdateBaseline(0)){ if(CSA_IsAnySensorActive()){ //Is sensor 0 active? //Is sensor 0 active? only updates the baseline and no if ((CSR_baSwOnMask[0]) & BUTTON_0){ if (CSA_bIsSensorActive(0)){ longer determines if a sensor is //Enter user code here. //Enter user code here. active or not. } } To determine if any sensor is active use the CSA_IsAnySensorActive(). To determine if a particular sensor is active use the CSA_bIsSensorActive(BYTE bSen- sor) routine. 13 November 28, 2007 Document No. 001-15237 Rev. *A [+] Feedback
  14. 14. AN2393 Appendix B CSR and CSA Code Size This appendix documents the RAM and ROM code size for CSR and CSA APIs and variables. CSA CSR API Name ROM (Bytes) API Name ROM (Bytes) CSA_bFindDACCodeBaseline 54 CSR_bGetScanStatus 15 CSA_bIsAnySensorActive 26 CSR_bUpdateBaseline w/ ESD 685 CSA_bIsSensorActive 165 CSR_bUpdateBaseline w/o ESD 433 CSA_ClearSensors 16 CSR_ClearSensors 13 CSA_DisableSensor 40 CSR_DisableSensor 52 CSA_EnableSensor 40 CSR_EnableSensor 45 CSA_InitializeBaselines 43 CSR_GetBaseline 53 CSA_ISR 37 CSR_GetScanStatus 15 CSA_ScanAllSensors 11 CSR_SCAN_ISR 119 CSA_ScanSensor 197 CSR_SetDacCurrent 20 CSA_SetDefaultFingerThresholds 24 CSR_SetScanSpeed 12 CSA_Start 112 CSR_Start 72 CSA_Stop 27 CSR_StartScan 70 CSA_UpdateAllBaselines 11 CSR_Stop 52 CSA_UpdateSensorBaseline 181 CSR_StopScan 7 CSA_wGetCentroidPos 566 CSR_UpdateBaselineIIR 48 CSA_wGetPortPin 9 CSR_wGetCentroidPos 557 CSA_wReadSensor 22 CSR_wGetPortPin 9 CSR_wReadSensor 22 Figure 12. Approximate CSR vs. CSA RAM Usage   400 CSA RAM Usage CSR RAM Usage 350 300 Approximate RAM Usage (Bytes) 250 200 150 100 50 0 0 5 10 15 20 25 30 Number of Sensors 14 November 28, 2007 Document No. 001-15237 Rev. *A [+] Feedback
  15. 15. AN2393 About the Author Name: Ted Tsui Title: Applications Engineer Sr Contact: utt@cypress.com In March of 2007, Cypress re-cataloged 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. quot;Programmable System-on-Chip,quot; PSoC Designer and PSoC Express 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. 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. November 28, 2007 Document No. 001-15237 Rev. *A 15 [+] Feedback

×