|
本帖最后由 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周年了!感谢大家的支持与爱护!!
一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。
|