cancel
Showing results for 
Search instead for 
Did you mean: 

Encoder mode

aba12
Visitor

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:

  1. The correct relationship between timer frequency and encoder output.
  2. How to properly choose the timer period for the encoder.

Below is my current configuration:

aba12_0-1742324330403.pngaba12_1-1742324352790.png

 

Thank you in advance for your help!

2 REPLIES 2
KnarfB
Principal III

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 

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 ?

aba12_0-1742335299908.pngaba12_1-1742335322639.pngaba12_2-1742335343926.png