AN4316 · Application noteHow to tune touch sensing applications on STM32 MCUs
Download .pdfOpen in the full document

Monitoring STMTouch driver variables using STM-Studio

Monitoring STMTouch driver variables using STM-Studio

The main parameters to trim a touch sensing application are the following:

  • Channel reference: “Ref” element of an array of TSL_ChannelData_T structure
  • Channel delta: “Delta” element of an array of TSL_ChannelData_T structure
  • Object state: “StateId” element of an array of TSL_TouchKeyData_T structure or a TSL_LinRotData_T structure

This list is not exhaustive and depends on the application.

To import these variables, the steps listed below must be followed:
  1. Open the STM-Studio tool corresponding to the used MCU.
  2. Right-click in the Display Variables tab and select Import or select the File/Import Variables menu.
  3. In the Import variables from executable window (shown in the figure below):
    1. Select the application Elf file (.elf, .out or .axf) through the Executable file field using the Browse button
    2. Check the Expand table elements box.
    3. Check the Store executable path relatively to the user settings file box to use a relative path.
    4. Enter ‘Ref’ in the Show symbol containing... text box.
    5. Select Add variables to the display variables table in the Variables list box.
    6. Select the ‘.Ref’ ended variables and click on the Import button or Ctrl+Click to operate an noncontinuous multi-selection.
    7. Repeat step d) and f) with ‘Delta’.
    8. Repeat step d) and f) with ‘StateId’
    9. Click on the Close button.
Figure 1. STM-Studio variable selection window

Once imported, the variables must be assigned to the viewer in order to be displayed. Follow the steps listed below:

  1. As described previously, select some variables in the Display Variables settings table.
  2. Right-click in the table and select Send To →VarViewer1 or drag them directly to the right viewer.
  3. In the Viewers settings window dock, right-click in the greyed part and select New VarViewer. A new VarViewer2 tab appears.

To ease the navigation, the VarViewer windows can be renamed with the name of the monitored variables (right click and rename).

Variables can be displayed as a curve, as a bar graph or in a table. The display in table is recommended for variables with very slow variation. Curve and bar graph suit for variables with quick variation (see examples in the figure below).

Figure 2. VarViewers with variable name

The value range for each VarViewer window can be adjusted:

  • The Delta depends on the application sensitivity and can be positive or negative.
  • The State varies from 0 to 19 (refer to TSL_StateId_enum_T in tsl_types.h for the meaning of this value).
  • The reference depends on CX/CS.

Connect a PC to the application with the selected binary code downloaded in the microcontroller (through a USB cable and the appropriate hardware tool such as an ST-LINK). Click on the green arrow or select the “Run/Start” menu to start the monitoring.

Data can be stored in a file with the below actions (see the figure below):
  1. Open Options and Acquisition Settings window.
  2. Check the Log to file box and set the log file path.
Figure 3. Data log setting

Tuning the thresholds

This section details how to select reliable thresholds depending on the application use cases.

Capacitive touch sensing applications are sensitive to earth coupling. The parameter tuning must be done in the same environment as the final application. The hardware tool connected to the application may change the earth coupling. This is especially true for example in battery power applications. ST is providing a galvanic insulated hardware tool (ST-LINK/V2-ISOL) to minimize this effect.

Use of a standard test finger

In order to build an application working with the widest range of people finger characteristics, the use of a standard test finger (see the figure below) gives a worst case but also allows the test repetition without human dependency (to test finger size, pressure and contact area or skin conductivity for example). An electrically conductive pen-shape tool with a flat rubber end is the most adequate for repetitive tests. The flat end made of conductive rubber allows a constant contact surface with the touchkey. The operator performing the validation must take care to center the contact area on the touchkey. A final validation with a panel of users may be planned.

Figure 4. Standard finger (8 mm diameter)

The figure below describes a recommended standard test finger.

Figure 5. Recommended standard finger

Touchkeys thresholds

To tune the detection thresholds, it is first necessary to determine the sensitivity of each touchkey, with the steps listed below:

  1. Connect the final hardware to a PC through ST-LINK/V2 and power the application.
  2. Download the firmware used in the final application with the final parameters of the STMTouch driver. The default detection thresholds can be set to a low value but must be kept higher than the noise level.
  3. Launch the STM-Studio tool and configure it as explained in STM-Studio overview.
  4. Use the standard finger as described in Use of a standard test finger.
  5. Touch a touchkey and move the finger in order to find the maximum delta. Write down this value, then repeat the operation for each touchkey. If around the maximum delta there is still significant jittering on the measure, then compute the average and use it as baseline.

