PSoC Creator的Component Tuners查看Capsense信号量状态

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值