This example shows two ways to have CapSense Linear Sliders in the Cypress PSoC4 Pioneer Kit.
The RGB LED color Red and Green are used to demonstrate the operation with help of mixing them as one slides the finger across the Linear slider.
Here is the Application Schematics:
Automatic Self Calibrating - Smart Sense
The first part of the this example deals with the use of the Capsense CSD module to perform the detection with auto calibration and sense patterns.
In this case the SCB based I2C module is not required.
Here are the configuration for the CapSense module { CapSense CSD [v1.11] } to have the automatic mode:
Here is the PWM module Configuration:
In this case we are using the Smart Sense feature of the CSD module. The Linear slider has 5 sense pads and is divided into 127 divisions.
The Input filter used here is the Stand IIR filter for high frequency noise filtering. These setting have been adapted from the system example of CapSense CSD PSoC4.
However without much of details one can easily realize this example thanks to Cypress PSoC Creator and handy component Library based API generation.
Here is the code to achieve the LED color mixing in Smart Sense mode.
#include <project.h> uint16 old,pos; int main() { // Enable Global Interrupts need for internal processing of the CapSense module CyGlobalIntEnable; // Start the PWM module PWM_1_Start(); // Initialize the CSD module CapSense_1_Start(); // Clear the Sensor baselines to begin the auto calibration cycle CapSense_1_InitializeAllBaselines(); while(1) { // Enable the Sensor Auto calibration CapSense_1_UpdateEnabledBaselines(); // Scan the Linear Slider CapSense_1_ScanEnabledWidgets(); // Wait till the operation completes while(CapSense_1_IsBusy() != 0); // Get the Present Values for the Linear Slider output pos = CapSense_1_GetCentroidPos(CapSense_1_LINEARSLIDER0__LS); // Check for errors and nullyfy non detection events if(pos == 0x0FFFFu) { pos = 0u; } // Check of the Value changed if( old != pos) { old = pos; // Update the LED outputs if(pos != 0) PWM_1_WriteCompare(pos<<9); } } }
This program would alter the PWM duty cycle with respect to the Linear slider value. This intern would light up the corresponding LED color brighter.
Tuner Calibrated CSD
There might be a need to also calibrate the internal algorithm and threshold values of the CSD module, in order to have better detection and accuracy in a given product scenario. For this the CSD Tuner is used.
The CSD Tuner uses the system I2C to communicate the calibration values. For this we would need to slave I2C module to interface. The PSoC 5 on the Pioneer kit would act as the I2C Tuner host to control the CSD on the PSoC 4.
Here are the settings for the I2C Slave module{ EZI2C Slave (SCB mode) [v1.10] } :
In order to have the Tuner enable we would need to change the settings for the CapSense CSD module also:
The rest of the configuration remains the same for the PWM module.
Now the code from the earlier automatic mode changes in order to support the Slave I2C communications and the calibration by the tuner.
#include <project.h> uint16 old,pos; int main() { // Enable Global Interrupts need for internal processing of the CapSense module CyGlobalIntEnable; // Start the PWM module PWM_1_Start(); // Initialize the CSD Tuner module CapSense_1_TunerStart();; while(1) { // Process Communications to the Tuner UI CapSense_1_TunerComm(); // Get the Present Values for the Linear Slider output pos = CapSense_1_GetCentroidPos(CapSense_1_LINEARSLIDER0__LS); // Check for errors and nullyfy non detection events if(pos == 0x0FFFFu) { pos = 0u; } // Check of the Value changed if( old != pos) { old = pos; // Update the LED outputs if(pos != 0) PWM_1_WriteCompare(pos<<9); } } }
Once to the code is build and loaded one needs to start the Tuner utility. To do so 'Right click' on the CapSense CSD module and Start the Tuner:
In the tuner window click on the Configuration button:
The add the following configuration and Press 'ok' to confirm:
Finally click on the Start button the enable the communications.
There are many features in the CSD Tuner that help to calibrate and configure the CSD module as needed for a specific use case.
Also since the levels of the touch are visible as analog and graphs one can perform adjustment in the Noise and Finger threshold to avoid false detection.
Although one needs to re-configure the CSD to perform the calibration, this ensure better sensitivity in the specific application scenarios when the CapSense items is packaged into the systems.
For example the CapSense button pad can be under the Glass or fiber window on a system then it would need special configuration to have reliable operation. This is where the tuner would be really helpful.