cancel
Showing results for 
Search instead for 
Did you mean: 

Capacitive Touch Sensing with STM32F302R8

MS.1134
Associate III

Which evaluation board I can use to practice and develop code on Capacitive Touch Sensing, which is suitable with STM32F302R8?

I have STM32F302 Nucleo board with STM32F302R8 MCU, which supports touch sensing. I need to learn and develop a practice code for capacitive touch sensing - sliders and buttons with this MCU and Nucleo board.

Which evaluation board I can use with this MCU that provides capacitive sliders / buttons and allow to develop a capacitive development practice project?

I am new to capacitive sensing code development, so some initial guidance about how to start would be very much helpful...

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
OlivierR
ST Employee

Hello,

You can also have a look at AN5105. There are 2 examples working in pooling mode for slider and button based on DISCO-F072B&L0538. See chapters 7.2 and 7.3.

As TSC peripheral is the same in L0, F0, F3, L4 software and design will be similar.

Even if DISCO-L0538 include a slider, this slider is used as 3 buttons for test purpose only.

Olivier

View solution in original post

9 REPLIES 9
Amel NASRI
ST Employee

Hi @Community member​ ,

Ready to use TouchSensing examples are available for the 3 STM32 evaluation boards. You find them under the following paths in STM32CubeF3 package:

  • STM32Cube_FW_F3_V1.11.0\Projects\STM32373C_EVAL\Applications\TouchSensing
  • STM32Cube_FW_F3_V1.11.0\Projects\STM32303E_EVAL\Applications\TouchSensing
  • STM32Cube_FW_F3_V1.11.0\Projects\STM32303C_EVAL\Applications\TouchSensing

I think that what you need the most to understand more about the touch sensing applications is to refer to UM1913: 'Developing applications on STM32Cube

 with STMTouch touch sensing library'.

AN3236 may interest you as well.

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

MS.1134
Associate III

Thank you so much for your replay, Amel,

I will study the applications and app note you suggested.

But how would I try to develop a capacitive touch based practice application to test?

Are there any demo evaluation board - like Nucleo or Discovery board that can be interfaced with my STM32F302 Nucleo board that provides touch sensors - sliders / rotor for me to test the application from Keil?

Or do I need to design my own PCB layout for such evaluation?

I am trying to develop a simple practice project for capacitive touch using STM32F302 Nucleo board.

Thank you

OlivierR
ST Employee

Hello,

You can also have a look at AN5105. There are 2 examples working in pooling mode for slider and button based on DISCO-F072B&L0538. See chapters 7.2 and 7.3.

As TSC peripheral is the same in L0, F0, F3, L4 software and design will be similar.

Even if DISCO-L0538 include a slider, this slider is used as 3 buttons for test purpose only.

Olivier

MS.1134
Associate III

thank you, OlivierR

MS.1134
Associate III

Hello, I've reviewed AN5105 and UM1913 application notes and as per the polling based example given in AN5105, I've tried to explore and understand the sample code given for STM32F072B-Disco evaluation board. Though, I was able to modify the sample code and get the sensors to detect touch indicated by the LEDs, I have some confusion and questions as below which I am trying to understand. Your help in explaining this concept is much appreciated!!

1. Resolution and Calculation of Position in the range of 0...255:

How do I calculate the position of the touch on the slider given in this example / in general?

My understanding is that this should be equally divided in the range of 0...255. In this discovery board, as there are 3 sensors configured as Linear Half ended electrode, each position should be (approximately) divided in the range of 255 / 3, isn't it?

Please explain how would I calculate position of the touch on the sensor.

From the header file, these are some configurations that I have been tweaking to understand how to calculate finger position but I am getting all strange LED response of the touch..

#define TSLPRM_USE_3CH_LIN_H (0)

#define TSLPRM_LINROT_RESOLUTION (7)

I am using MyLinRots[0].p_Data->Position structure to compare the position value in the range of 0...255 but not able to understand the correlation of the value and touch. How does Resolution value 1..8 affect this calculation? What's the formula for such correlation? Why is the TSLPRM_LINROT_RESOLUTION configured to 7 with this example? If I change this to any other value in the range of 1..8, I can't get the slider to provide evenly distributed response with 3 Ch. in the position of 0...255.

I am trying to get 4 LEDs to be evenly distributed in the entire slider over the range of 0...255 with the following code:

if(MyLinRots[0].p_Data->StateId == TSL_STATEID_DETECT)

