2025-03-18 12:00 PM - last edited on 2025-03-18 12:43 PM by mƎALLEm
Hello everyone,
I am currently working on encoder mode with an STM32C031. I am using a DC motor with an incremental encoder and a gear reducer. My goal is to measure both the velocity and position of the motor.
I have configured Timer1 with a frequency of 24 MHz, using channels 1 and 2 in quadrature mode to read the encoder signals. However, I am struggling to understand the relation between the timer frequency configuration and the values provided by the encoder.
Additionally, I am uncertain about how to correctly set the timer period for the encoder. Currently, I have set it equal to the timer period, but I am not sure if this is the correct approach.
I would appreciate any insights or explanations regarding:
Below is my current configuration:
Thank you in advance for your help!
2025-03-18 12:38 PM - edited 2025-03-18 12:39 PM
You set the timer to quadrature encoder mode, okay. Then, there is no fixed frequency. The timer will count the encoder steps, up and down, depending on the direction. So, you may set the timer period to the number of encoder steps per rotation. Then, the timer counter register gives you the relative encoder position at any time.
If you want to calculate derived values, like rotation speed, you need a second timer driven by the internal clock and maybe with prescaling. You can use an interrupt handler for measuring the encoder position delta and calculating the speed from it.
hth
KnarfB
2025-03-18 3:16 PM
thank you for your help,
but i use this function to calculate the velocity and position and i think there is no need here to use another timer, what do you think about that ?