espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.27k stars 7.2k forks source link

[New capacitive sensor] Enable other denoise options by providing the raw signal (TOUCH_PAD_DENOISE_BIT0) (IDFGH-6270) #7939

Open CarlosGS opened 2 years ago

CarlosGS commented 2 years ago

The new capacitive sensor module in ESP32-S2 has an integrated denoise option, which uses an internal pad to measure noise simultaneously with any other pad, and then subtract it to reduce overall noise.

However, the current implementation seems to only allow the removal of some of the bits (https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/api-reference/peripherals/touch_pad.html#_CPPv425touch_pad_denoise_grade_t). For example, setting TOUCH_PAD_DENOISE_BIT4 takes the original pad measurement and substacts (noise & 0xF). Which can be limiting in applications that need more accuracy than touch sensors, such as other metrology tasks.

I needed to have the raw signals together with the noise measurements. Currently doing this:

noise = touch_pad_denoise_read_data();
denoised_raw = touch_pad_read_raw_data();
real_raw = denoised_raw + (noise & 0xF); // Undo the internal noise removal operation

Would it be possible to provide TOUCH_PAD_DENOISE_BIT0? This way we could also have the real raw signals without having to "undo" any operations.

Thanks for the great work! :smiley:

CarlosGS commented 2 years ago

I found a bit unintuitive that touch_pad_read_raw_data() reads the already "denoised" data. But in order to avoid a breaking change, my request is: can you provide TOUCH_PAD_DENOISE_BIT0?

In advanced capacitive sensing applications, having a better noise removal procedure improves SNR dramatically. And the only way to do this is to have a separate raw signal without any prior filtering. I'm available to test. Thanks!