This example demonstrates how any metal target can be converted into the CapSense target using Cypress PSoC 4 Pioneer Kit.
For metal target an old lock has been used. The PSoC4 enters deeps sleep for 2seconds and is woken up by the Watchdog timer.
After wake up it perform a capacitive sensing scan on the metal target and then goes back to sleep.
Here is the Application Schematics:
The CapSense module { CapSense CSD [v1.11] } needs to be configured as follows:
And the Digital output pin that is used to drive the LED is configured as follows:
In this case the CSD module is used without a tuner like the earlier Non-Tuner example. The CSD performs the scan after each wake-up and unless there is a detection the LED is turned off.
Here is the source code for this example:
#include <project.h> #include <cyPm.h> // Used for Deep Sleep mode entry uint8 val; // Used to obtain the CapSense value for the button - which is Arbitrary Metal target CY_ISR(Wakee) // ISR to handle the wakeup from DeepSleep { CySysWdtClearInterrupt(CY_SYS_WDT_COUNTER0_INT); CyIntClearPending(9); } int main() { CyIntSetVector(9, Wakee); // Setup the WDT Isr CyIntEnable(9); Pin_LED_Write(1); // Set the Default LED state as OFF CyGlobalIntEnable; // Enable the Interrupts CapSense_1_Start(); //Initialize CapSense Module CapSense_1_InitializeAllBaselines(); // WDT Configuration CySysWdtWriteMode(CY_SYS_WDT_COUNTER0,CY_SYS_WDT_MODE_INT_RESET); // Counter 0 with Reset in case 3times the interrupt is not serviced CySysWdtWriteMatch(CY_SYS_WDT_COUNTER0,0x2FFF); // Delay for wake-up from Deep Sleep CySysWdtWriteClearOnMatch(CY_SYS_WDT_COUNTER0, 1u); // Auto Clear the Timer CySysWdtEnable(CY_SYS_WDT_COUNTER0_MASK); //Enable the WDT CySysWdtLock(); // Lock WDT registers for(;;) { // Enable the Sensor Autocalibration CapSense_1_UpdateEnabledBaselines(); // Begin Scanning the Linear Sider CapSense_1_ScanEnabledWidgets(); // Wait for Scanning to Complete while(CapSense_1_IsBusy() != 0); // Obtain the Detection Value val = CapSense_1_CheckIsWidgetActive(CapSense_1_BUTTON0__BTN); if(val == 1) { Pin_LED_Write(0); // Turn On the LED if there was detection } else { Pin_LED_Write(1); //Else Turn OFf by default } CySysPmDeepSleep(); // Enter Sleep to be woken up by the WDT interrupt } }
After building and loading this program the Blue color in the RGB Led would be lit up when the metal object is touched.
An important thing to note is that the code generated by using IIR filter for the CapSense would be high. It would better if by tuning the Threshold and Noise coefficients and use a simpler jitter or averaging filter instead for this type of CapSense detection.
Here is a short video demonstrating the operation and current consumption for this example.