STM8L触摸库 CT模式下配置说明(希望对大家有所帮助)

2019-12-25 18:47发布

本帖最后由 iVIC 于 2013-10-24 23:03 编辑

最近有个客户产品上采用了STM8L系列的芯片,看了原理图刚好是采用的CT模式触摸,这两天从ST网站上下了CT模式的触摸库.理解了一部分,试着在客户的板子上跑跑触摸按键,没想到还成功了,在论坛上找了找,很少看到CT模式下的配置说明,现在和大家分享一下,说的不对的地方,望理解.
1:其实ST给出的触摸库中已经给出了说明.现在把触摸库的按键配置和大家分享一下.然后再一步步和大家解释.以下是CT模式下的配置.中文注释的地方是我用到的按键触摸部分说明.滚轮和划条由于产品上没有,也没法测试.过段时间有空打个板玩玩.

/**
  ******************************************************************************
  * @file    Example06_STM8L15x_LD_CT_10k_SWacqincstm8_tsl_conf.h
  * @author  MCD Application Team
  * @version V2.4.0
  * @date    01-July-2011
  * @brief   STM8 Touch Sensing Library - This file is a template for the
  *          Charge-Transfer acquisition and must be adapted to your requirements.
  ******************************************************************************
  * @attention
  *
  * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  *
  * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  ******************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __TSL_CONF_H
#define __TSL_CONF_H


//==============================================================================
//
// 1) MCU SELECTION
//
// 1 = STM8L10x
// 2 = STM8L15x with 4Kb or 8Kb Flash (low density) - Software acquisition mode
// 3 =   "        "   "      "             "        - Hardware acquisition mode
// 4 = STM8L15x with 16Kb, 32kb or 64Kb Flash (medium and high density)
//     STM8L16x
//==============================================================================

#define MCU_SELECTION  (2)     //第一步要选择MCU型号,我用的型片中4K的.所以选2


//==============================================================================
//
// 2) GENERIC TIMEBASE TIMER SELECTION (TIMTICK)
//
// Set the generic timebase timer.
// The timer you select must be a basic 8-bit timer.
// This table summarizes the values for some products (consult the datasheet
// if your product is not in the list):
// Product                TIMTICK
// STM8L15x               TIM4
// STM8L10x               TIM4
// Warning: The selected timer update/overflow interrupt vector must point to
// the TSL_Timer_ISR() interrupt routine.
//
//==============================================================================

#define TIMTICK         (TIM4)      //第二步.定时器选择.我用的是TM8L15x ,如上所说选TIM4


//==============================================================================
//
//  *** GROUP AND CHANNEL DESCRIPTION ***
//
//   CHARGE_TRANSFER group and channel description for STM8L10x devices
//       For more details please refer to the Comparator
//       section in the reference manual
//
// Group 1  CH1   PB0  __/____
//          CH2   PB1  __/__|
//          CH3   PD0  __/__|
//          CH4   PD1  __/__|
//
// Group 2  CH1   PB2  __/____
//          CH2   PB3  __/__|
//          CH3   PD2  __/__|
//          CH4   PD3  __/__|
//
//
//   CHARGE_TRANSFER group and channel description for STM8L15x devices
//       For more details please refer to the Routing Interface
//       section in the reference manual
// Group 1  CH1   PA6  __/____
//          CH2   PA5  __/__|
//          CH3   PA4  __/__|
//          CH4   PA7  __/__|  FOR STM8L15x with 4Kb or 8Kb Flash only
//
// Group 2  CH1   PC7  __/____
//          CH2   PC4  __/__|
//          CH3   PC3  __/__|
//          CH4   PE7  __/__|  FOR STM8L15x with 4Kb or 8Kb Flash only
//
//
// Group 3  CH1   PC2  __/____
//          CH2   PD7  __/__|
//          CH3   PD6  __/__|
//
// Group 4  CH1   PD5  __/____
//          CH2   PD4  __/__|
//          CH3   PB7  __/__|
//
// Group 5  CH1   PB6  __/____
//          CH2   PB5  __/__|
//          CH3   PB4  __/__|
//
// Group 6  CH1   PB3  __/____
//          CH2   PB2  __/__|
//          CH3   PB1  __/__|
//
// Group 7  CH1   PB0  __/____
//          CH2   PD3  __/__|
//          CH3   PD2  __/__|
//          CH4   PE3  __/__|  FOR STM8L15x with 4Kb or 8Kb Flash only
//
// Group 8  CH1   PD1  __/____
//          CH2   PD0  __/__|
//          CH3   PE5  __/__|
//          CH4   PE4  __/__|  FOR STM8L15x with 4Kb or 8Kb Flash only
//
// The below values are only used for the groups and channels settings.
// DO NOT change the values.
#define GROUP1 (0x01)
#define GROUP2 (0x02)
#define GROUP3 (0x04)
#define GROUP4 (0x08)
#define GROUP5 (0x10)
#define GROUP6 (0x20)
#define GROUP7 (0x40)
#define GROUP8 (0x80)
#define CH1    (1)
#define CH2    (2)
#define CH3    (3)
#define CH4    (4)                //以上参数不能修改.ST定义好的.
//==============================================================================






//==============================================================================
//
// 3) SAMPLING CAPACITOR CHANNEL SELECTION
//
// Set the sampling capacitors channel.
//
// The hardware for CHARGE_TRANSFER is done in such way that all the sampling
// capacitors have to be connected to the same channel of each group.
// For example, the sampling capacitors are connected to CH2 of each group.
//
//==============================================================================

#define SAMP_CAP_CH   (CH3)  /**< Possible values are CH1, CH2, CH3 and CH4 */

