Skip to main content
MSpir.2
Associate II
March 7, 2022
Solved

I want to change the period of a timer based on the 2 last pulses of a button constantly. How can I handle this

  • March 7, 2022
  • 1 reply
  • 871 views

..

This topic has been closed for replies.
Best answer by LCE

Like a tap for tempo detection in music?

Anyway...

Use the timer's input capture mode, which means the timer values are stored in the CCR registers when the button is pressed (or released, check the hardware, set the edge sensitivity of the capture accordingly).

If it's a button press made by a human being, you'll have enough time to use just interrupts:

button action 1st interrupt: reset timer counter to 0

button action 2nd interrupt: save timer counter value, then reset

1 reply

LCE
LCEBest answer
Principal II
March 8, 2022

Like a tap for tempo detection in music?

Anyway...

Use the timer's input capture mode, which means the timer values are stored in the CCR registers when the button is pressed (or released, check the hardware, set the edge sensitivity of the capture accordingly).

If it's a button press made by a human being, you'll have enough time to use just interrupts:

button action 1st interrupt: reset timer counter to 0

button action 2nd interrupt: save timer counter value, then reset