cancel
Showing results for 
Search instead for 
Did you mean: 

Touch Sensing Library (STM32Cube_FW_L0_V1.12.1) uses delay which depends on fixed system clock!

STE_Michael
Associate II

In STM32Cube_FW_L0_V1.12.1\Middlewares\ST\STM32_TouchSensing_Library\src\tsl.c, the value TSL_Globals.DelayDischarge is initialized in TSL_Init() as:

TSL_Globals.DelayDischarge = (uint32_t)((TSLPRM_DELAY_DISCHARGE_ALL * (uint32_t)(SystemCoreClock /1000000)) / 72);  

It is noticeable that :
- 72 is used as magicNumber
- DelayDischarge also changes when the SystemClock is changed, i.e. when the main clock of the STM32 is changed, the behavior of the touch evaluation could change unexpectedly.

- What is with IAR Compiler?

TSL_Globals.DelayDischarge is only used for the SoftDelay() function tsl_acq_tsc.c

/**
  * @brief  Software delay (private routine)
  * @param  val Wait delay
  * @retval None
  * @note Measurements done with HCLK=72MHz and Keil/MDK-ARM compiler
  * val =  500: ~ 63us
  * val = 1000: ~126us
  * val = 2000: ~251us
  */
void SoftDelay(uint32_t val)
{
  volatile uint32_t idx;
  for (idx = val; idx > 0; idx--)
  {}
}

This is therefore only a software delay. The commentary shows that the approximate values were measured with a main clock of HCLK=72MHz. This is presumably where the magicNumber 72 above comes from. So if the value of DelayDischarge should not depend on the SystemClock, the assignment in TSL_Init() would probably have to be changed.

The question is whether other delay functions are available for SoftDelay(), which delay a microsecond duration independently of the system clock so that the touch parameters (especially TSLPRM_DELAY_DISCHARGE_ALL) do not depend on the system clock.

1 REPLY 1
Stassen.C
ST Employee

Hi STE_Michael,

You are right it is only a software delay and this allows that all capacitors to be completely discharge.
The formula

TSL_Globals.DelayDischarge = (uint32_t)((TSLPRM_DELAY_DISCHARGE_ALL * (uint32_t)(SystemCoreClock /1000000)) / 72);  

is linked to the system clock, there is a define in the tsl_conf.h

#define TSLPRM_DELAY_DISCHARGE_ALL (1000)

You can update this value to get your desired delay. For now we don't have any other function doing this.

I hope I answered your question

 


Regards
Stassen

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.