
Overview
========

 In this code example, the CSA_EMC UM scans all the buttons and slider segments 
 on the SLM continuously and an EzI2Cs buffer is updated with the various 
 CapSense parameters continuously so that the I2CUSB bridge can be used to read 
 the capsense parameters and display the same on PC using bridge control panel. 
 The code example also turns ON/OFF the LEDs present on the SLM  to indicate the button 
 status and slider position.

Operation
=========

 Upon program execution all hardware settings from the device configuration are
 loaded into the device and main.c is executed. CSA_EMC, EzI2Cs UMs are 
 initialized. All sensors are scanned continuously & the RawCounts, difference counts
 and the baseline data is updated in the EzI2Cs buffer. When any button is 
 touched by the user, its corresponding LED is  turned ON. and it is turned OFF 
 when the button is released. When Slider is touched, One LED is turned on 
 depending on the finger position on slider.
	
Pin Assignment
==============

	P0[3] - Cmod		(Connect Capacitor, 2.2nF between Pin P0[3] & Gnd)
	P1[6] - SW0			(CapSense button 0)
	P1[3] - SW1			(CapSense button 1)
	P3[3] - SW2			(CapSense button 2)
	P2[1] - SW3			(CapSense button 3)
	P2[3] - SW4			(CapSense button 4)
	P2[4] - SLD4		(Slider Segment 4)
	P2[2] - SLD3		(Slider Segment 3)
	P2[0] - SLD2		(Slider Segment 2)
	P3[2] - SLD1		(Slider Segment 1)
	P3[0] - SLD0		(Slider Segment 0)
	P2[5] - LED0		(Active Low)
	P2[7] - LED1		(Active Low)
	P0[1] - LED2		(Active Low)
	P0[5] - LED3		(Active Low)
	P1[2] - LED4		(Active Low)
	P1[0] - EzI2Cs SDA
	P1[1] - EzI2Cs SCL

Project Settings
================

 The following changes have to be made in the Device Editor:
  1. Selecting & placing user modules from catalog
      a. Select CSA_EMC under Cap Sensors & place it. Rename it to 
	    "CSA_EMC".
	  b. Select EzI2Cs under Digital Comm & place it. Rename it to "EzI2Cs".
  2. Configure the global resources & user modules settings as given below.
  3. Assign pins for sensor buttons & slider from CapSense wizard
  4. Assign pins for LED in Pinout section
 
 A. Global Resources
     IMO Setting  = 24MHz     ;System clock is set to 24MHz
  	 CPU_Clock    = SysClk/1  ;CPU clock set to 12 MHz
	 [leave all other parameters with default values]

 B. User Module parameter Settings
	-------------------------------------------------------------------------------------------------------------------
 	UM			Parameter 			Value 			Comments   
	-------------------------------------------------------------------------------------------------------------------
	CSA_EMC		        Finger Threshold	88				Finger threshold is to decide the ON/OFF condition of the sensor. 
													It should be set to 75% of finger response/signal
														
				Noise Threshold		44				If the RawCounts change by an amount less than Noise theshold, it is 
													considered as noise and the baseline bucket is updated to track the RawCounts.
													Noise threshold should be set to 40% of finger response.
														
				BaseLine Update		88				Baseline update threshold decides how fast the baseline should track
				Threshold							the RawCounts. 
													It is generally set to double the noise theshold	
				
				Settling time		80				Calculate as per the formula given in CY8C20x34 Design Guide		
														
				Sensors Autoreset	Disabled		When the parameter is set to disabled, the baseline is updated only when raw count 
													& baseline difference is below the noise threshold parameter. Enabling this parameter
													limits the maximum activated time of sensors. 
														
				Hysteresis			16				It is generally to take care of false ON and OFF situations whenever Button is 
													pressed. It should be sent to 15% of signal.
															
				Debounce			3				If the Difference count is more than Finger Threshold for less than 'Debounce' number 
													of samples, it will not be taken as a Button Press.
				
				Negative Noise		44				If the Raw Count is below BaseLine and the Difference Count is more than this
				Threshold							threshold, the BaseLine will not update. This parameter helps in overcoming
													spike noise in negative direction.
													It should be set equal to noise threshold.
				
				Low BaseLine Reset 	50				If the Raw Count is below BaseLine and the Difference Count is more than 
													Negative Noise Threshold for number of samples given by this parameter, the BaseLine 
													will reset to new Raw Count. A value of 10 is generally recommended for this parameter.

				
	
	--------------------------------------------------------------------------------------------------------------------------------------------
	
	EzI2Cs		Slave Address		04				This parameter decides the address that is assigned to the slave.If we set Address_Type 
													to 'Dynamic', this can be changed using APIs during the Run. Value assigned can be any vaue
													from 0 to 127 (decimal)
														
				ROM Registers		Disable			If we set this to Enable, we can use RAM area as one slave and ROM area as one slave with 
													the addresses differing by only MSB of 7-bit address.
													
													MSB = 1 ---> ROM Regsters addressed.
													MSB = 0 ---> RAM area addressed.
													
				HW Addr Rec			Disabled		This parameter enables/disables the hardware I2C slave address recognition feature. It
													affects ROM/RAM usage and EzI2Cs ISR execution time.
														
				I2C Pin				P1[0]-P1[1]		This tells which pins are going to be used as SDA and SCL lines of I2C.
				
				I2C Clock			400k Standard	It decides the maximum clock speed that the slave can operate at.
	-------------------------------------------------------------------------------------------------------------------------------------------- 
 C. Pin Drive modes
   	 1. EzI2Cs pins
       	 Pin	    Select	            Drive
    	 ----------------------------------------------
    	 P1[0]	   	EzI2CsSDA    		Open Drain Low, Initial Value=1	
		 P1[1]		EzI2CsSCL			Open Drain Low, Initial Value=1	
		 ----------------------------------------------
	 2. Sensor & LED
     	 Pin	    Select	            Drive
    	 ----------------------------------------------
		 P1[6]		SW0		HIGH Z Analog
		 P1[3]		SW1		HIGH Z Analog
		 P3[3]		SW2		HIGH Z Analog
		 P2[1]		SW3		HIGH Z Analog
		 P2[3]		SW4		HIGH Z Analog
		 P1[4]		SLD0	HIGH Z Analog
		 P0[6]		SLD1	HIGH Z Analog
		 P0[4]		SLD2	HIGH Z Analog
		 P0[2]		SLD3	HIGH Z Analog
		 P2[6]		SLD4	HIGH Z Analog
		 P2[4]		SLD5	HIGH Z Analog
		 P2[2]		SLD6	HIGH Z Analog
		 P2[0]		SLD7	HIGH Z Analog
		 P3[2]		SLD8	HIGH Z Analog
		 P3[0]		SLD9	HIGH Z Analog
		 P0[3]	   	Cmod	HIGH Z Analog
		 P2[5]		LED0	STRONG, Initial Value=1
		 P2[7]		LED1	STRONG, Initial Value=1
		 P0[1]		LED2	STRONG, Initial Value=1
		 P0[5]		LED3	STRONG, Initial Value=1
		 P1[2]		LED4	STRONG, Initial Value=1

