From 09181b7d940e14a388bdeb4dd2360b01931d5732 Mon Sep 17 00:00:00 2001 From: Wangjialin Date: Fri, 18 May 2018 15:56:45 +0800 Subject: [PATCH] driver(touchpad): improve touchpad filter mode and update examples. --- components/driver/include/driver/touch_pad.h | 60 ++++++++-- components/driver/rtc_module.c | 107 ++++++++++++++---- .../peripherals/touch_pad_interrupt/README.md | 18 ++- .../main/tp_interrupt_main.c | 33 +++--- examples/peripherals/touch_pad_read/README.md | 47 ++++---- .../touch_pad_read/main/tp_read_main.c | 87 +++++--------- 6 files changed, 221 insertions(+), 131 deletions(-) diff --git a/components/driver/include/driver/touch_pad.h b/components/driver/include/driver/touch_pad.h index 9d14fe4e7..f18069ab3 100644 --- a/components/driver/include/driver/touch_pad.h +++ b/components/driver/include/driver/touch_pad.h @@ -103,14 +103,17 @@ typedef enum { typedef intr_handle_t touch_isr_handle_t; #define TOUCH_PAD_SLEEP_CYCLE_DEFAULT (0x1000) /*!> n) & 0x1) == ((data >> m) & 0x1) ? (data) : ((data) ^ ((0x1 <filtered_val[i] = s_touch_pad_filter->filtered_val[i] == 0 ? (val << TOUCH_PAD_SHIFT_DEFAULT) : s_touch_pad_filter->filtered_val[i]; - s_touch_pad_filter->filtered_val[i] = _touch_filter_iir((val << TOUCH_PAD_SHIFT_DEFAULT), - s_touch_pad_filter->filtered_val[i], TOUCH_PAD_FILTER_FACTOR_DEFAULT); + if ((s_touch_pad_init_bit >> i) & 0x1) { + _touch_pad_read(i, &val, mode); + s_touch_pad_filter->raw_val[i] = val; + s_filtered_temp[i] = s_filtered_temp[i] == 0 ? ((uint32_t)val << TOUCH_PAD_SHIFT_DEFAULT) : s_filtered_temp[i]; + s_filtered_temp[i] = _touch_filter_iir((val << TOUCH_PAD_SHIFT_DEFAULT), + s_filtered_temp[i], TOUCH_PAD_FILTER_FACTOR_DEFAULT); + s_touch_pad_filter->filtered_val[i] = (s_filtered_temp[i] + TOUCH_PAD_SHIFT_ROUND_DEFAULT) >> TOUCH_PAD_SHIFT_DEFAULT; + } + } + xTimerReset(s_touch_pad_filter->timer, portMAX_DELAY); + xSemaphoreGive(rtc_touch_mux); + if(s_filter_cb != NULL) { + //return the raw data and filtered data. + s_filter_cb(s_touch_pad_filter->raw_val, s_touch_pad_filter->filtered_val); } } @@ -526,6 +552,8 @@ esp_err_t touch_pad_set_meas_time(uint16_t sleep_cycle, uint16_t meas_cycle) SENS.sar_touch_ctrl2.touch_sleep_cycles = sleep_cycle; //touch sensor measure time= meas_cycle / 8Mhz SENS.sar_touch_ctrl1.touch_meas_delay = meas_cycle; + //the waiting cycles (in 8MHz) between TOUCH_START and TOUCH_XPD + SENS.sar_touch_ctrl1.touch_xpd_wait = TOUCH_PAD_MEASURE_WAIT_DEFAULT; portEXIT_CRITICAL(&rtc_spinlock); xSemaphoreGive(rtc_touch_mux); return ESP_OK; @@ -792,10 +820,19 @@ esp_err_t touch_pad_config(touch_pad_t touch_num, uint16_t threshold) { RTC_MODULE_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_FAIL); RTC_MODULE_CHECK(touch_num < TOUCH_PAD_MAX, "Touch_Pad Num Err", ESP_ERR_INVALID_ARG); + s_touch_pad_init_bit |= (1 << touch_num); touch_pad_set_thresh(touch_num, threshold); touch_pad_io_init(touch_num); - touch_pad_set_cnt_mode(touch_num, TOUCH_PAD_SLOPE_7, TOUCH_PAD_TIE_OPT_HIGH); - touch_pad_set_group_mask((1 << touch_num), (1 << touch_num), (1 << touch_num)); + touch_pad_set_cnt_mode(touch_num, TOUCH_PAD_SLOPE_7, TOUCH_PAD_TIE_OPT_LOW); + touch_fsm_mode_t mode; + touch_pad_get_fsm_mode(&mode); + if (TOUCH_FSM_MODE_SW == mode) { + touch_pad_clear_group_mask((1 << touch_num), (1 << touch_num), (1 << touch_num)); + } else if (TOUCH_FSM_MODE_TIMER == mode){ + touch_pad_set_group_mask((1 << touch_num), (1 << touch_num), (1 << touch_num)); + } else { + return ESP_FAIL; + } return ESP_OK; } @@ -822,6 +859,7 @@ esp_err_t touch_pad_deinit() if (rtc_touch_mux == NULL) { return ESP_FAIL; } + s_touch_pad_init_bit = 0x0000; touch_pad_filter_delete(); touch_pad_set_fsm_mode(TOUCH_FSM_MODE_SW); touch_pad_clear_status(); @@ -831,19 +869,52 @@ esp_err_t touch_pad_deinit() return ESP_OK; } +static esp_err_t _touch_pad_read(touch_pad_t touch_num, uint16_t *touch_value, touch_fsm_mode_t mode) +{ + esp_err_t res = ESP_OK; + touch_pad_t tp_wrap = touch_pad_num_wrap(touch_num); + if (TOUCH_FSM_MODE_SW == mode) { + touch_pad_set_group_mask((1 << touch_num), (1 << touch_num), (1 << touch_num)); + touch_pad_sw_start(); + while (SENS.sar_touch_ctrl2.touch_meas_done == 0) {}; + *touch_value = (tp_wrap & 0x1) ? \ + SENS.touch_meas[tp_wrap / 2].l_val: \ + SENS.touch_meas[tp_wrap / 2].h_val; + + touch_pad_clear_group_mask((1 << touch_num), (1 << touch_num), (1 << touch_num)); + } else if (TOUCH_FSM_MODE_TIMER == mode) { + while (SENS.sar_touch_ctrl2.touch_meas_done == 0) {}; + *touch_value = (tp_wrap & 0x1) ? \ + SENS.touch_meas[tp_wrap / 2].l_val: \ + SENS.touch_meas[tp_wrap / 2].h_val; + } else { + res = ESP_FAIL; + } + return res; +} + esp_err_t touch_pad_read(touch_pad_t touch_num, uint16_t *touch_value) { RTC_MODULE_CHECK(touch_num < TOUCH_PAD_MAX, "Touch_Pad Num Err", ESP_ERR_INVALID_ARG); RTC_MODULE_CHECK(touch_value != NULL, "touch_value", ESP_ERR_INVALID_ARG); RTC_MODULE_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_FAIL); - touch_pad_t tp_wrap = touch_pad_num_wrap(touch_num); + esp_err_t res = ESP_OK; + touch_fsm_mode_t mode; + touch_pad_get_fsm_mode(&mode); xSemaphoreTake(rtc_touch_mux, portMAX_DELAY); - while (SENS.sar_touch_ctrl2.touch_meas_done == 0) {}; - *touch_value = (tp_wrap & 0x1) ? \ - SENS.touch_meas[tp_wrap / 2].l_val: \ - SENS.touch_meas[tp_wrap / 2].h_val; + res = _touch_pad_read(touch_num, touch_value, mode); xSemaphoreGive(rtc_touch_mux); + return res; +} + +IRAM_ATTR esp_err_t touch_pad_read_raw_data(touch_pad_t touch_num, uint16_t *touch_value) +{ + RTC_MODULE_CHECK(rtc_touch_mux != NULL, "Touch pad not initialized", ESP_FAIL); + RTC_MODULE_CHECK(touch_num < TOUCH_PAD_MAX, "Touch_Pad Num Err", ESP_ERR_INVALID_ARG); + RTC_MODULE_CHECK(touch_value != NULL, "touch_value", ESP_ERR_INVALID_ARG); + RTC_MODULE_CHECK(s_touch_pad_filter != NULL, "Touch pad filter not initialized", ESP_ERR_INVALID_STATE); + *touch_value = s_touch_pad_filter->raw_val[touch_num]; return ESP_OK; } @@ -853,7 +924,7 @@ IRAM_ATTR esp_err_t touch_pad_read_filtered(touch_pad_t touch_num, uint16_t *tou RTC_MODULE_CHECK(touch_num < TOUCH_PAD_MAX, "Touch_Pad Num Err", ESP_ERR_INVALID_ARG); RTC_MODULE_CHECK(touch_value != NULL, "touch_value", ESP_ERR_INVALID_ARG); RTC_MODULE_CHECK(s_touch_pad_filter != NULL, "Touch pad filter not initialized", ESP_ERR_INVALID_STATE); - *touch_value = (s_touch_pad_filter->filtered_val[touch_num] >> TOUCH_PAD_SHIFT_DEFAULT); + *touch_value = (s_touch_pad_filter->filtered_val[touch_num]); return ESP_OK; } @@ -908,13 +979,12 @@ esp_err_t touch_pad_filter_start(uint32_t filter_period_ms) } } if (s_touch_pad_filter->timer == NULL) { - s_touch_pad_filter->timer = xTimerCreate("filter_tmr", filter_period_ms / portTICK_PERIOD_MS, pdTRUE, + s_touch_pad_filter->timer = xTimerCreate("filter_tmr", filter_period_ms / portTICK_PERIOD_MS, pdFALSE, NULL, touch_pad_filter_cb); if (s_touch_pad_filter->timer == NULL) { ret = ESP_ERR_NO_MEM; } xTimerStart(s_touch_pad_filter->timer, portMAX_DELAY); - s_touch_pad_filter->enable = true; } else { xTimerChangePeriod(s_touch_pad_filter->timer, filter_period_ms / portTICK_PERIOD_MS, portMAX_DELAY); s_touch_pad_filter->period = filter_period_ms; @@ -932,7 +1002,6 @@ esp_err_t touch_pad_filter_stop() xSemaphoreTake(rtc_touch_mux, portMAX_DELAY); if (s_touch_pad_filter != NULL) { xTimerStop(s_touch_pad_filter->timer, portMAX_DELAY); - s_touch_pad_filter->enable = false; } else { ESP_LOGE(RTC_MODULE_TAG, "Touch pad filter deleted"); ret = ESP_ERR_INVALID_STATE; diff --git a/examples/peripherals/touch_pad_interrupt/README.md b/examples/peripherals/touch_pad_interrupt/README.md index fd4c2aa4b..44a5efb51 100644 --- a/examples/peripherals/touch_pad_interrupt/README.md +++ b/examples/peripherals/touch_pad_interrupt/README.md @@ -1,12 +1,16 @@ # Touch Pad Interrupt Example +Demonstrates how to set up ESP32's capacitive touch pad peripheral to trigger interrupt when a pad is touched. It also shows how to detect the touch event by the software for sensor designs when greater touch detection sensitivity is required. -Demonstrates how to set up ESP32's capacitive touch pad peripheral to trigger interrupt when a pad is touched. +ESP32 supports touch detection by configuring hardware registers. The hardware periodically detects the pulse counts. If the number of pulse counts exceeds the set threshold, a hardware interrupt will be generated to notify the application layer that a certain touch sensor channel may be triggered. -Application has been developed and tested using [ESP32 Demo Board V2](https://dl.espressif.com/dl/schematics/ESP32-Demo-Board-V2_sch.pdf) that has ten capacitive sensor pads T0 to T9 exposed. +For the sensor designs when the pad is covered a glass or plastic, the difference caused by a 'touch' action could be very small. In such a case we are using software pooling and algorithms to reduce noise to still be able to detect small changes of the pulse counts. In certain cases we may need to use additional routines to adjust the threshold level dynamically as it may change depending on environment conditions. -![alt text](https://dl.espressif.com/dl/schematics/pictures/esp32-demo-board-v2.jpg "ESP32 Demo Board V2") +Comparison of the two modes: -The following output is shown when a pad is touched: +- The hardware interrupt mode occupies less CPU resources, but only a single threshold can be set and cannot support various software algorithms. +- The continuous pooling is flexible and supports various software algorithms. However, it also costs CPU overhead + +The application is cycling between the interrupt mode and the pooling mode with a filter, to compare performance of the touch sensor system in both scenarios: ``` I (6303) Touch pad: Waiting for any pad being touched... @@ -23,8 +27,10 @@ I (17903) Touch pad: Waiting for any pad being touched... I (22903) Touch pad: Waiting for any pad being touched... ``` -Note: Sensing threshold is set up automatically at start up by performing simple calibration. Application is reading current value for each pad and assuming half of this value as the sensing threshold. Do not touch pads on application start up, otherwise sensing may not work correctly. +Note: Sensing threshold is set up automatically at start up by performing simple calibration. Application is reading current value for each pad and assuming two thirds of this value as the sensing threshold. Do not touch pads on application start up, otherwise sensing may not work correctly. -For a simpler example how to configure and read capacitive touch pads, please refer to [touch_pad_read](../touch_pad_read). +For a simpler example how to configure and read capacitive touch pads, please refer to [touch_pad_read](../touch_pad_read). + +Design and implementation of the touch sensor system is a complex process. The [Touch Sensor Application Note](https://github.com/espressif/esp-iot-solution/blob/master/documents/touch_pad_solution/touch_sensor_design_en.md) contains several ESP32 specific notes and comments to optimize the design and get the best out of the application with sensors controlled with the ESP32. See the README.md file in the upper level 'examples' directory for more information about examples. diff --git a/examples/peripherals/touch_pad_interrupt/main/tp_interrupt_main.c b/examples/peripherals/touch_pad_interrupt/main/tp_interrupt_main.c index a1c58762a..dd0f8c26d 100644 --- a/examples/peripherals/touch_pad_interrupt/main/tp_interrupt_main.c +++ b/examples/peripherals/touch_pad_interrupt/main/tp_interrupt_main.c @@ -17,12 +17,12 @@ static const char* TAG = "Touch pad"; #define TOUCH_THRESH_NO_USE (0) -#define TOUCH_THRESH_PERCENT (99) +#define TOUCH_THRESH_PERCENT (80) +#define TOUCHPAD_FILTER_TOUCH_PERIOD (10) static bool s_pad_activated[TOUCH_PAD_MAX]; static uint32_t s_pad_init_val[TOUCH_PAD_MAX]; - /* Read values sensed at all available touch pads. Use 2 / 3 of read value as the threshold @@ -42,7 +42,7 @@ static void tp_example_set_thresholds(void) //read filtered value touch_pad_read_filtered(i, &touch_value); s_pad_init_val[i] = touch_value; - ESP_LOGI(TAG, "test init touch val: %d\n", touch_value); + ESP_LOGI(TAG, "test init touch val: %d", touch_value); //set interrupt threshold. ESP_ERROR_CHECK(touch_pad_set_thresh(i, touch_value * 2 / 3)); @@ -58,7 +58,7 @@ static void tp_example_set_thresholds(void) In interrupt mode, the table is updated in touch ISR. In filter mode, we will compare the current filtered value with the initial one. - If the current filtered value is less than 99% of the initial value, we can + If the current filtered value is less than 80% of the initial value, we can regard it as a 'touched' event. When calling touch_pad_init, a timer will be started to run the filter. This mode is designed for the situation that the pad is covered @@ -90,12 +90,13 @@ static void tp_example_read_task(void *pvParameter) } else { //filter mode, disable touch interrupt touch_pad_intr_disable(); + touch_pad_clear_status(); for (int i = 0; i < TOUCH_PAD_MAX; i++) { uint16_t value = 0; touch_pad_read_filtered(i, &value); if (value < s_pad_init_val[i] * TOUCH_THRESH_PERCENT / 100) { ESP_LOGI(TAG, "T%d activated!", i); - ESP_LOGI(TAG, "value: %d; init val: %d\n", value, s_pad_init_val[i]); + ESP_LOGI(TAG, "value: %d; init val: %d", value, s_pad_init_val[i]); vTaskDelay(200 / portTICK_PERIOD_MS); // Reset the counter to stop changing mode. change_mode = 1; @@ -115,7 +116,7 @@ static void tp_example_read_task(void *pvParameter) // We can compare the two different mode. if (change_mode++ % 2000 == 0) { filter_mode = !filter_mode; - ESP_LOGI(TAG, "Change mode...%s\n", filter_mode == 0? "interrupt mode": "filter mode"); + ESP_LOGW(TAG, "Change mode...%s", filter_mode == 0? "interrupt mode": "filter mode"); } } } @@ -152,26 +153,20 @@ void app_main() // Initialize touch pad peripheral, it will start a timer to run a filter ESP_LOGI(TAG, "Initializing touch pad"); touch_pad_init(); - + // If use interrupt trigger mode, should set touch sensor FSM mode at 'TOUCH_FSM_MODE_TIMER'. + touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); + // Set reference voltage for charging/discharging + // For most usage scenarios, we recommend using the following combination: + // the high reference valtage will be 2.7V - 1V = 1.7V, The low reference voltage will be 0.5V. + touch_pad_set_voltage(TOUCH_HVOLT_2V7, TOUCH_LVOLT_0V5, TOUCH_HVOLT_ATTEN_1V); // Initialize and start a software filter to detect slight change of capacitance. - touch_pad_filter_start(10); - // Set measuring time and sleep time - // In this case, measurement will sustain 0xffff / 8Mhz = 8.19ms - // Meanwhile, sleep time between two measurement will be 0x1000 / 150Khz = 27.3 ms - touch_pad_set_meas_time(0x1000, 0xffff); - - //set reference voltage for charging/discharging - // In this case, the high reference valtage will be 2.4V - 1.5V = 0.9V - // The low reference voltage will be 0.8V, so that the procedure of charging - // and discharging would be very fast. - touch_pad_set_voltage(TOUCH_HVOLT_2V4, TOUCH_LVOLT_0V8, TOUCH_HVOLT_ATTEN_1V5); + touch_pad_filter_start(TOUCHPAD_FILTER_TOUCH_PERIOD); // Init touch pad IO tp_example_touch_pad_init(); // Set thresh hold tp_example_set_thresholds(); // Register touch interrupt ISR touch_pad_isr_register(tp_example_rtc_intr, NULL); - // Start a task to show what pads have been touched xTaskCreate(&tp_example_read_task, "touch_pad_read_task", 2048, NULL, 5, NULL); } diff --git a/examples/peripherals/touch_pad_read/README.md b/examples/peripherals/touch_pad_read/README.md index a6525f3b6..13c5b39f2 100644 --- a/examples/peripherals/touch_pad_read/README.md +++ b/examples/peripherals/touch_pad_read/README.md @@ -1,24 +1,23 @@ -# Touch Pad Read Example - -Read and display raw values from capacitive touch pad sensors. - -Once configured, ESP32 is continuously measuring capacitance of touch pad sensors. Measurement is reflected as numeric value inversely related to sensor's capacitance. The capacitance is bigger when sensor is touched with a finger and the measured value smaller. In opposite situation, when finger is released, capacitance is smaller and the measured value bigger. - -To detect when a sensor is touched and when not, each particular design should be calibrated by obtaining both measurements for each individual sensor. Then a threshold between both values should be established. Using specific threshold, API is then able to distinguish whether specific sensor is touched or released. - -ESP32 supports reading up to ten capacitive touch pad sensors T0 - T9, connected to specific GPIO pins. For information on available pins please refer to [Technical Reference Manual](https://espressif.com/sites/default/files/documentation/esp32_technical_reference_manual_en.pdf). Application initializes all ten sensor pads. Then in a loop reads sensors T0 - T9 and displays obtained values (after a colon) on a serial terminal: - -``` -T0: 486 T1: 1 T2: 559 T3: 567 T4: 871 T5: 522 T6:1174 T7:1531 T8:1508 T9:1640 -T0: 485 T1: 1 T2: 559 T3: 568 T4: 871 T5: 521 T6:1176 T7:1536 T8:1509 T9:1635 -T0: 485 T1: 1 T2: 559 T3: 568 T4: 871 T5: 521 T6:1172 T7:1536 T8:1507 T9:1640 -T0: 11 T1: 1 T2: 558 T3: 568 T4: 871 T5: 522 T6:1172 T7:1535 T8:1507 T9:1638 -``` - -Above log is prepared using [ESP32 Demo Board V2](https://dl.espressif.com/dl/schematics/ESP32-Demo-Board-V2_sch.pdf) that has all ten pad sensors exposed. Values will be different depending on layout of pads on particular board. - -![alt text](https://dl.espressif.com/dl/schematics/pictures/esp32-demo-board-v2.jpg "ESP32 Demo Board V2") - -There is another similar example that demonstrates how to perform simple calibration and trigger an interrupt when a pat is touched - see [touch_pad_interrupt](../touch_pad_interrupt). - -See the README.md file in the upper level 'examples' directory for more information about examples. +# Touch Pad Read Example + +Read and display raw values or IIR filtered values from capacitive touch pad sensors. + +Once configured, ESP32 is continuously measuring capacitance of touch pad sensors. Measurement is reflected as numeric value inversely related to sensor's capacitance. The capacitance is bigger when sensor is touched with a finger and the measured value smaller. In opposite situation, when finger is released, capacitance is smaller and the measured value bigger. + +To detect when a sensor is touched and when not, each particular design should be calibrated by obtaining both measurements for each individual sensor. Then a threshold between both values should be established. Using specific threshold, API is then able to distinguish whether specific sensor is touched or released. + +ESP32 supports reading up to ten capacitive touch pad sensors T0 - T9, connected to specific GPIO pins. For information on available pins please refer to [Technical Reference Manual](https://espressif.com/sites/default/files/documentation/esp32_technical_reference_manual_en.pdf). Application initializes all ten sensor pads. Then in a loop reads sensors T0 - T9 and displays obtained values (after a colon) on a serial terminal: + +``` +Touch Sensor filter mode read, the output format is: +Touchpad num:[raw data, filtered data] + +T0:[1072,1071] T1:[ 475, 475] T2:[1004,1003] T3:[1232,1231] T4:[1675,1676] T5:[1146,1146] T6:[1607,1607] T7:[1118,1118] T8:[1695,1695] T9:[1223,1222] +T0:[1072,1071] T1:[ 475, 475] T2:[1003,1003] T3:[1231,1231] T4:[1676,1676] T5:[1146,1146] T6:[1607,1607] T7:[1118,1118] T8:[1694,1694] T9:[1222,1221] +T0:[1071,1071] T1:[ 475, 475] T2:[1004,1004] T3:[1231,1231] T4:[1678,1677] T5:[1147,1146] T6:[1607,1607] T7:[1118,1118] T8:[1694,1694] T9:[1222,1221] +``` +For hardware and firmware design guidelines on ESP32 touch sensor system, please refer to [Touch Sensor Application Note](https://github.com/espressif/esp-iot-solution/blob/master/documents/touch_pad_solution/touch_sensor_design_en.md), where you may find comprehensive information on how to design and implement touch sensing applications, such as linear slider, wheel slider, matrix buttons and spring buttons. + +There is another similar example that demonstrates how to perform simple calibration and trigger an interrupt when a pat is touched - see [touch_pad_interrupt](../touch_pad_interrupt). + +See the README.md file in the upper level 'examples' directory for more information about examples. diff --git a/examples/peripherals/touch_pad_read/main/tp_read_main.c b/examples/peripherals/touch_pad_read/main/tp_read_main.c index def1dacf0..b7f9e0ea7 100644 --- a/examples/peripherals/touch_pad_read/main/tp_read_main.c +++ b/examples/peripherals/touch_pad_read/main/tp_read_main.c @@ -11,69 +11,37 @@ #include "freertos/task.h" #include "driver/touch_pad.h" -#define TOUCH_TEST_LOOP_NUM (10) #define TOUCH_PAD_NO_CHANGE (-1) #define TOUCH_THRESH_NO_USE (0) +#define TOUCH_FILTER_MODE_EN (1) +#define TOUCHPAD_FILTER_TOUCH_PERIOD (10) /* Read values sensed at all available touch pads. Print out values in a loop on a serial monitor. */ static void tp_example_read_task(void *pvParameter) { + uint16_t touch_value; + uint16_t touch_filter_value; +#if TOUCH_FILTER_MODE_EN + printf("Touch Sensor filter mode read, the output format is: \nTouchpad num:[raw data, filtered data]\n\n"); +#else + printf("Touch Sensor normal mode read, the output format is: \nTouchpad num:[raw data]\n\n"); +#endif while (1) { - uint16_t touch_value; - //set reference voltage for charging/discharging - // In this case, the high reference valtage will be 2.7V - 0V = 2.7V - // The low reference voltage will be 0.5 - // So the charing/discharging time would be longer, so the counter value would be smaller. - touch_pad_set_voltage(TOUCH_HVOLT_2V7, TOUCH_LVOLT_0V5, TOUCH_HVOLT_ATTEN_0V); - - vTaskDelay(100 / portTICK_PERIOD_MS); - printf("Case[1], set default measure time\n"); - for (int j = 0; j < TOUCH_TEST_LOOP_NUM; j++) { - for (int i = 0; i < TOUCH_PAD_MAX; i++) { - ESP_ERROR_CHECK(touch_pad_read(i, &touch_value)); - printf("T%d:%5d ", i, touch_value); - } - printf("\n"); - vTaskDelay(500 / portTICK_PERIOD_MS); - } - - printf("Case[2], set max measure time\n"); - //set reference voltage for charging/discharging - // In this case, the high reference valtage will be 2.4V - 1.5V = 0.9V - // The low reference voltage will be 0.8 - // So the charing/discharging time would be shorter, so the counter value would be larger. - touch_pad_set_voltage(TOUCH_HVOLT_2V4, TOUCH_LVOLT_0V8, TOUCH_HVOLT_ATTEN_1V5); - vTaskDelay(100 / portTICK_PERIOD_MS); - for (int j = 0; j < TOUCH_TEST_LOOP_NUM; j++) { - for (int i = 0; i < TOUCH_PAD_MAX; i++) { - ESP_ERROR_CHECK(touch_pad_read(i, &touch_value)); - printf("T%d:%5d ", i, touch_value); - } - printf("\n"); - vTaskDelay(500 / portTICK_PERIOD_MS); - } - - - touch_pad_set_voltage(TOUCH_HVOLT_2V7, TOUCH_LVOLT_0V5, TOUCH_HVOLT_ATTEN_0V); - vTaskDelay(100/portTICK_PERIOD_MS); - - printf("Case[3], set differen slope for each channel\n"); - for (int i = 0;i