ST STM8-TOUCH-LIB User Manual

STM8-TOUCH-LIB
STM8 touch sensing library
Data brief
Features
Complete C source code library with firmware
Both resistor-capacitor (RC) and charge
transfer (CT) acquisition principles supported
Multifunction capability to combine capacitive
sensing functions with traditional MCU features (communications, LED/beeper/ LCD control)
Configuration of STM8 GPIO as touchkey
Flexible touchkey/wheel/slider configuration
and combination – RC acquisition: up to 24 keys and 2
wheels/sliders supported
– CT acquisition: up to 16 keys and 2
wheels/sliders supported
Acquisition, filtering and calibration functions
Enhanced processing features for optimized
sensitivity and immunity
Touch-sensing user interface through firmware
API for status reporting and application configuration
MCU resources
– Minimized number of external components – Reduced MCU memory space
Up to 8-bit wheel/slider resolution with only
three capacitive sensing channels
Active shield feature
Compliance with MISRA
Compliance with Cosmic, IAR and Raisonance
C compilers
Description
STMicroelectronics STM8-TOUCH-LIB is a touch sensing library that provides a complete robust free source-code solution to transform any 8-bit STM8 microcontroller into a capacitive touch sensing controller. This solution allows designers familiar with the use of standard microcontrollers to create higher-end human interfaces by replacing conventional electromechanical switches by touch sensing keys.
The STM8 touch sensing library is part of the application firmware. It allows combining various capacitive sensing touchkey, wheels or sliders with traditional MCU features (communications, control of LEDs, beeper or LCD) in the same application.
Two acquisition principles, RC and CT, are available and can be configured at compiling level. Both acquisition principles offer the same advanced processing algorithms to filter out noise and to compensate environmental parameters such as temperature, humidity, and power supply variation.
September 2010 Doc ID 17896 Rev 1 1/9
For further information contact your local STMicroelectronics sales office.
www.st.com
9
Resistor-capacitor (RC) acquisition principle STM8-TOUCH-LIB

1 Resistor-capacitor (RC) acquisition principle

The RC acquisition principle consists in measuring the charge and discharge time duration of a RC cell made of the electrode capacitance (C
) and a load resistor (RL).
X
The RC acquisition is supported by all STM8S and STM8L microcontrollers and requires a direct connection of the device to earth to operate properly.
The main features are the following:
Up to 24 touchkeys distributed over 3 GPIO ports
Up to 2 wheels or sliders with 2 different hardware implementations (5 or 8 capacitive
sensing channels)
Capacitive sensing channels are acquired sequentially

2 Charge transfer (CT) acquisition principle

