搜索
bottom↓
回复: 2

如何解决STM8S触摸键在临界距离,键状态反复翻转?

[复制链接]

出0入213汤圆

发表于 2017-7-28 14:33:47 | 显示全部楼层 |阅读模式
本帖最后由 jyrpxj 于 2017-7-28 16:01 编辑

通过IO接LED指示键的按下与松开。

现在遇到的问题是:
手指悬停在在临界感应距离时,键状态反复翻转。

主程序
void main(void)
{
        _asm("sim");
        GPIO1_Init();
        CLK_Init_RC16();
        DelayXms(200);
        TSL_Init();
        ExtraCode_Init();
        PB_ODR=PBBAK;
        IWDG_Init();
        while(1)
        {
                IWDG_KR = 0x0AA; //刷新看门狗
                DelayXms(20);
                ExtraCode_StateMachine();
                TSL_Action();
        }
}


stm8_tsl_conf.h 文件的参数配置
//============================================================================
//
// 12) TSL PARAMETERS CONFIGURATION
//
//============================================================================

/** @addtogroup TSL_parameters_RC
  * @{ */

// IO acquisition
#define SCKEY_ACQ_NUM                   (4)  /**< Single channel key acquisition number - N (value from 1 to 255) */
#define SCKEY_ADJUST_LEVEL              (2)  /*1*< Single channel key adjustment level (value from 0 to 255) */
#define MCKEY_ACQ_NUM                   (6)  /**< Multi channel key acquisition number - N (value from 1 to 255) */
#define MCKEY_ADJUST_LEVEL              (1)  /**< Multi channel key adjustment level (value from 0 to 255) */

// IO acquisition number of rejected values and measure guardbands
#define MAX_REJECTED_MEASUREMENTS       (5)  /**< Max number of rejected measurements allowed (value from 0 to 255) */
#define MAX_MEAS_COEFF             (0x0200)//(0x0126)  /**< Max measure guardband (MSB=integer part, LSB=decimal part) */
#define MIN_MEAS_COEFF             (0x00D9)  /**< Min measure guardband (MSB=integer part, LSB=decimal part) */

// Thresholds
#define SCKEY_DETECTTHRESHOLD_DEFAULT          (3)  /*2*< Single channel key detection threshold (value from 1 to 127) */
#define SCKEY_ENDDETECTTHRESHOLD_DEFAULT        (9)  /*8*< Single channel key end detection threshold (value from 1 to 127) */
#define SCKEY_RECALIBRATIONTHRESHOLD_DEFAULT  (-10)  /**< Single channel key calibration threshold (value from -1 to -128) */
#define MCKEY_DETECTTHRESHOLD_DEFAULT          (30)  /**< Multi channel key detection threshold (value from 1 to 127) */
#define MCKEY_ENDDETECTTHRESHOLD_DEFAULT       (20)  /**< Multi channel key end detection threshold (value from 1 to 127) */
#define MCKEY_RECALIBRATIONTHRESHOLD_DEFAULT  (-30)  /**< Multi channel key calibration threshold (value from -1 to -128) */

// MCKey resolution
#define MCKEY_RESOLUTION_DEFAULT                   (4)  /**< Multi channel key resolution (value from 1 to 8) */

// MCKey Direction Change process
#define MCKEY_DIRECTION_CHANGE_ENABLED               (1)  /**< Multi channel key direction change enable (1) or disable (0) switch */
#define MCKEY_DIRECTION_CHANGE_MAX_DISPLACEMENT    (255)  /**< Multi channel key direction change maximum displacement (value from 0 to 255) */
#define MCKEY_DIRECTION_CHANGE_INTEGRATOR_DEFAULT    (1)  /**< Multi channel key direction change integrator (value from 1 to 255) */
#define MCKEY_DIRECTION_CHANGE_THRESHOLD_DEFAULT    (10)  /**< Multi channel key direction change threshold (value from 1 to 255) */

// Integrators
#define DETECTION_INTEGRATOR_DEFAULT       (2)  /**< Detection Integrator = Debounce Filter (value from 0 to 255) */
#define END_DETECTION_INTEGRATOR_DEFAULT   (2)  /**< End detection Integrator = Debounce Filter (from 0 to 255) */
#define RECALIBRATION_INTEGRATOR_DEFAULT  (10)  /**< Calibration integrator (value from 1 to 255) */

// IIR Filter
#define ECS_TIME_STEP_DEFAULT  (20)  /**< Sampling frequency, multiple of 10ms */
#define ECS_TEMPO_DEFAULT      (20)  /**< Delay after detection, multiple of 100ms */
#define ECS_IIR_KFAST_DEFAULT  (20)  /**< K factor for fast filtering */
#define ECS_IIR_KSLOW_DEFAULT  (10)  /**< K factor for slow filtering */

