on my STM32F103, I use a timer to read rotary encoder

  • Prescaler = 71
  • Period = 20
  • Clock = 72MHz
  • Rotary encoder: 2000 ppr

Given the formula:

  • TIMUpdateFrequency(Hz)=Clock/((PSC−1)∗(Period−1))

I obtain an update every 54'135Hz Each update, I read the encoder value and compare to the previous one. Very stupid question: how can I get à RPM figure with that?


Your sample frequency is let's say 50 Hz. Calculatel the difference of the encoder values. Than divide by 2000 (ppr). This means you get this many of revolutions in 50 Hz (or 1/50 = 0.02s).

As calculation

 RotationSpeed = (EncoderValue_Last - EncoderValue_Previous) / 2000 ppr) * Freq [Hz]

Assuming the previous encoder value was 30,000, the current 80,000, ppr is 2,000 and using 50 Hz (sample encoder data each 0.02 s):

 = (80000 - 30000) / 2000 * 50 = 1,250 RPM

In this article ppr and cpr are explained in more detail.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.