//电容通道配置,在GROUP1-8中,每一个GROUP中(4个IO或3个IO)要有一个引脚接一个电容,而接电容的引脚,在GROUP1-GROUP8中必须是同一通道,如以下两组
// Group 1  CH1   PA6  __/____
//          CH2   PA5  __/__|
//          CH3   PA4  __/__|
//          CH4   PA7  __/__|  FOR STM8L15x with 4Kb or 8Kb Flash only
//
// Group 2  CH1   PC7  __/____
//          CH2   PC4  __/__|
//          CH3   PC3  __/__|
//          CH4   PE7  __/__|  FOR STM8L15x with 4Kb or 8Kb Flash only
//
如果SAMP_CAP_CH  =(CH3),则第一组的PA4,和第二组的PC3,是接电容通道,电容连接原理图示例如下,第一组GROUP需要接一个电容.
STM8TouchSCH.jpg (115.89 KB, 下载次数: 1) 下载附件 2013-10-24 22:25 上传



//==============================================================================
//
// 4) SINGLE CHANNEL KEYS DEFINITION FOR CHARGE_TRANSFER - 1st Bank
//
// Set the number of keys
// Set the Channel (cannot be the channel defined for the sampling capacitor)
// Set the Group for each key
//
//==============================================================================

#define SCKEY_P1_KEY_COUNT  (5)        //第一通道按键数量,每组可以设置8个按键,有3组,一个最多可以支持24个(ST).有SCKEY_P1,SCKEY_P2,SCKEY_P3.
我的理解为有8个GROUP,假设第个GROUP有3个IO.那就是3*8=24个IO.但每组需要有一个电容引脚所以占用8个,那就是24-8=16个.也不知道理解对不对?

#define SCKEY_P1_CH   (CH1) /**< Possible values are CH1, CH2, CH3 and CH4 */   //选择按键通道号,如果选CH1就是指PA6,PC7,PC2, PD5, PB6  ,PB3,PB0,PD1,这几个引脚所接的触摸按键(见上面GROUP1-8定义
/**< Even if SCKEY_P1_KEY_COUNT is null          */
/**< SCKEY_P1_CH must contain the channel number */
/**< used by a multi-key*/

