
Overview
========

 This project is an example for usage of EzI2C user module to send the CapSense 
 data to the I2C Master. It incorporates the CSD user module for capacitive
 sensing algorithm. The CapSense module scans all the buttons and sliders 
 continuously and stores the button Raw Count, Difference Count, Baseline, status
 and the slider centroid details in a structure defined by MyI2CRegs. This 
 Structure is used by the EzI2Cs Module to send the data to master whenever required.	
	
Operation
=========

 Upon program execution all hardware settings from the device configuration are
 loaded into the device and main.c is executed. CSD, EzI2Cs UMs are 
 initialized. All sensors are scanned continuously & I2C buffer is updated with 
 ON/OFF status of each button & centroid position of slider. 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)
	P1[4] - SLD0		(Slider Segment 0)
	P0[6] - SLD1		(Slider Segment 1)
	P0[4] - SLD2		(Slider Segment 2)
	P0[2] - SLD3		(Slider Segment 3)
	P2[6] - SLD4		(Slider Segment 4)
	P2[4] - SLD5		(Slider Segment 5)
	P2[2] - SLD6		(Slider Segment 6)
	P2[0] - SLD7		(Slider Segment 7)
	P3[2] - SLD8		(Slider Segment 8)
	P3[0] - SLD9		(Slider Segment 9)
	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 "User Modules" catalog
      a. Select CSD under Cap Sensors & place it. Rename it to 
	    "CSD".
	  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 buttons & slider segments from CSD 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 24 MHz
	 [leave all other parameters with default values]

 B. User Module parameter Settings
	-------------------------------------------------------------------------------------------------------------------
 	UM			Parameter 			Value 			Comments   
	-------------------------------------------------------------------------------------------------------------------
	CSD			Finger Threshold	108				Finger threshold is to decide the ON/OFF condition of the sensor. 
											It should be set to 75% of finger response/signal
														
				Noise Threshold		58				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		116				Baseline update threshold decides how fast the baseline should track
				Threshold						the RawCounts.It is generally set to double the noise theshold 
														
											
														
				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		21				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		58				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 	10				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.

				iDAC Value		20				Capacitance measurement range depends on this parameter if auto-calibration is
											not enabled. This parameter has no effect if auto-calibration is enabled

				Resolution		13				Higher the resolution, higher will be the sensitivity.

				Scanning Speed		Fast				Decides the speed of scanning process.
													
				ShieldElectrodeOut	None				Shield electrode is not used in this project.
														
				PrechargeSource		PRS				This parameter selects PRS as the clock source for precharge switches.

				Prescaler		4				This parameter determines the precharge switch output frequency.

				PRS Resolution		8 bit				This parameter sets the PRS sequence length. Sequence length for 8 bit is 511.

				Autocallibration	Enabled				This parameter enables a successive approximation for the iDAC setting that establishes a raw count
											baseline at or above 85 percent. Autocalibration should always be set to enabled in CY8C20xx6A
											CSD designs.
														
				iDAC Range		4x				Sets the current range of IDAC.

	-------------------------------------------------------------------------------------------------------------------
	
	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 API
											during runtime. Value assigned can be any vaue	from 0 to 7Fh.

				Address_Type		Static			    	If set to static, I2C address cannot be changed dynamically during 
											runtime, but, saves	one byte of RAM. Setting this option to dynamic 
											allows the firmware to change the address at any time.
														
				ROM Registers		Disable		        	If we set this to Enable, we can use RAM area as one slave and ROM 
											area as another slave with the addresses differing only by MSB of 
											7-bit address.
														
											MSB = 1 ---> ROM Regsters addressed.
											MSB = 0 ---> RAM area addressed.
														
											E.g: if slave address is 0x0A, RAM address=0x0A & ROM address=0x4A

				HW Addr Rec		Disable				This parameter enables/disables the hardware I2C slave address 
				                          
				
				I2C Clock		400k Fast			It decides the maximum clock speed that the slave can operate at.
											recognition feature.	
													
				I2C Pin			P1[0]-P1[1]			Pins assigned for SDA and SCL lines of I2C.
	-------------------------------------------------------------------------------------------------------------------

 C. Pin Drive modes
   	 1. I2C Lines
       	 Pin	    Select	            Drive
    	 ----------------------------------------------
    	 P1[0]	   I2C SDA	    	Open Drain Low
	 P1[1]	   I2C SCL		Open Drain Low
		 ----------------------------------------------
	 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
		