{

//TSLPRM_LINROT_RESOLUTION

if(MyLinRots[0].p_Data->Position >= 1 && MyLinRots[0].p_Data->Position < 60)

{

HAL_GPIO_WritePin(LD4_GPIO_Port, LD3_Pin, GPIO_PIN_SET);

HAL_GPIO_WritePin(LD4_GPIO_Port, LD4_Pin, GPIO_PIN_RESET);

HAL_GPIO_WritePin(LD6_GPIO_Port, LD6_Pin, GPIO_PIN_RESET);

HAL_GPIO_WritePin(LD5_GPIO_Port, LD5_Pin, GPIO_PIN_RESET);

}

if(MyLinRots[0].p_Data->Position >= 60 && MyLinRots[0].p_Data->Position < 120)

{

HAL_GPIO_WritePin(LD4_GPIO_Port, LD3_Pin, GPIO_PIN_RESET);

HAL_GPIO_WritePin(LD6_GPIO_Port, LD6_Pin, GPIO_PIN_RESET);

HAL_GPIO_WritePin(LD4_GPIO_Port, LD4_Pin, GPIO_PIN_SET);

HAL_GPIO_WritePin(LD5_GPIO_Port, LD5_Pin, GPIO_PIN_RESET);

}

if(MyLinRots[0].p_Data->Position >= 120 && MyLinRots[0].p_Data->Position < 180)

{

HAL_GPIO_WritePin(LD4_GPIO_Port, LD3_Pin, GPIO_PIN_RESET);

HAL_GPIO_WritePin(LD5_GPIO_Port, LD5_Pin, GPIO_PIN_RESET);

HAL_GPIO_WritePin(LD4_GPIO_Port, LD4_Pin, GPIO_PIN_RESET);

HAL_GPIO_WritePin(LD6_GPIO_Port, LD6_Pin, GPIO_PIN_SET);

}

if(MyLinRots[0].p_Data->Position >= 180 && MyLinRots[0].p_Data->Position < 255)

{

HAL_GPIO_WritePin(LD4_GPIO_Port, LD3_Pin, GPIO_PIN_RESET);

HAL_GPIO_WritePin(LD5_GPIO_Port, LD5_Pin, GPIO_PIN_SET);

HAL_GPIO_WritePin(LD4_GPIO_Port, LD4_Pin, GPIO_PIN_RESET);

HAL_GPIO_WritePin(LD6_GPIO_Port, LD6_Pin, GPIO_PIN_RESET);

}

}

else //if(MyLinRots[0].p_Data->StateId == TSL_STATEID_RELEASE)

{

HAL_GPIO_WritePin(LD4_GPIO_Port, LD3_Pin, GPIO_PIN_RESET);

HAL_GPIO_WritePin(LD4_GPIO_Port, LD4_Pin, GPIO_PIN_RESET);

HAL_GPIO_WritePin(LD5_GPIO_Port, LD5_Pin, GPIO_PIN_RESET);

HAL_GPIO_WritePin(LD6_GPIO_Port, LD6_Pin, GPIO_PIN_RESET);

}

}

2. How does this calculation and response changes if I configure the same linear sensor available on the F072 Disco board as TSLPRM_USE_3CH_LIN_M1 / M2 / D type electrode design? How does it affect position calculation? How to modify this sensor to act as 4 individual touch keys?

3. How can I modify the code to be interrupt driven?

As I am new to touch library and trying to learn firmware development with touch sensor, please bear with me with the questions above and your time and support is much appreciated..

Thank you.

MS.1134
Associate III

Attached is another touch key practice project that I was trying to learn. I am trying to configure 3 touch keys on the STM32F072B-Disco board and trying to turn on a single LED based on touch detect on any of 3 keys. When I configure TSLPRM_TKEY_Detect_IN_TH and TSLPRM_TKEY_Detect_OUT_TH as default of 110 & 120, the project compiles without any error. On the Disco board, I can only detect press of two keys. I can't detect press of the key configured in half mode. Why?

To detect the other two keys, I have to press very hard and often times, it's very difficult to detect touch on these two keys.

So, I changed threshold of Detect In & OUT to lower value - 50.

With this change, I get 15 errors in compiling that the value is out of the range.

I don't understand what is it that I am doing wrong and how can I configure 3 touch keys on this slider?

Your help is much appreciated!

Thank you,

MS.1134
Associate III

Hello,

I had a few questions as I posted last week in this thread and waiting for some answers..

I am very much interested in learning TSC / capacitive touch based libraries and developing my own application. Your support is very much appreciated with the questions I posted above, which would help me understand the process better.. thank you and looking forward for some update..

Hello MS, 

Regarding point 1)

See tsl_conf.h comments regarding these defines:

#define TSLPRM_USE_3CH_LIN_H (0)   ==> Must be set as DISCO is using Half-ended 3 channels electrodes design

#define TSLPRM_LINROT_RESOLUTION (7) ==> This mean 0 to 128

Q:divided in the range of 255 / 3, isn't it?

No, resolution give full range from left to right.

Regarding point 2)

You must keep _H for DISCOF072 (See tsl_conf.h comments):

M1 = Mono electrodes design with 0/255 position at extremities of the sensor

M2 = Mono electrodes design

H = Half-ended electrodes design

Q:How to modify this sensor to act as 4 individual touch keys?

This is not possible as half-ended electrodes are connected.

You need to new design for this.

Have a look at TSLPRM_LINROT_USE_NORMDELTA parameter to improve linearity.

Set MyLinRots and MyLinRot_DeltaCoeff in tsl_user.c according AN.

Regarding point 3)

Have a look here.

thank you so much, OlivierR

I will review the notes and will work on the practice project again to fully understand the concept.

I will let you know if I run into any further questions.