PSoC Creator的Component Tuners查看Capsense信号量状态
在设计过程中,通常因为EMC实验导致TouchKey的状态异常,而导致功能产生紊乱,需要找到异常的原因,对应修改相应的配置参数来减小影响。下面以普通的Touch Key按键为例,介绍如何使用Tuners实时查看当前TouchKey的状态。
第一步配置capsense
- 从PSoC Creator的左侧栏目中选择Capsense拖拽至TopDesign.cysch内
- 点击拖拽出来的CapSense,选择需要放置的Capnsense(控件),本例中选择Button,选择自容方式,模式选择手动;
- 在参数配置栏按照实际需要进行对应的参数配置
- 配置Tuners的连接通道,本例中选择I2C,Tuners 调试时,电路板做为从机。从PSoC Creator的左侧栏目中选择I2C拖拽至TopDesign.cysch内,并配置I2C作为从机的地址,与速率。
- 在PSoC Creator 的pin 中绑定配置相应的引脚
- 保存编译,在mian.c中添加capsense与EZI2C的启动代码
/*Set the macro value to '1' to use tuner for debugging and tuning CapSense sensors
Set the macro value to '0' to disable the tuner*/
#define ENABLE_TUNER (1u)
/* Finite state machine for device operating states
SENSOR_SCAN - Sensors are scanned in this state
WAIT_FOR_SCAN_COMPLETE - CPU is put to sleep in this state
PROCESS_DATA - Sensor data is processed, LEDs are controlled,
*/
typedef enum
{
SENSOR_SCAN = 0x01u,
WAIT_FOR_SCAN_COMPLETE = 0x02u,
PROCESS_DATA = 0x03u,
} DEVICE_STATE;
int main(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
/*start EZI2C block*/
EZI2C_Start();
#if ENABLE_TUNER
/* Set up I2C communication data buffer with CapSense data structure
to be exposed to I2C master on a primary slave address request
*/
EZI2C_EzI2CSetBuffer1(sizeof(CapSense_dsRam),\
sizeof(CapSense_dsRam),(uint8 *)&CapSense_dsRam);
#else
/*Set up communication data buffer with CapSense slider centroid
position and button status to be exposed to EZ-BLE Module on CY8CKIT-149 PSoC 4100S Plus Prototyping Kit*/
EZI2C_EzI2CSetBuffer1(sizeof(i2cBuffer), sizeof(i2cBuffer),i2cBuffer);
#endif
/* Place your initialization/startup code here (e.g. MyInst_Start()) */
DEVICE_STATE currentState = SENSOR_SCAN;
/* Start CapSense block */
CapSense_Start();
for(;;)
{
/* Place your application code here. */
/* Switch between SENSOR_SCAN->WAIT_FOR_SCAN_COMPLETE->PROCESS_DATA states */
switch(currentState)
{
case SENSOR_SCAN:
/* Initiate new scan only if the CapSense block is idle */
if(CapSense_NOT_BUSY == CapSense_IsBusy())
{
#if ENABLE_TUNER
/* Update CapSense parameters set via CapSense tuner before the
beginning of CapSense scan
*/
CapSense_RunTuner();
#endif
/* Scan widget configured by CSDSetupWidget API */
CapSense_ScanAllWidgets();
/* Set next state to WAIT_FOR_SCAN_COMPLETE */
currentState = WAIT_FOR_SCAN_COMPLETE;
}
break;
case WAIT_FOR_SCAN_COMPLETE:
/* Put the device to CPU Sleep until CapSense scanning is complete*/
if(CapSense_NOT_BUSY != CapSense_IsBusy())
{
CySysPmSleep();
}
/* If CapSense scanning is complete, process the CapSense data */
else
{
currentState = PROCESS_DATA;
}
break;
case PROCESS_DATA:
/* Process data on all the enabled widgets */
CapSense_ProcessAllWidgets();
/* User code based on the result of Widget processing. */
/* Set the device state to SENSOR_SCAN */
currentState = SENSOR_SCAN;
break;
/*******************************************************************
* Unknown power mode state. Unexpected situation.
******************************************************************/
default:
break;
}
}
}
- 编译下载到线路板中,然后将EZI2C的SDA ,GND,SCL连接调试器,然后点击Tools---->Component Tuners----->CapSense进入Tuners调试。因为只配置了一个Capsense,所以只有一个。

- 进入Tuners界面后,选择通讯方式I2C,配置I2C的速率,从机地址等参数(保持与配置的EZI2C一致)。
- 点击connect,连接成功后,点击start开始捕捉touch.
触摸按键,查看实时信号量
tuners