Shanghai Hangxin ACM32F070 Development Board + Touch Function Evaluation Board Evaluation - Part 2 Capacitive Touch Slider Function Development
[Copy link]
This post was last edited by oxygen_sh on 2022-10-23 22:21
This evaluation experiment developed a simple touch slider algorithm based on the SDK example.
1. Hardware Preparation
I have a capacitive touch panel that I have used before. It has 5 buttons and 1 slider. The slider consists of 3 electrodes.
This slider can be used to develop slider functions based on ACM32F070.
Through flying wire welding, the three electrodes of the slider on the old board are connected to the PB3-PB5 three pins of the ACM32F070 development board. These three pins are not used on the ACM32F070 development board, so they can be used here to realize the slider function.
The capacitive touch acquisition process signal was captured by an oscilloscope:
Single channel single scan complete signal:
The signal after local amplification:
2. Slide touch software development
The SDK provides several examples that include touch functions. I chose the LCD_TK sample to learn. This example provides both touch and LCD display functions, which is convenient for effect display. This example only provides the touch button function.
- Touch channel configuration
In TKey.h, enable the three channels used by the slider.
#define TKEY_CHANNEL_12_ENABLE
#define TKEY_CHANNEL_13_ENABLE
#define TKEY_CHANNEL_14_ENABLE
The electrode area used by the slider is large, so the sensitivity parameter needs to be lowered. According to the debugging situation, it is set to 20 here.
#define TKEY_12_SENSITIVITY 20
#define TKEY_13_SENSITIVITY 20
#define TKEY_14_SENSITIVITY 20
The Touchkey will be initially calibrated during the initialization process.
The current algorithm is relatively simple and does not take into account baseline calibration. Therefore, it is necessary to stop the dynamic calibration function in the routine. The specific method is to comment out TKEY_Calibrate_Process() in the implementation in the App_Test() function.
The routine uses a timer to periodically scan touch keys.
- Slider detection algorithm implementation
uint16_t HAL_TKEY_Slider_Process()
{
int16_t middle_delta, left_delta, right_delta, middle_index,position;
uint32_t pos1, pos;
middle_delta = slider_delta[0];
left_delta = slider_delta[2];
right_delta = slider_delta[1];
middle_index = 0;
position = 1024;
if(middle_delta < 10){
return 0xFF;
}
if(slider_delta[1] > middle_delta){
middle_delta = slider_delta[1];
left_delta = slider_delta[0];
right_delta = slider_delta[2];
middle_index = 1;
position = 2048;
}
if(slider_delta[2] > middle_delta){
middle_delta = slider_delta[2];
left_delta = slider_delta[1];
right_delta = slider_delta[0];
middle_index = 2;
position = 3192;
}
if(left_delta > right_delta){
pos1 = (uint16_t)((middle_delta - right_delta) + (left_delta - right_delta));
pos = (left_delta - right_delta);
pos = pos << 10;
pos = pos /(pos1);
if(middle_index == 0){
position = 4096;
}
position -= pos;
}else{
pos1 = (uint16_t)((middle_delta - left_delta) + (right_delta - left_delta));
pos = (right_delta - left_delta);
pos = pos << 10;
pos = pos /(pos1);
position +=pos;
}
return position;
}
The sliding window method is used to filter the detection results.
filtered_slider_cnt = sliding_wondow_filter(raw_slider_cnt);
3. Demo video demonstration and optimization direction
The slider is slow to respond, and the detection algorithm needs to be further optimized. In addition, the slider uses three capacitor electrodes with a large area, so the hardware sampling capacitor needs to be replaced with a larger capacitor from the current 10nF, such as 22nF, to achieve better detection resolution.
2-1
|