1087 views|5 replies

444

Posts

0

Resources
The OP
 

【Fudan Microelectronics Automotive MCU FM33FT0A Series】--TSI Touch [Copy link]

This post was last edited by dirty on 2024-2-22 09:38

The development board FM33FT056A MCU integrates the touch detection function. The official provides a complete TSI touch solution with advantages such as preventing false liquid touches, suppressing electromagnetic interference, supporting overlay touches, and automatic tuning algorithms. Through the collaboration of software and hardware, it can be applied in the field of automotive electronic touch, such as touch applications for windows, lights, and central control panels. This article describes the implementation of TSI button touch and slider touch and position functions.

1. Hardware Principle

The development board has two touch buttons BT0 and BT1 and a touch slider SLDER. The schematic diagram and hardware are as follows

Figure 1: Touch buttons and sliders

The TSI module uses the self-capacitance method to detect touch behavior. Fudan Micro has a complete introduction to TSI. It integrates its own algorithm and is equipped with a debugging tool TSITuner. On the one hand, it saves costs, and on the other hand, it completes the closed loop in the solution application. This is a good job.

2. Code Preparation

The official provides TSIDemo, here are some interpretations, improvements, modifications and applications.

1. About TSI Software Library

(1). tsi.c, tsi.h: Contains the library's operation control functions (start, stop, etc.);
(2). tsi_baseline.c, tsi_baseline.h: Contains the baseline algorithm implementation;
(3). tsi_calibration.c, tsi_calibration.h: Contains the touch hardware parameter automatic calibration algorithm implementation;
(4). tsi_conf.h: User configuration file, some configurable parameters of the TSI software library are listed here. We only provide the template tsi_conf_template.h corresponding to this file. Users can modify it and rename it to tsi_conf.h for use.
(5). tsi_def.h: Contains some definitions required by the library, including some definitions of optional configuration parameter values.
(6). tsi_filter.c, tsi_filter.h: Contains the implementation of the RawCount filter.
(7). tsi_interrupt.c: Contains the interrupt service routine of the TSI module.
(8). tsi_objects.c, tsi_objects.h: tsi_objects.c contains all TSI module control definitions and parameters ( touch pins TSI_Pins and channel TSI_ChannelSensorMap, etc. ), tsi_objects.h contains all TSI software library data structure definitions. tsi_objects.c We only provide the corresponding template tsi_objects_template.c. Users can modify it and rename it to tsi_objects.h for use.
(9). tsi_sensor.c, tsi_sensor.h: Contains the configuration, initialization, and status update functions used by the sensor;
(10). tsi_widget.c, tsi_widget.h: Contains the configuration, initialization, and status update functions used by the widget;

2. Code modification

(1) Remove TSI_DEBUG_xxx from the main function, add the debug serial port printing mentioned above , and add buttons, slider touch and position detection . The code is as follows

