cancel
Showing results for 
Search instead for 
Did you mean: 

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

MSpir.2
Associate II
 
1 ACCEPTED SOLUTION

Accepted Solutions
LCE
Principal

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

View solution in original post

1 REPLY 1
LCE
Principal

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