The collected values are the thresholds baseline. If a significant variation exists between the baseline of the application touchkeys, it is recommended to set a specific threshold for each touchkey.

The detection threshold that must be exceeded in order to report the touchkey as detected, must be set between 55 % and 65 % of the baseline. The end-of-detection threshold, below which the key is not detected anymore, must be set between 35 % and 45 % of the baseline (see the figure below).

Figure 6. Threshold position
An example of threshold firmware adjustment, with a baseline measured at 80 and a threshold adjusted between ~65 % and ~55 % of the baseline, is given below:
MyTKeys[0].p_Param->DetectInTh = 50; // Key 1 detection threshold
MyTKeys[0].p_Param->DetectOutTh = 30; // Key 1 end of detection threshold

The calibration threshold (TSLPRM_TKEY_CALIB_TH) can be common to all keys and set to 60 % of the maximum baseline.

If one of these thresholds must be greater than 255, the TSLPRM_COEFF_TH must be set in order to bring the value in the correct range [0;255]. This is obtained by dividing by two all thresholds (except the calibration threshold) to the power of TSLPRM_COEFF_TH. In that case, the divided coefficients values (except for the calibration threshold) are the values that need to be configured in the firmware. A compensation factor of two to the power of TSLPRM_COEFF_TH is then applied to all coefficients (except the calibration threshold) by the firmware.

Linear and rotary touch sensors thresholds

The approach is different for these sensors as they are composed of several channels. The standard test finger must be moved along the whole sensor and a log of the delta must be recorded using the STM-Studio tool.

Detection thresholds adjustment

A rotary sensor log example is shown is the figure below.

Figure 7. Rotary sensor log

The worst case delta as shown in the figure above must be considered as the baseline to compute the threshold for this sensor. This threshold must be reached in order to trig the computation of the position and to report a detection on this sensor.

The same ratio used for a touchkey can be applied to this baseline, so between 65 % and 55 % to enter in detection and between 35 % and 45 % to stop reporting a detection.

Balancing between channels

While a significant difference of sensitivity appears on the channels, the STMTouch driver provides a way to balance the delta in order to minimize the error on the position computation.

The sensitivity is determined with the maximum delta on each channel.

The figure below shows a log from a rotary sensor with an excessive difference of sensitivity.

Figure 8. Sensor log before balancing

To get well-balanced channels, a coefficient must be applied to each channel delta. This coefficient is the ratio between the maximum deltas of each channel. The reference channel is the one with the highest delta (A for channel 1), the others channels have their maximum delta in B for channel 0 and C for channel 2. The coefficient of channel 0 must be set to A/B and the one of channel 2 to A/C. Channel 1 is not changed and gets its coefficient at 1.

These coefficients must be multiplied by 255 as they are used as a fraction of 255.

For instance:

  • With A/B = 1.75, the coefficient is 488 = 0x1C0.
  • With A/C = 3, the coefficient is 768 = 0x300 then the code is the following one:
    CONST uint16_t MyLinRot0_DeltaCoeff[LINROT_CHANNELS] =
    {
    	0x1C0, 0x100, 0x300,// CH0, CH1, CH2
    };

MyLinRot0_DeltaCoeff is pointed by the p_DeltaCoeff item in the declaration of the TSL_LinRot_T or TSL_LinRotB_T structure (see the code below).

CONST TSL_LinRotB_T MyLinRots[TSLPRM_TOTAL_LNRTS] =
{
	{
    &MyLinRots_Data[0], 
    &MyLinRots_Params[0],
    &MyChannels_Data[CHANNEL_16_DEST],
    (TSL_tNb_T)LINROT_CHANNELS, 
    MyLinRot0_DeltaCoeff,  
    (TSL_tsignPosition_T *)TSL_POSOFF_3CH_LIN_INTERLACED,
    (TSL_tIndex_T) TSL_SCTCOMP_3CH_LIN_INTERLACED,
    (TSL_tIndex_T) TSL_POSCORR_3CH_LIN_INTERLACED
  }
};

Proximity

To define the proximity thresholds, the designer must consider the noise sensitivity and the expected detection distance, but also the minimum surface to detect.