#define SCKEY_P1_A  (GROUP1)      //为这一通道配置按键,由于我们选择的是CH1,而GROUP1中CH1对应的是PA6,那就是说明PA6上我们接了一个触摸按键
#define SCKEY_P1_B  (GROUP5)      // PB6上我们接了一个触摸按键
#define SCKEY_P1_C  (GROUP6)      // PB3上我们接了一个触摸按键
#define SCKEY_P1_D  (GROUP7)      // PB0上我们接了一个触摸按键
#define SCKEY_P1_E  (GROUP8)      // PD1上我们接了一个触摸按键
#define SCKEY_P1_F  (0)
#define SCKEY_P1_G  (0)
#define SCKEY_P1_H  (0)

//上面参数不能空着写.如
#define SCKEY_P1_A  (GROUP1)      
#define SCKEY_P1_B  (0)                //这里不能为空,必须连续.
#define SCKEY_P1_C  (GROUP5)     
#define SCKEY_P1_D  (GROUP6)   
#define SCKEY_P1_E  (GROUP7)     
#define SCKEY_P1_F  (0)
#define SCKEY_P1_G  (0)
#define SCKEY_P1_H  (0)

//==============================================================================
//
// 5) SINGLE CHANNEL KEYS DEFINITION FOR CHARGE_TRANSFER - 2nd Bank
//
// Set the number of keys
// Set the Channel (cannot be the channel defined for the sampling capacitor)
// Set the Group for each key
//
//==============================================================================

#define SCKEY_P2_KEY_COUNT  (4)       //这里配置和上面说明一样,只不过有3个通道,这是第二个.这一通道我们配置了4个按键.
#define SCKEY_P2_CH   (CH2) /**< Possible values are CH1, CH2, CH3 and CH4 */
/**< Even if SCKEY_P2_KEY_COUNT is null                */
/**< SCKEY_P2_CH must contain the channel number       */
/**< used by a multi-key if different from SCKEY_P1_CH */


#define SCKEY_P2_A  (GROUP1)
#define SCKEY_P2_B  (GROUP5)
#define SCKEY_P2_C  (GROUP6)
#define SCKEY_P2_D  (GROUP8)
#define SCKEY_P2_E  (0)
#define SCKEY_P2_F  (0)
#define SCKEY_P2_G  (0)
#define SCKEY_P2_H  (0)


/*==============================================================================
//
// WARNING: FOR STM8L10x or STM8L15x devices with 4kb or 8kb Flash only
//
// 6) SINGLE CHANNEL KEYS DEFINITION FOR CHARGE_TRANSFER - 3rd Bank
//
// Set the number of keys
// Set the Channel (cannot be the channel defined for the sampling capacitor)
// Set the Group for each key
//
//==============================================================================*/

#if (MCU_SELECTION != 4)

#define SCKEY_P3_KEY_COUNT  (0)          //这里配置和上面说明一样,只不过有3个通道,这是第二个.如果不用说写0

#define SCKEY_P3_CH   (0) /**< Possible values are CH1, CH2, CH3 and CH4 */
/**< Even if SCKEY_P3_KEY_COUNT is null                */
/**< SCKEY_P3_CH must contain the channel number       */
/**< used by a multi-key if different from SCKEY_P1_CH */
/**< and SCKEY_P2_CH                                   */

#define SCKEY_P3_A  (0)
#define SCKEY_P3_B  (0)

// For STM8L15x devices with 4kb or 8kb Flash only
#if ((MCU_SELECTION == 2) || (MCU_SELECTION == 3))
#define SCKEY_P3_C  (0)
#define SCKEY_P3_D  (0)
#define SCKEY_P3_E  (0)
#define SCKEY_P3_F  (0)
#define SCKEY_P3_G  (0)
#define SCKEY_P3_H  (0)
#endif

#endif