int main(void)
{
    /* 使能IWDT */
    IWDT_Init(FL_IWDT_PERIOD_4000MS);

    /* Init FL driver library */
    FL_Init();

    /* 使能SVD, 阈?.157V(falling)~4.257V(rising) */
    SVD_Init(SVD_MONTIOR_VDD, FL_SVD_WARNING_THRESHOLD_GROUP11, FL_SVD_REFERENCE_1P0V);
    /* 确认SVD监测结果是否高于阈值,如否则持续等?*/
    while(false == SVD_Result_Confirmed(SVD_HIGHER_THRESHOLD, 2000U/*us*/));
    
    /* 使能BOR */
    RMU_BOR_Init(FL_RMU_BOR_THRESHOLD_2P00V);
   
    /* Init system clock */
    SystemClockInit();

    /* USER CODES AREA 1 BEGIN */

    /* USER CODES AREA 1 END */
    
    MF_Config_Init();
     
     
    /* Init TSI */
    TSI_Init();
    printf("TSI Init \r\n");
    
    /* Enable all widgets */
    TSI_Widget_EnableAll();

    /* Feed watchdog */
    FL_IWDT_ReloadCounter(IWDT);

    /* Start TSI */
    TSI_Start();
    printf("TSI Start \r\n");
    
    /* Feed watchdog */
    FL_IWDT_ReloadCounter(IWDT);
    
    /* Init and start TSI debug */
//    TSI_Debug_Init();
//    TSI_Debug_Start();

    /* USER CODES AREA 2 BEGIN */

    /* USER CODES AREA 2 END */

    while(1)
    {   
        /* USER CODES AREA 3 BEGIN */

        /* USER CODES AREA 3 END */

        /* Feed watchdog */
        FL_IWDT_ReloadCounter(IWDT);

        /* 电源掉电监测处理 */
        PowerDownMonitoring();

        /* Handle debug event */
        TSI_Debug_Handler();

        /* USER CODES AREA 4 BEGIN */

        /* USER CODES AREA 4 END */
              
        /* Wait until a scan sequence has completed */
        if(TSI_GETSTAT_SCAN_CPLT())
        {   
			
            TSI_CLRSTAT_SCAN_CPLT();
            
            /* Update all widgets */
            TSI_Widget_UpdateAll();

			if(TSI_WidgetList.bt0.buttonStatus==1)
			{
				printf("bt0 is touched\r\n");
			}

			if(TSI_WidgetList.bt1.buttonStatus==1)
			{
				printf("bt1 is touched\r\n");
			}
              
            
			if(TSI_WidgetList.slider.sliderStatus==1)
			{
				printf("silder is touched,position:%d--[range:0-255]\n",TSI_WidgetList.slider.centerPos);
			}

            
            /* Update debug interface trace buffer */
//            TSI_Debug_UpdateTrace();

            /* USER CODES AREA 5 BEGIN */

            /* USER CODES AREA 5 END */
        }

        /* USER CODES AREA 6 BEGIN */

        /* USER CODES AREA 6 END */
    }
}

(2) When debugging the simulation, it was found that the slider trigger status was not set. The official code has a bug. Modify TSI_Widget_UpdateSlider and add sliderWidget->sliderStatus=sliderWidget->base.status; the complete function is as follows:

void TSI_Widget_UpdateSlider(TSI_SliderWidgetTypeDef* sliderWidget)
{
    if(sliderWidget->base.status == 1U)
    {
        int i;
        uint8_t peakIndex = 0U;
        uint16_t peakSignalVal = 0U;
        uint16_t centroidCalcData[3];
        uint16_t threshold = sliderWidget->base.activeTh - sliderWidget->base.activeHys;
        int32_t centroid;
        const TSI_MetaWidgetTypeDef *metaWidget = sliderWidget->base.meta;
        TSI_SensorTypeDef* sensor = metaWidget->sensors;
        int32_t mul = (TSI_SLIDER_RESOLUTION / (metaWidget->sensorCnt - 1)) << 8U;

        /* 
            Calculate the slider postion using centroid algorithm:
            1. Find the sensor X with the highest signal, which is the center of the touched area;
            2. Calcuate centroid using X's neighbour sensor;
        */
        
        /* Find peak value and corresponding sensor */
        for (i = 0; i < metaWidget->sensorCnt; i++)
        {
            if(sensor->diffCount > threshold && sensor->diffCount > peakSignalVal) 
            {
                peakIndex = i+1;
                peakSignalVal = sensor->diffCount;
            }
            sensor++;
        }
        
        if(peakIndex != 0)
        {
            /* Get neighbour sensors signal value */
            sensor = metaWidget->sensors;
            if(peakIndex == 1)
            {
                centroidCalcData[0] = 0;
                centroidCalcData[1] = peakSignalVal;
                centroidCalcData[2] = (int32_t)sensor[1].diffCount;
            }
            else if(peakIndex == metaWidget->sensorCnt)
            {
                centroidCalcData[0] = sensor[peakIndex-2].diffCount;
                centroidCalcData[1] = peakSignalVal;
                centroidCalcData[2] = 0;
            }
            else
            {
                centroidCalcData[0] = sensor[peakIndex-2].diffCount;
                centroidCalcData[1] = peakSignalVal;
                centroidCalcData[2] = sensor[peakIndex].diffCount;
            }
            
            /* Calculate centroid */
            centroid = ((int32_t)centroidCalcData[2] 
                        - (int32_t)centroidCalcData[0]) * mul / 
                        ((int32_t)centroidCalcData[0]
                        + (int32_t)centroidCalcData[1]
                        + (int32_t)centroidCalcData[2]);
            centroid += (peakIndex-1) * mul;
            centroid >>= 8U;
            sliderWidget->centerPos = centroid;
			
			
        }
    }
	//fix bug:sliderStatus not setted when touched or released
	sliderWidget->sliderStatus=sliderWidget->base.status;
	
}