// Detection Timeout
#define DTO_DEFAULT  (0)  /**< 1s unit (value from 0 (= infinite!) to 255) */

// Automatic Calibration
#define NEGDETECT_AUTOCAL (1)  /**< 0 (Enable negative threshold for noise), 1 (Enable autocalibration)  */

// Acquisition values limits
#define SCKEY_MIN_ACQUISITION    (50) /**< Single channel key minimum acquisition value */
#define SCKEY_MAX_ACQUISITION  (3000) /**< Single channel key maximum acquisition value */
#define MCKEY_MIN_ACQUISITION    (75) /**< Multi channel key minimum acquisition value */
#define MCKEY_MAX_ACQUISITION  (5000) /**< Multi channel key maximum acquisition value */

// Optional parameters for Delta Normalization Process (for Multi channel keys only).
// The MSB is the integer part, the LSB is the real part:
// For example to apply a factor 1.10:
// 0x01 to the MSB
// 0x1A to the LSB (0.1 x 256 = 25.6 -> 26 = 0x1A)
// Final value to define is: 0x011A

#define MCKEY1_DELTA_COEFF_A (0x0100) /**< MCKey1 Channel A parameter */
#define MCKEY1_DELTA_COEFF_B (0x0100) /**< MCKey1 Channel B parameter */
#define MCKEY1_DELTA_COEFF_C (0x0100) /**< MCKey1 Channel C parameter */
#define MCKEY1_DELTA_COEFF_D (0x0100) /**< MCKey1 Channel D parameter */
#define MCKEY1_DELTA_COEFF_E (0x0100) /**< MCKey1 Channel E parameter */
#define MCKEY1_DELTA_COEFF_F (0x0100) /**< MCKey1 Channel F parameter */
#define MCKEY1_DELTA_COEFF_G (0x0100) /**< MCKey1 Channel G parameter */
#define MCKEY1_DELTA_COEFF_H (0x0100) /**< MCKey1 Channel H parameter */

#define MCKEY2_DELTA_COEFF_A (0x0100) /**< MCKey2 Channel A parameter */
#define MCKEY2_DELTA_COEFF_B (0x0100) /**< MCKey2 Channel B parameter */
#define MCKEY2_DELTA_COEFF_C (0x0100) /**< MCKey2 Channel C parameter */
#define MCKEY2_DELTA_COEFF_D (0x0100) /**< MCKey2 Channel D parameter */
#define MCKEY2_DELTA_COEFF_E (0x0100) /**< MCKey2 Channel E parameter */
#define MCKEY2_DELTA_COEFF_F (0x0100) /**< MCKey2 Channel F parameter */
#define MCKEY2_DELTA_COEFF_G (0x0100) /**< MCKey2 Channel G parameter */
#define MCKEY2_DELTA_COEFF_H (0x0100) /**< MCKey2 Channel H parameter */

// Interrupt synchronisation
#define IT_SYNC  (1) /**< Interrupt synchronisation. (=1) Allow to synchronize the aquisition with a flag set in an interrupt routine */

// Spread spectrum
#define SPREAD_SPECTRUM      (0) /**< Spread spectrum. (=1) Add a variable delay between acquisitions */
#define SPREAD_COUNTER_MIN   (1) /**< Spread min value */
#define SPREAD_COUNTER_MAX  (20) /**< Spread max value */

// RTOS Management of the acquisition (instead of the timebase interrupt sub-routine
#define RTOS_MANAGEMENT    (0) /**< The Timebase routine is launched by the application instead to be managed through a timebase interrupt routine */
// Timer Callback to allow the user to add its own function called from the timer interrupt sub-routine
#define TIMER_CALLBACK (0)    /**< if (1) Allows the use of a callback function in the timer interrupt. This function will be called every 0.5ms. The callback function must be defined inside the application and have the following prototype FAR void USER_TickTimerCallback(void);  */
/** @} */


//========已自己用老办法解决============
连续检测20次,在20次中有大于14次按下,则判为按下,在20次中有少于6次按下,则判为松开,如果介于这6~14之间,则采用上次的判断结果。
去抖效果非好,只是不能使用快速双击了。


阿莫论坛20周年了!感谢大家的支持与爱护!!

一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。

出0入8汤圆

发表于 2017-7-28 14:48:18 来自手机 | 显示全部楼层
st的库有滞回比较的功能
你把detect和enddetect的threshold改一下

出0入0汤圆

发表于 2017-7-28 14:33:48 来自手机 | 显示全部楼层
用状态机的扫描,消抖处理
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-18 01:05

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表