//==============================================================================
//
// 7) NUMBER OF MULTI CHANNEL KEYS AND NUMBER OF CHANNELS USED
//
// Set the total number of multi channel keys used (0, 1 or 2)
//
//==============================================================================

#define NUMBER_OF_MULTI_CHANNEL_KEYS  (0)  /**< Number of multi channel keys (value from 0 to 2) */        //滚轮和划条配置.最多两.
//==============================================================================
//
// 8) MULTI CHANNEL KEYS DEFINITION FOR CHARGE_TRANSFER - 1st MCkey
//
// Set the Channel (cannot be the channel defined for the sampling capacitor)
// and the Group for each IO composing the MCkey
//
//==============================================================================

#if NUMBER_OF_MULTI_CHANNEL_KEYS > 0

#define MCKEY1_A_CH  (0)  /**< Multi channel key 1: 1st IO Channel */
#define MCKEY1_A     (0)  /**< Multi channel key 1: 1st IO Group */
#define MCKEY1_B_CH  (0)  /**< Multi channel key 1: 2nd IO Channel */
#define MCKEY1_B     (0)  /**< Multi channel key 1: 2nd IO Group */
#define MCKEY1_C_CH  (0)  /**< Multi channel key 1: 3rd IO Channel */
#define MCKEY1_C     (0)  /**< Multi channel key 1: 3rd IO Group */

#define MCKEY1_TYPE (0)   /**< Multi channel key 1 type: 0=wheel (zero between two electrodes), 1=slider (zero in the middle of one electrode) */

#endif


//==============================================================================
//
// 9) MULTI CHANNEL KEYS DEFINITION FOR CHARGE_TRANSFER - 2nd MCkey (optional)
//
// Set the Channel (cannot be the channel defined for the sampling capacitor)
// and the Group for each IO composing the MCkey
//
//==============================================================================

#if NUMBER_OF_MULTI_CHANNEL_KEYS > 1

#define MCKEY2_A_CH   (0)  /**< Multi channel key 2: 1st IO Channel */
#define MCKEY2_A      (0)  /**< Multi channel key 2: 1st IO Group */
#define MCKEY2_B_CH   (0)  /**< Multi channel key 2: 2nd IO Channel */
#define MCKEY2_B      (0)  /**< Multi channel key 2: 2nd IO Group */
#define MCKEY2_C_CH   (0)  /**< Multi channel key 2: 3rd IO Channel */
#define MCKEY2_C      (0)  /**< Multi channel key 2: 3rd IO Group */

#define MCKEY2_TYPE (0)    /**< Multi channel key 2 type: 0=wheel (zero between two electrodes), 1=slider (zero in the middle of one electrode) */

#endif



//============================================================================
//
// 10) TSL PARAMETERS CONFIGURATION
//
//============================================================================

/** @addtogroup TSL_parameters_CT
  * @{ */

// Thresholds
#define SCKEY_DETECTTHRESHOLD_DEFAULT          (20)  /**< Single channel key detection threshold (value from 1 to 127) */          //
#define SCKEY_ENDDETECTTHRESHOLD_DEFAULT       (10)  /**< 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          (45)  /**< Multi channel key detection threshold (value from 1 to 127) */
#define MCKEY_ENDDETECTTHRESHOLD_DEFAULT       (40)  /**< Multi channel key end detection threshold (value from 1 to 127) */
#define MCKEY_RECALIBRATIONTHRESHOLD_DEFAULT  (-45)  /**< Multi channel key calibration threshold (value from -1 to -128) */

// MCKey resolution
#define MCKEY_RESOLUTION_DEFAULT                   (7)  /**< 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) */

// 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    (150) /**< 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 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 */

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

//IO Protection from Interrupt modification
#define PROTECT_IO_ACCESS (1)  /**< Protect the IO access : to be enabled to allow the access to the IO registers used by the STM Touch library by any interrupt routine */