The charge transfer acquisition consists in charging the electrode capacitance (CX) and transferring part of the accumulated charge into a sampling capacitor (C repeated until the voltage across C
reaches a given threshold. The number of transfers
S
required to reach the threshold depends on the size of the electrode capacitance. This acquisition principle provides a better sensitivity and robustness than RC acquisition.
). This sequence is
S
It requires a dedicated hardware composed of analog switches and STM8L MCU.
The charge transfer acquisition is only supported by STM8L101x and STM8L15x devices since it requires a dedicated hardware composed of analog switches used to interconnect several GPIOs which is only available on these products.
The main features are the following:
Number touchkeys supported
Up to 6 touchkeys on STM8L101x MCUs
Up to 16 touchkeys on STM8L15x MCUs
Up to 2 wheels or sliders with a single hardware implementation (3 capacitive sensing
channels)
Number of capacitive sensing channels acquired simultaneously
Up to 2 channels on STM8L101x MCUs
Up to 8 channels on STM8L15x MCUs
2/9 Doc ID 17896 Rev 1
STM8-TOUCH-LIB Library architecture
CORE
-AIN3TATE
-ACHINE
!0)LAYER
+EYS3TATE
-ACHINE
!PPLICATIONLAYER
4IMEBASE
(7LAYER
3ERVICES
AI
2#ACQUISITION
34-,X
#4ACQUISITION
34-,X
#4ACQUISITION

3 Library architecture

Figure 1 shows the STM8-TOUCH-LIB firmware layers.
Figure 1. STM8-TOUCH-LIB architecture
Doc ID 17896 Rev 1 3/9
MCU resources STM8-TOUCH-LIB

4 MCU resources

Tab le 1 shows the STM8 peripherals that are used by the STM8-TOUCH-LIB. Care must be
taken when using them to avoid any misbehavior.
Table 1. List of STM8 peripherals used by the STM8-TOUCH-LIB
Peripheral Function Acquisition principle
GPIOs I/O control RC, CT
16-bit timer with 8-bit prescaler (TIM2 or TIM3)
8-bit timer (TIM4)
Comparator (COMP) Charge transfer CT
Routing interface (RI) I/O control and charge transfer CT

4.1 Number of charge transfer capacitive sensing channels

measurement RC
V
IH/VIL
Generic timebase for the state machine
RC, CT
Tab le 2 and Ta b l e 3 provide the maximum number of charge-transfer capacitive sensing
channels for the STM8L101x and STM8L15x package, respectively.
Table 2. STM8L101x resources used for CT acquisition
group
Acquisition
Group
1
Group
2
Maximum number
of channels
TSSOP20 / UFQFPN20 WFQFPN28 VFQFPN32 / LQFP32
I/O port
TSSOP pin
PB0 10 7
PB1 11 8 13 14
PD0 9 6 8 9
PD1 - - 9 10
PB2 12 9
PB3 13 10 15 16
PD2 - - 10 11
pin
UFQFPN
Number of
3
2
available
pins
channels
with one sampling capacitor
1 channel
with one sampling capacitor
Usage
2
Pin
12
14
PD3 - - 11 12
3
with 2 sampling capacitors
pins
available
Number of
channels
4
with one sampling capacitor
channels
4
with one sampling capacitor
6
with 2 sampling
capacitors
Usage
3
Pin
13
Number of
pins
available
Usage
3
channels
4
with one sampling capacitor
15
3
3
channels
4
with one sampling capacitor
6
with 2 sampling
capacitors
4/9 Doc ID 17896 Rev 1
STM8-TOUCH-LIB MCU resources
Table 3. STM8L15x resources used for CT acquisition
STM8L151 (no LCD) STM8L152 (with LCD)
WFQFPN28 WFQFPN32 / LQFP32 VFQFPN48 / LQFP48 WFQFPN32 / LQFP32 VFQFPN48 / LQFP48
Number
I/O port
Acquisition group
PA 6 -
Group
PA 5 5 5 6 5 6
1
PA 4 4 4 5 4 5
PC7 -
PC4
Group
2
PC3
PC2
Group
PD7 - 24 36
3
PD6 - 23 35
PD5 -
Group
PD4
4
PB7
PB6
Group
PB5
5
PB4
PB3
Group
PB2
6
PB1
PB0
Group
PD3
7
PD2
PD1 9
Group
PD0 8 9 20 - 20
8
PE5 - - 19 - 19
Maximum
number of
channels
of
Pin
available
pins
2
2 5
2
2 4
2 3
1
2
2
0
1 9
1 8
1
3
7
1 6
1 5
1
3
4
1 3
1 2
1
3
1
1 0
2
10 channels
with 7 sampling
capacitors
Usage
1
channel
with 1 sampling capacitor
1
channel
with 1 sampling capacitor
cannot
be used
for
touch
sensing
1
channel
with 1 sampling capacitor
2
channels
with 1 sampling capacitor
2
channels
with 1 sampling capacitor
2
channels
with 1 sampling capacitor
1
channel
with 1 sampling capacitor
Number
of
3
2
3
3
3
3
3
2
capacitors
Usage
2
channels
with 1 sampling capacitor
1
channel
with 1 sampling capacitor
2
channels
with 1 sampling capacitor
2
channels
with 1 sampling capacitor
2
channels
with 1 sampling capacitor
2
channels
with 1 sampling capacitor
2
channels
with 1 sampling capacitor
1
channel
with 1 sampling capacitor
Pin
available
pins
6
-
29 43
28 42
27
22
21 33
20 31
19
18 29
17 28
16
15 26
14 25
13
12 23
11 22
10
14 channels
with 8 sampling
Number
of
Pin
available
pins
7
46
41
34
30
27
24
21
16 channels
with 8 sampling
capacitors
Number
Usage
2
channels
with 1
3
sampling capacitor
2
channels
with 1
3
sampling capacitor
2
channels
3
with 1 sampling capacitor
2
channels
with 1
3
sampling capacitor
2
channels
with 1
3
sampling capacitor
2
channels
with 1
3
sampling capacitor
2
channels
with 1
3
sampling capacitor
2
channels
with 1
3
sampling capacitor
of
Pin
available
pins
6
3
-
2 9
2
2 8
2 7
2
3
4
2 3
2 2
2
3
1
2 0
1 9
1
3
8
1 7
1 6
1
3
5
1 4
1 3
1
3
2
1 1
1 0
1
13 channels
with 7 sampling
capacitors
Usage
2
channels
with 1 sampling capacitor
1
channel
with 1 sampling capacitor
2
channels
with 1 sampling capacitor
2
channels
with 1 sampling capacitor
2
channels
with 1 sampling capacitor
2
channels
with 1 sampling capacitor
2
channels
with 1 sampling capacitor
cannot
be used
for
touch
sensing
Number
Pin
available
pins
7
46
43
42
41
36
35
34
33
31
30
29
28
27
26
25
24
23
22
21
16 channels
with 8 sampling
capacitors
of
Usage
2
channels
with 1
3
sampling capacitor
2
channels
with 1
3
sampling capacitor
2
channels
3
with 1 sampling capacitor
2
channels
with 1
3
sampling capacitor
2
channels
with 1
3
sampling capacitor
2
channels
with 1
3
sampling capacitor
2
channels
with 1
3
sampling capacitor
2
channels
with 1
3
sampling capacitor
Doc ID 17896 Rev 1 5/9
Memory resources STM8-TOUCH-LIB

5 Memory resources

The STM8-TOUCH-LIB size depends on the following parameters:
Acquisition principle (RC or CT)
C compiler and options: memory model, size or speed optimization
Number of capacitive sensing channels used and type (touchkey or/and wheel or
slider)
For further information on memory resources for RC and CT acquisition, refer to
Section 5.1.

5.1 RC acquisition memory resources

Prerequisites

COSMIC STM8 C Compiler 16-KByte version release 4.3.1 dated 02 July 2009
Compiler options: +modsl0 +compact +split
Sections counted for RAM: ZRAM_TSL_IO + ZRAM_TSL + ZRAM_TSLMCK +
RAM_TSL_IO + RAM_TSL + RAM_TSLMCK
Sections counted for ROM: CODE_TSL_IO + CONST_TSL_IO + CONST_TSL +
CONST_TSLMCK + CODE_TSL + CODE_TSLMCK

RAM and ROM requirements

Tab le 4 gives the RAM and ROM memory space required to use the STM8-TOUCH-LIB for
RC acquisition.
Table 4. Typical RAM and ROM memory space required for RC acquisition
Configuration RAM (bytes) ROM (bytes)
STM8S207
5x single-channel keys
STM8L101x
3x single-channel keys
~120 ~2350
~90 ~2350

5.2 CT acquisition memory resources

Prerequisites

COSMIC STM8 C Compiler 16-Kbyte version release 4.3.1 dated 02 July 2009
Compiler options: +modsl0 +compact +split
Sections counted for RAM: ZRAM_TSL_IO + ZRAM_TSL + ZRAM_TSLMCK +
RAM_TSL_IO + RAM_TSL + RAM_TSLMCK
Sections counted for ROM: CODE_TSL_IO + CONST_TSL_IO + CONST_TSL +
CONST_TSLMCK + CODE_TSL + CODE_TSLMCK
6/9 Doc ID 17896 Rev 1
STM8-TOUCH-LIB Memory resources

RAM and ROM requirements

Tab le 4 gives the RAM and ROM memory space required to use the STM8-TOUCH-LIB for
CT acquisition.
Table 5. Typical RAM and ROM memory space required for CT acquisition
Configuration RAM (bytes) ROM (bytes)
STM8L101x
3x single-channel keys
STM8L15X
10x single-channel keys
STM8L15X
10x single-channel keys +
1x multichannel key
~90 ~1800
~220 ~1700
~280 ~4200
Doc ID 17896 Rev 1 7/9
Revision history STM8-TOUCH-LIB

6 Revision history

Table 6. Document revision history
Date Revision Changes
27-Sep-2010 1 Initial release.
8/9 Doc ID 17896 Rev 1
STM8-TOUCH-LIB
Please Read Carefully:
Information in this document is provided solely in connection with ST products. STMicroelectronics NV and its subsidiaries (“ST”) reserve the right to make changes, corrections, modifications or improvements, to this document, and the products and services described herein at any time, without notice.
All ST products are sold pursuant to ST’s terms and conditions of sale.
Purchasers are solely responsible for the choice, selection and use of the ST products and services described herein, and ST assumes no liability whatsoever relating to the choice, selection or use of the ST products and services described herein.
No license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted under this document. If any part of this document refers to any third party products or services it shall not be deemed a license grant by ST for the use of such third party products or services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoever of such third party products or services or any intellectual property contained therein.
UNLESS OTHERWISE SET FORTH IN ST’S TERMS AND CONDITIONS OF SALE ST DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY WITH RESPECT TO THE USE AND/OR SALE OF ST PRODUCTS INCLUDING WITHOUT LIMITATION IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE (AND THEIR EQUIVALENTS UNDER THE LAWS OF ANY JURISDICTION), OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT.
UNLESS EXPRESSLY APPROVED IN WRITING BY AN AUTHORIZED ST REPRESENTATIVE, ST PRODUCTS ARE NOT RECOMMENDED, AUTHORIZED OR WARRANTED FOR USE IN MILITARY, AIR CRAFT, SPACE, LIFE SAVING, OR LIFE SUSTAINING APPLICATIONS, NOR IN PRODUCTS OR SYSTEMS WHERE FAILURE OR MALFUNCTION MAY RESULT IN PERSONAL INJURY, DEATH, OR SEVERE PROPERTY OR ENVIRONMENTAL DAMAGE. ST PRODUCTS WHICH ARE NOT SPECIFIED AS "AUTOMOTIVE GRADE" MAY ONLY BE USED IN AUTOMOTIVE APPLICATIONS AT USER’S OWN RISK.
Resale of ST products with provisions different from the statements and/or technical features set forth in this document shall immediately void any warranty granted by ST for the ST product or service described herein and shall not create or extend in any manner whatsoever, any liability of ST.
ST and the ST logo are trademarks or registered trademarks of ST in various countries.
Information in this document supersedes and replaces all information previously supplied.
The ST logo is a registered trademark of STMicroelectronics. All other names are the property of their respective owners.
© 2010 STMicroelectronics - All rights reserved
STMicroelectronics group of companies
Australia - Belgium - Brazil - Canada - China - Czech Republic - Finland - France - Germany - Hong Kong - India - Israel - Italy - Japan -
Malaysia - Malta - Morocco - Philippines - Singapore - Spain - Sweden - Switzerland - United Kingdom - United States of America
www.st.com
Doc ID 17896 Rev 1 9/9
Loading...