cancel
Showing results for 
Search instead for 
Did you mean: 

Motor speed estimation using TIM2 and TIM3 on STM32F407

zd9797
Visitor

I'm trying to connect an encoder with STM32F407VGT6. The encoder sends out A,B and Z pulses out. I can read both A-B and Z pulses using TIM2 and TIM3 respectively. Timer 2 is in encoder mode and TIM3 is in input PWM mode. 

I want to know if I'm correct:

A-B encoder signals give me the rotation data 
and 
Z signal will give out pulse with variable frequency.

If I read the time period saved in CCR1/CCR2 of TIM3, can I estimate the speed of the motor? If yes, how?

 

1 REPLY 1
Bob S
Principal

The "Z" signal gives you 1 pulse per encoder revolution.  You don't need to use PWM Input mode on TIM3, you can use input capture mode (pick an edge, it doesn't matter).  Taking delta CCR1 values gives you the timer counts per encoder revolution.  If you know the timer clock freq (you should) and the ratio of encoder revolutions to motor revolutions, then it is a simple calculation to get the motor speed.

One caveat is you need to handle the case where the Z pulses are more than 65536 timer clock periods apart (i.e. the motor is "slow" compared to your timer clock).