The timer input channel of stm32 has a filter unit, which is located on each input path (yellow box in the middle) and the External Trigger input path (blue box in the middle ), they are used to filter out high-frequency interference from input signals.
The procedure is as follows:
CKD [1:0] In timx_cr1 allows you to set a sampling frequency benchmark for the input signal. There are three options:
1) sampling frequency reference fdts = timer input frequency fck_int
2) sampling frequency reference fdts = timer input frequency fck_int/2
3) sampling frequency reference fdts = timer input frequency fck_int/4
Then, the above frequency is used as the benchmark to sample the input signal. When n valid electric signals are continuously sampled, a valid input level is considered.
The actual sampling frequency and number of sampling times can be selected by the user program as needed; the filter parameters of the external triggering input channel are set in the ETF [] of the slave mode control register (timx_smcr; filter parameters for each input channel in capture/compare mode register 1 (timx_ccmr1) or capture/compare mode register 2 (timx_ccmr2) ic1f [], ic2f [], ic3f [], and ic4f.
For example, when fck_int = 72mhz, select fdts = fck_int/2 = 36 MHz, sampling frequency fsampling = fdts/2 = 18 MHz and n = 6, the signal above 3 MHz will be filtered out by this filter, effectively shielding interference above 3 MHz.
For example, in combination with the interruption of input capture, you can easily achieve the de-jitter function of keys without the intervention of software. This is a de-jitter function implemented by hardware, this greatly saves software overhead and program code length.
Each timer can input up to four buttons. This method can also be used for keyboard matrix scanning. In addition, the software does not need to scan frequently because it is implemented through interruption.