AnsweredAssumed Answered

Calculate the quadrature encoder speed with interrupt

Question asked by Malayjerdi.Ehsan on Apr 30, 2017

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.

 

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.

Outcomes