The code is ready, compile and burn.

3. Test

Open the serial port, touch BT0, BT1 to see the touch button is triggered; the slider position from right to left (USB TYPE-C facing left) is 0-255, you can touch or slide. The complete log is as follows

Figure 2: Touch log

At this point, the touch function has been implemented, the effect is good, the touch is sensitive and the slider position is accurate.

This post is from Automotive Electronics

Latest reply

3mm is still OK. The distance is quite far.   Details Published on 2024-2-27 09:09

6744

Posts

2

Resources
2
 
Can this capacitive sensor be placed in between glass or something like that?
This post is from Automotive Electronics

Comments

OK  Details Published on 2024-2-22 21:05
 
 

444

Posts

0

Resources
3
 
wangerxian posted on 2024-2-22 19:40 Can this capacitive sensor be separated by glass or something like that?

OK

This post is from Automotive Electronics

Comments

How thick can it be detected?  Details Published on 2024-2-23 09:12
 
 
 

6744

Posts

2

Resources
4
 

How thick can it be detected?

This post is from Automotive Electronics

Comments

I have tested it on an acrylic board with a thickness of about 3mm.  Details Published on 2024-2-26 23:29
 
 
 

444

Posts

0

Resources
5
 
wangerxian posted on 2024-2-23 09:12 How thick can it be detected?

I have tested it on an acrylic board with a thickness of about 3mm.

This post is from Automotive Electronics

Comments

3mm is still OK. The distance is quite far.  Details Published on 2024-2-27 09:09
 
 
 

6744

Posts

2

Resources
6
 
dirty posted on 2024-2-26 23:29 It has been tested on an acrylic board with a thickness of about 3mm.

3mm is still OK. The distance is quite far.

This post is from Automotive Electronics
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Featured Posts
BlueNRG-1/2 Flash operations require mutual exclusion with BLE events

When using the Flash of BlueNRG-1/2 to store application data, you may encounter problems such as no Bluetooth signal o ...

T6963C negative display problem

480893 I'm working on T6963C recently, and I don't quite understand the manual regarding negative display under text fea ...

【Development and application based on NUCLEO-F746ZG motor】14. Parameter configuration - motor parameter configuration

This post was last edited by annysky2012 on 2021-10-20 21:59 I haven't updated for a few days. The weather has turned c ...

How to generate bin format files in MDK

In the integrated development environment of Realview MDK , by default, debug files in *.axf format and executable files ...

[Flower carving hands-on] Interesting and fun music visualization series of small projects (19) - full-body fiber optic lamp

I suddenly had the urge to do a series of topics on music visualization. This topic is a bit difficult and covers a wide ...

[Flower carving hands-on] Interesting and fun music visualization series of small projects (22) - LED infinite cube

I suddenly had the urge to do a series of topics on music visualization. This topic is a bit difficult and covers a wide ...

Ebyte E103-W01 module adapter board trial

When I first received the package from Ebyte and opened it, I was confused. There was only the adapter base plate. After ...

What exactly is the problem?

After my graphics card broke last time, I bought a second-hand graphics card (1060 3G), and I also had a graphics card t ...

Are analog electronics such as triodes still used in electronic design today?

I would like to ask all the senior experts, do we still use analog electronic designs such as triodes in electronic desi ...

[Good book reading - "Switching Power Supply Simulation and Design - Based on SPICE"] - 005 BUCK Working Mode

This post was last edited by zyb329321151 on 2024-7-17 22:39 Buck converter ( BUCK ) operating mode discussion In a b ...

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list