cancel
Showing results for 
Search instead for 
Did you mean: 

Calculate the quadrature encoder speed with interrupt

Ehsan Malayjerdi
Associate
Posted on April 30, 2017 at 19:03

Hi everyone

I work on the mobile robot with stm32f429 discovery. I read the quad encoder with TIM3(PA6,PA7).

everything is ok

now I want to calculate the speed of dc motor via the encoder.

I enable the TIM10 for the interrupt in 1khz.

my dc motor PWM in 1khz.

0690X00000606uYQAQ.png

my interrupt code as follow

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)

        {

            // return speed in mm per second

  oldEncoder = Encoder;

  Encoder =__HAL_TIM_GetCounter(&htim3);

   Count = Encoder - oldEncoder;

           a=Count*1000;

          b=e*60;

           x=j/40;

           y=encCounter1/68;

            

        }

but the Count variable is fixed as 2 or 3 in different PWM speed.

How do I do for calculate the speed correctly?

please answer my question.

thanks.

0 REPLIES 0