AnsweredAssumed Answered

Motor Encoder read - please help

Question asked by hynek.ondrej on Apr 12, 2013
Latest reply on Apr 12, 2013 by Clive One
Hello, I have my own developed board for motor driving. MCU is STM32F407VET6. The board has inputs from 4 motor encoders. I need to know an actual speed of each motor. ENC1_A, ENC2_A, ENC3_A, ENC4_A pins are connected to TIM8(CH1 - 4). Every 100ms i want to check motors speed. So i have TIM7 initialized for timing but i dont know how to read TIM8 CH1-CH4 Counters. 

In TIM8 init:

        TIM_ICInitStructure.TIM_Channel = TIM_Channel_4;
     TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
     TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
     TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
     TIM_ICInitStructure.TIM_ICFilter = 0xF;

     TIM_ICInit(TIM8, &TIM_ICInitStructure);
     
     TIM_Cmd(TIM8, ENABLE);

In TIM7 interrupt routine:
                if (TIM_GetITStatus(TIM7, TIM_IT_Update) != RESET){
              TIM_ClearITPendingBit(TIM7, TIM_IT_Update);
          
              M1_CurrentSpeed = TIM_GetCapture4(TIM8);
          
              TIM8->CCR4 = 0;
              TIM8->CNT = 0;
              LED_Toggle(LED_COMM);
     }

But if i turn manually with motor shaft and encoder will give ONE pulse, TIM_GetCapture4(TIM8) gives values like 500, 12221, 5300, 42000 etc.
It seems that TIM dont react on Rising edge on input ?

Please help.

Outcomes