| The Datasheet Archive - 100 Million Datasheets from 7500 Manufacturers. |
Calibrating CapSense with User Module Author: Darrin Vallis Assoc
Top Searches for this datasheetAN2355 Calibrating CapSense with User Module Author: Darrin Vallis Associated Project: Associated Part Family: CY8C21x24, CY8C24x94 PSoC Designer Version: Associated Application Notes: AN2233a, AN2277, AN2292, AN2318 Abstract This Application Note describes steps necessary select, place calibrate (Capacitive Switch Relaxation Oscillator) User Module CapSense applications. Introduction Cypress' PSoC® extremely versatile system-on-chip device. capabilities allow engineers solve problems develop exciting products. most unique features available PSoC capacitive sensing. PSoC able detect presence finger through glass, plastic, acrylic many other non-metallic materials, using simple trace sensor. Application Note AN2233a "Capacitive Switch Scan" more actual physics electrical engineering PSoC capacitive sensing. Designers free implement buttons, sliders type touch-based user interface. This significant advantage consumer electronics. Many most popular devices market today have PSoC capacitive sense interface. This Application Note helps engineer implement their first capacitive sense design. Even though PSoC Designerhas user module that provides necessary hardware connections, software APIs, does sophisticated background processing, still configured correctly. Background Requirements Designers must least familiar with PSoC architecture PSoC Designer development environment. Cypress Field Applications Engineers available just such information. http://www.cypress.com/, click "About Cypress" sidebar then "Cypress Locations." Local Sales Offices designers touch with FAEs questions even quick PSoC training. Building Project This section describes select devices select, place configure necessary user modules (UMs). Step Creating Project Create project with CapSense-enabled device. These CapSense-enabled parts include those CY8C21x34 CY8C24x94 families. example project this Application Note uses CY8C21434-24LFXI, 32-pin with CapSense I/Os. Step Selecting User Modules Under User Module Selection View PSoC Designer, select category "MUXs" User Module. Double-click icon place User Modules into your project. default name "CSR_1." possible rename whatever easy use. 2/22/2006 Revision AN2355 example project this Application Note renamed "SENSE" ease coding later also good practice drop communication interface. example project uses EZI2C User Module easy configure work with. This been renamed User module selections shown Figure Figure Wizard Setting Confirmation Figure Wizard Figure User Module Selection Drag drop switches want onto ports, shown Figure Step Placing User Modules Before writing main loop, necessary place user modules into their respective blocks. User Module occupies first digital blocks first analog column PSoC analog digital resources. Right-click place Place first. Blocks that used fixed. Step Assigning Pins Once placed, right-click block Wizard. Enter number buttons sliders boxes screen. This shown Figure (B). Once number sliders been set, number pins used each slider, shown Figure (C). resolution slider, Figure (D). After each setting, wizard will prompt user confirmation shown Figure Figure Wizard Operation Screen 2/22/2006 Revision AN2355 Press "OK" exit Wizard. example project this Application Note, only buttons used. These buttons correspond pins Port final Wizard display example project shown Figure Step Configuring Other Pins Before building project, select switch list name them LEDs. drive mode "Strong." This shown Figure switches used indicate when switch pressed. Build project navigate program, main(). Figure Setting Drives Program Structure Figure Example Project Wizard Setup Step Configuring User Modules necessary assign pins other user modules already complete. example project, communication pins P1[0] (SDA) P1[1] (SCL). User Module several options User Module Parameters window. These depend design features that decided later project development. However, wise Method "Period" shown Figure It's always excellent coding practice keep things simple. Example code project found Appendix main loop basically does one-time configuration I/O, parameters. After that, loops forever, scanning buttons, handling interrupt setting LEDs. That's Tuning User Module While parameters exist build project, there several values that must calibrated tuned specific boards specific buttons. This done both Device Editor Application Editor PSoC Designer. Setting Data Receipt Before tuning begin, necessary install method viewing capacitive sense data that gathered application. Though PSoC Designer includes excellent debug capabilities with flex pods, different approach required when working with capacitive sensing. senses finger presence very small changes capacitance. flex will have VERY different electrical characteristics than regular PSoC soldered onto your board. absolutely necessary have working same time flex ICE, Figure Setting Scanning Method 2/22/2006 Revision AN2355 #ifdef statement used re-define parameters when attached. simple projects like this Application Note, excellent tune CSR. Note that author's project required communication. Therefore, logical choice data read. master from Electronics (http://www.m3electronics.biz/) used. data that must monitored tuning best dealt with within structure: struct I2C_RegType Control register BYTE Control; On/Off register BYTE LEDs; Button state BYTE Buttons; #ifdef debug Button data counts[NBUTTONS]; Baseline data baseline[NBUTTONS]; Button differences difference[NBUTTONS]; #endif I2Cregs; When compiled debug. "Counts" shows counts being read each switch "Baseline" automatically updated provides compensation environmental changes over time. "Difference" very important. shows difference counts between button scan next. decides button been pressed based this "difference" data. Electrical Description that there mechanisms what's going inside PSoC during runtime, time tune First, basic description electrical system described below. complete description electrical circuit capacitive sensing using PSoC, please application note AN2233a. Figure shows basic setup relaxation oscillator capacitive sensing. sensor capacitor charged threshold comparator with internal current source (C). When comparator reaches threshold, switch closed sensor capacitor discharged. #ifdef used include debug data tuning board. PSoC Designer, PROJECT SETTINGS entry labeled "Macro Defines." symbol typed here passed compiler during build, allowing code included excluded needed. data structure. iCHARGE "Control" I2C-accessible byte providing control LEDs, interrupt polarity other settings. This optional, often useful. "LEDs" I2C-accessible register allowing user LEDs over This necessary some applications. "Buttons" byte-wide register showing ON/OFF status each button. COMP Figure Basic Relaxation Oscillator Circuit 2/22/2006 Revision AN2355 CY8C21x34 series PSoC devices specialized circuitry automatically charging discharging external capacitor. capacitive sensing, capacitor trace, whose capacitance altered presence conductive object such finger. capacitance varies, does rate which oscillator charges CY8C21x34 devices, discharge time fixed clock cycles). voltage capacitor (sensor) shown waveforms Figure finger) (finger). comparator output shown Figure finger) (finger). clock relaxation oscillator's comparator output. gates 16-bit timer (B). number clock cycles that basic unit measurement charge waveform associate clock cycles shown Figure Figure Sensor Charge Waveform Clock Cycles data that used sent PSoC with regard these clock cycles. PSoC measuring capacitance directly, rather amount time necessary charge capacitor. Now, Tuning. basic steps tuning User Module are: current. Scan Speed. Adjust Thresholds (Finger Noise). Figure Sensor Capacitor Voltage, Finger Comparator Output, Finger Sensor Capacitor Voltage, Finger Comparator Output, Finger timer used determine length time necessary charge capacitor threshold with circuit described Figure Step Setting Current Tuning begins with setting frequency oscillation each sensor. This oscillation charge-discharge cycle sensor capacitor. rate charge capacitor factor size capacitor current that used charge threshold voltage. first parameter fixed hardware what being measured. second parameter, current, over which designer control. start, necessary choose arbitrary current This done using SetDacCurrent( call. example setting current using range shown below: SYSCLK 16-Bit Timer Enable 8-Bit Figure Counting Circuit This drives certain amount current into trace, resulting specific frequency oscillation. current setting incremented mode high mode. example, current implementation hardware within PSoC, optimal operating frequency this oscillation less. 2/22/2006 Revision AN2355 Determine current frequency setting scan speed three units with following call: SENSE_SetScanSpeed(3); FOSC ScanSpeed Counts every switch scan, user module requires cycles data processing. Therefore, setting scan speed means button counts gathered cycle only. Since counts sampled system clock, formula determine oscillator frequency Working backwards, reading counts sensor ScanSpeed(3) means Fosc kHz. other words, necessary tune current that each button reads approximately counts with ScanSpeed Table Spreadsheet Tuning Current Sensor Current Setting Value Counts (ScanSpeed Oscillator Frequency 3.04 81.91 2.90 81.63 2.48 80.27 2.42 81.63 2.21 80.54 2.07 80.54 2.35 81.91 2.62 81.91 Table Spreadsheet Tuning Scan Speed Sensor Current Scan Speed Counts (Sensor Untouched) 6788 1A84 6688 1A20 6725 1A45 6802 1A92 6944 1B20 6692 1A24 6758 1A66 6673 1A11 This good time introduce spreadsheet. process tuning, necessary record counts, differences, calculated thresholds, etc. this work very well suited spreadsheet. Table shows spreadsheet project that used record current settings each button their corresponding oscillator frequency. achieve count value approximately counts kHz) each sensor, different current settings required. This variations parasitic capacitance that arise from board layout. Using current enough that sensor runs buttons results other sensors' oscillators running speeds that optimal. what's solution? Scan_Buttons( routine, array used hold different current values. Instead scanning buttons, code loads current button, scans that button once only then loops next. This yields individual tuning control each button, making board exceptionally responsive more noise immune. Step Setting Scan Speed Once each sensor tuned oscillator frequency, it's time scan speed. scan speed (Period Mode) sets number oscillator pulses which high. Increasing scan speed increases things: counts read PSoC time necessary scan each sensor. This more data sensor calibrating sensitivity accounting noise. First, verify "counts" each sensor without touching sensor. This accomplished same manner counts were obtained while setting current. used example project. Second, gradually increase scan speed parameter each sensor. stated above, counts increase with scan speed. Setting scan speed higher number simply means that instead collecting counts sensor scan processing two, counts collected scans processing occurs two. other words: SetScanSpeed(N) Collect Data cycles, process cycles. 2/22/2006 Revision AN2355 optimum number counts each sensor depends project requirements. However, counts should exceed 0x2000 (8192). This explained below. Notice that scan speed necessary achieve desired number counts different each sensor. This again result parasitic capacitances each sensor. Note that counts each sensor cannot exceed 0x3FFF (16,383). This occurs when scan speed high PSoC looks sensor long. variable that stores counts each sensor integer, meaning that functional limit 0xFFFF (65,535). baselining algorithm described later this document further limits this value fourth. Values that exceed this limit overflow integer (roll past zero). example, current scan speed parameters return 0x5100 (20,736) counts, integer will overflow instead will detect 0x1100 (4352) counts. This causes problems number routines including baseline update debounce. This will lead sensors exhibit strange behavior. Step Setting Thresholds Once current scan speed set, it's time tune thresholds device. Thresholds predefined difference counts that correspond sensor activation status change. First, some definitions: Difference counts number counts which current counts differ from baseline. baseline constantly updated zero value each button. baseline represents parasitic capacitance seen when finger other such conductive object present sensor. baseline used calculate both noise finger thresholds, which simply added baseline. noise threshold number counts above below baseline that ignored PSoC. long difference counts exceed noise threshold, baseline update function operates. noise threshold also serves sensor deactivation threshold, whereby PSoC determines that finger longer present sensor. finger threshold number counts above baseline that necessary detect presence finger. counts fall below this value (due noise) sensor will remain active. until counts fall below noise threshold that sensor state changed inactive. Difference Counts _baBtnFThreshold Noise Threshold Figure Thresholds Sensor Activation more detail. noise threshold parameter User Module Parameter configuration screen PSoC Designer. button scan showing difference less than noise threshold ignored. This parameter makes design more robust filtering amplitude noise. Setting noise threshold high filter valid button presses. Part BaselineUpdate algorithm states that counts exceed noise threshold, baseline updated. This ensures that finger sensor does inappropriately high count values baseline update filter. Setting noise threshold will increase likelihood that baseline updated limit PSoC's ability adjust environmental changes. Finger threshold decision point button. difference between successive scans exceeds this threshold, button flagged variable *(name)_baSwOnMask. determine valid button press occurred polling this variable. noise threshold finger threshold sensors User Module Parameters window Device Editor shown Figure 2/22/2006 Revision AN2355 Noise Threshold board code must output data scan continuously. Without finger present sensor, values fluctuate slightly each sensor. minimum maximum values represent lower upper noise limits. This another time which spreadsheet very useful. Table complete noise data example system. sensor[0], counts sensor fluctuate between 0x1A84 (6788) 0x1A56 (6742). This overall difference noisiest sensor, however, sensor[3] with fluctuation Since sensor[3] noisiest sensor because noise threshold global setting this project, noise threshold high enough accommodate counts fluctuation. Figure Setting Thresholds Globally calculate threshold values. Table Spreadsheet Determining Noise Threshold Sensor Counts Counts Noise 6788 1A84 6688 1A20 6725 1A45 6802 1A92 6944 1B20 6692 1A24 6758 1A66 6673 1A11 6742 1A56 6654 19FE 6673 1A11 6749 1A5D 6896 1AF0 6656 1A00 6719 1A3F 6639 19EF Absolute Setting Table Spreadsheet Determining Finger Threshold Sensor Counts (Untouched) Counts (Touched) Signal (Difference) Finger Theshold 6788 1A84 6903 1AF7 6688 1A20 6834 1AB2 6725 1A45 6881 1AE1 6802 1A92 6929 1B11 6944 1B20 7074 1BA2 6692 1A24 6833 1AB1 6758 1A66 6903 1AF7 6673 1A11 6815 1A9F noise threshold setting actually positive negative adder baseline. Therefore, divide noise floor two, then three result give some room corner cases that seen during calibration view time. This yields actual noise threshold setting Finger Threshold Finger threshold used denote when sensors become active. same setup used determine values this setting. Instead leaving sensors untouched, each sensor must activated result that activation recorded, again, table. results example application shown Table Finger threshold globally User Module Parameters window (shown Figure 13). Since each sensor example project different level activation, necessary finger threshold each individually. This done initiation routine using following line code: SENSE_baBtnFThreshold[0] This sets finger threshold sensor. This done each sensor structure. result same. Figure shows these settings apply sensor [0]. 2/22/2006 Revision AN2355 Observed Anything below noise threshold ignored. When difference between counts from scan next exceeds baBtnFThreshold[n], sensor "ON." Once difference falls below baBtnFThreshold[n], sensor "OFF." Actually pretty simple, very dependant setting these thresholds correctly. Signal-to-Noise Ratio While calculating signal-to-noise ratio necessary, useful when determining efficiency sensor. _baBtnFThreshold[0] Noise Threshold Ingnore Observed Noise Baseline Figure Button[0] Threshold Settings Table Spreadsheet Calculating Signal-to-Noise Ratio Sensor SIGNAL NOISE 20LOG(S/N) 26.5 19.5 2/22/2006 Revision AN2355 Appendix main.c //-// Touch code Application Note Author: Darrin Vallis //-#include <m8c.h> #include "PSoCAPI.h" #include "main.h" void main() Setup_IO(); Setup_I2C(); Setup_Touch(); M8C_EnableGInt; while(1) Scan_Buttons(); Set_LEDS(); Set_Interrupt_Pin(); part specific constants macros PSoC definitions //Set GPIO address inputs //Configure start engine //Configure touch //Start everything //Switch data *SENSE_baSwOnMask //Turn LEDs //Set clear 2/22/2006 Revision AN2355 main.h #define #define #define I2CBASE #define LED_AUTO #define NBUTTONS #define INT_PIN 0x10 #define INT_POL_MASK 0x02 #define INT_ENA_MASK 0x01 #define INT_STAT_MASK 0x80 0x40 0x08 0x40 0x04 P1_6 P1_3 address 0x86/0x86 with pull-downs Number buttons P1_4 Control register, Control register, Control register, struct I2C_RegType BYTE Control; BYTE LEDs; BYTE Buttons; #ifdef debug adc[NBUTTONS]; baseline[NBUTTONS]; difference[NBUTTONS]; #endif I2Cregs; BYTE dacCurrent[] {44,42,36,35,32,30,34,38}; Individual current switch BYTE scanSpeed[] {30,29,25,14,10,10,12,13}; Individual scan speed switch BYTE prev_buttons Keeps track button press status void Setup_IO(void) //Make sure LEDs PRT2DR 0xFF; I2Cregs.LEDs 0x00; Control register On/Off register Button state Button data Baseline data Button differences //ReConfigure I/O. Fixes Start-Up glitch leaving //in tri-state power-up, then switching mode PRT1DM2 0xA0; PRT1DM1 0xA0; PRT1DM0 0xA0; //Set default polarity (Active Low), i.e., button pressed PRT1DR INT_PIN; //Set default values control I2Cregs.Control 0x00; I2Cregs.Control ~INT_ENA_MASK; //Enable interrupt //Active polarity //No interrupt pending //Set Pull-Ups A1/A0, P1_6/P1_3 PRT1DR 0x48; void Setup_I2C(void) unsigned char PortData, I2Caddr, I2Cstatus; //Set address //Internal PSoC, address right shifted 2/22/2006 Revision AN2355 //I2CBASE b0100 0000 //If pulled chip, 0000 0001 //If pulled chip, 0000 0010 //When resistors placed, address 0100 0011 //This translates b10000110 0x87R, 0x86W. Clear PRT1DR (A1|A0); //Turn internal pull-ups A1,A0 pins PortData PRT1DR; //Read A1,A0 data from P1_6, P1_3 I2Caddr I2CBASE; I2Caddr (PortData (I2Caddr|0x01) I2Caddr; //If bit=1, address with 0x01 I2Caddr (PortData (I2Caddr|0x02) I2Caddr; //If bit=1, address with 0x02 I2C_Start(); //Start hardware I2C_SetAddr(I2Caddr); //Set address from strap pins (BYTE &I2Cregs); //I2Cregs defined main.h //Init other registers I2Cregs.Control LED_AUTO I2Cregs.Buttons 0x00; void Setup_Touch(void) SENSE_Start(); SENSE_baBtnFThreshold[0] SENSE_baBtnFThreshold[1] SENSE_baBtnFThreshold[2] SENSE_baBtnFThreshold[3] SENSE_baBtnFThreshold[4] SENSE_baBtnFThreshold[5] SENSE_baBtnFThreshold[6] SENSE_baBtnFThreshold[7] BYTE Scan_Buttons() BYTE i,status; for( i=0; NBUTTONS; i++) //Set current this button //Set scan speed this button //Scan button while(!(SENSE_GetScanStatus() SENSE_SCAN_SET_COMPLETE)); //Wait until it's done #ifdef debug I2Cregs.adc[i] SENSE_iReadSwitch(i); I2Cregs.baseline[i] SENSE_iaSwBaseline[i]; I2Cregs.difference[i]= SENSE_iaSwDiff[i]; #endif status SENSE_bUpdateBaseline(0); prev_buttons *SENSE_baSwOnMask; return(status); void Set_Interrupt_Pin() 100; 100; 100; 100; 100; 2/22/2006 Revision AN2355 !(I2Cregs.Control&INT_ENA_MASK) I2Cregs.Control INT_STAT_MASK; //Set interrupt register PRT1DR (I2Cregs.Control&INT_POL_MASK)? PRT1DR|INT_PIN PRT1DR&~INT_PIN; //And (I2C_GetActivity() I2C_READ_ACTIVITY) //On read I2Cregs.Control ~INT_STAT_MASK; //Clear control register status PRT1DR (I2Cregs.Control&INT_POL_MASK)? PRT1DR&~INT_PIN PRT1DR|INT_PIN; //Clear void Set_LEDS() PRT2DR *SENSE_baSwOnMask; 2/22/2006 Revision AN2355 About Author Name: Title: Darrin Vallis Principal Field Applications Engineer Cypress Semiconductor 2700 162nd Street Building Lynnwood, 98087 Phone: 800.669.0557 Fax: 425.787.4641 http://www.cypress.com/ Copyright 2006 Cypress Semiconductor Corporation. rights reserved. PSoC registered trademark Cypress Semiconductor Corp. "Programmable System-on-Chip," PSoC Designer PSoC Express trademarks Cypress Semiconductor Corp. other trademarks registered trademarks referenced herein property their respective owners. information contained herein subject change without notice. Made U.S.A. 2/22/2006 Revision Other recent searchesT2322B - T2322B T2322B Datasheet SN74LVC821 - SN74LVC821 SN74LVC821 Datasheet PQ1CZ38M2Z - PQ1CZ38M2Z PQ1CZ38M2Z Datasheet KSK-1A87-2025 - KSK-1A87-2025 KSK-1A87-2025 Datasheet In-circuit - In-circuit In-circuit Datasheet emulator - emulator emulator Datasheet MINICUBE - MINICUBE MINICUBE Datasheet QB-78K0SKX1MINI-EE - QB-78K0SKX1MINI-EE QB-78K0SKX1MINI-EE Datasheet 78K0S - 78K0S 78K0S Datasheet series - series series Datasheet HMC221 - HMC221 HMC221 Datasheet CTLM1074-M832D - CTLM1074-M832D CTLM1074-M832D Datasheet
Privacy Policy | Disclaimer |