AnsweredAssumed Answered

quadrature encoder

Question asked by waiz.abdul on Aug 10, 2017
Latest reply on Aug 11, 2017 by Clive One

hi everyone i have configured the timer for quadrature encoder which is working but as my quadrature encoder resolution is 1920 counts in 360 degree but in debugging mode it is give me 180 counts per 360 degree my code is given .in main function

e my code is given .in main function //for encoder initializing HAL_TIM_Encoder_Start(&htim5,TIM_CHANNEL_1|TIM_CHANNEL_2); 

while()

{

count=Encoder();

 

}

float Encoder(void)
{

 

Position=__HAL_TIM_GET_COUNTER(&htim5);
return(Position);
}

static void MX_TIM5_Init(void)
{

TIM_Encoder_InitTypeDef sConfig;
TIM_MasterConfigTypeDef sMasterConfig;

htim5.Instance = TIM5;
htim5.Init.Prescaler = 0;
htim5.Init.CounterMode = TIM_COUNTERMODE_UP;
htim5.Init.Period = 0xffff;
htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
sConfig.EncoderMode = TIM_ENCODERMODE_TI2;
sConfig.IC1Polarity = TIM_ICPOLARITY_RISING;
sConfig.IC1Selection = TIM_ICSELECTION_DIRECTTI;
sConfig.IC1Prescaler = TIM_ICPSC_DIV1;
sConfig.IC1Filter = 6;
sConfig.IC2Polarity = TIM_ICPOLARITY_RISING;
sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI;
sConfig.IC2Prescaler = TIM_ICPSC_DIV1;
sConfig.IC2Filter = 6;
if (HAL_TIM_Encoder_Init(&htim5, &sConfig) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}

sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}

}

Outcomes