// Capacitance Loading Waiting HIGH Time Adjustment
#define CLWHTA    {nop();nop();nop();}  /**< Add here the necessary number of NOP  or a call to wait(n);*/
// Capacitance Loading Waiting LOW Time Adjustment
#define CLWLTA    {}  /**< Add here the necessary number of NOP or a call to wait(n);*/

// Spread spectrum
#define SPREAD_SPECTRUM      (1)  /**< Spread spectrum enabled (=1) */
#define SW_SPREAD_SPECTRUM   (0) /**< Software Spread spectrum enabled (=1) for STM8L15x only when the UART is also used, to comment if not used */
#define SPREAD_COUNTER_MIN   (1) /**< Spread min value (for STM8L10x devices or when STM8L15x and the Software Spread Spectrum is used) CAUTION :  0 is not a valid value*/
#define SPREAD_COUNTER_MAX  (20) /**< Spread max value (for STM8L10x devices or when the Software Spread Spectrum is used) or maximum amplitude of the HSI trimming for STM8L15x and Software Spread Spectrum disabled */
// Active Shield
#define ACTIVE_SHIELD_GROUP  (0) /**< Active Shield is disabled (=0), else this symbolic constant contains the group dedicated to this function, this group will be driven but never acquired  */
// 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);  */
//Inline functions
#define USE_INLINED_FUNCTIONS (0) /**< Inline functions are enabled (=1) */

// For STM8L15x with 4Kb or 8Kb Flash (low density) devices only
#define HW_ACQ_CT_PERIOD  (2)  /**< Charge-Transfer H/W acquisition period in 祍 unit (value from 1 to 10) */

/** @} */


//==============================================================================
//
// DEFINITIONS CHECK. DO NOT TOUCH ANYTHING BELOW !!!
//
//==============================================================================

#define CHARGE_TRANSFER (1)

// Automatic Calibration always enabled
#define NEGDETECT_AUTOCAL (1)

// Only 3 channels per MCKey are supported
#define CHANNEL_PER_MCKEY (3)
#define MCKEY1_D_CH   (0)
#define MCKEY1_D      (0)
#define MCKEY1_E_CH   (0)
#define MCKEY1_E      (0)
#define MCKEY1_F_CH   (0)
#define MCKEY1_F      (0)
#define MCKEY1_G_CH   (0)
#define MCKEY1_G      (0)
#define MCKEY1_H_CH   (0)
#define MCKEY1_H      (0)
#define MCKEY2_D_CH   (0)
#define MCKEY2_D      (0)
#define MCKEY2_E_CH   (0)
#define MCKEY2_E      (0)
#define MCKEY2_F_CH   (0)
#define MCKEY2_F      (0)
#define MCKEY2_G_CH   (0)
#define MCKEY2_G      (0)
#define MCKEY2_H_CH   (0)
#define MCKEY2_H      (0)

// Only the interlaced layout is supported
#define MCKEY1_LAYOUT_TYPE (0)
#define MCKEY2_LAYOUT_TYPE (0)

#include "stm8_tsl_checkconfig.h"

#endif /* __TSL_CONF_H */

/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/










2: 以下是工程文件,可以参考.
STM8_TouchS.rar (5.5 MB, 下载次数: 165) 2013-10-24 22:53 上传 点击文件名下载附件
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
10条回答
szxszx
1楼-- · 2019-12-25 22:42
好资料,学习了
ijlc1314
2楼-- · 2019-12-26 02:47
好资料,谢谢楼主,顺便请教一下,RC方式和CT方式有什么区别,哪种更好一点。
grs432
3楼-- · 2019-12-26 04:48
 精彩回答 2  元偷偷看……
i7gly
4楼-- · 2019-12-26 06:06
学习了!!!
hollandcy
5楼-- · 2019-12-26 10:18
哎 一早起来找这个资料了  收藏先
ZYBing
6楼-- · 2019-12-26 13:49
MARK,谢谢分享!

一周热门 更多>