cancel
Showing results for 
Search instead for 
Did you mean: 

[SOLVED] Unable to retrieve the count from TIM1 in Encoder Mode

debug
Associate III

Hi, I'm using an STM32F439ZI (on a nucleo board) and connected a Zaber stage with its encoder to it. When disconnected, I can measure the A & B signals schanging from GND to 5V. I currently cannot paste an image from the scope but I've lookerd at them before and the quadrature output looks as expected with no pullups or pull downs required. I hooked the signals up to pins PE9 & PE11 and set TIM1 up to Encoder mode: 

debug_0-1712181677426.png 

and the TIM1_init() looks like this:

 

 

static void MX_TIM1_Init(void)
{
  /* USER CODE BEGIN TIM1_Init 0 */

  /* USER CODE END TIM1_Init 0 */

  TIM_Encoder_InitTypeDef sConfig = {0};
  TIM_MasterConfigTypeDef sMasterConfig = {0};

  /* USER CODE BEGIN TIM1_Init 1 */

  /* USER CODE END TIM1_Init 1 */

  htim1.Instance = TIM1;
  htim1.Init.Prescaler = 0;
  htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim1.Init.Period = 65535;
  htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  htim1.Init.RepetitionCounter = 0;
  htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
  sConfig.EncoderMode = TIM_ENCODERMODE_TI1;
  sConfig.IC1Polarity = TIM_ICPOLARITY_RISING;
  sConfig.IC1Selection = TIM_ICSELECTION_DIRECTTI;
  sConfig.IC1Prescaler = TIM_ICPSC_DIV1;
  sConfig.IC1Filter = 10;
  sConfig.IC2Polarity = TIM_ICPOLARITY_RISING;
  sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI;
  sConfig.IC2Prescaler = TIM_ICPSC_DIV1;
  sConfig.IC2Filter = 0;
  if (HAL_TIM_Encoder_Init(&htim1, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }
  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
  {
    Error_Handler();
  }

  /* USER CODE BEGIN TIM1_Init 2 */

  /* USER CODE END TIM1_Init 2 */
}

 

yet, TIM1->CNT remains 0 as trhe encoder rotates.

Can someone here help me find where my problem might be at?

 

1 ACCEPTED SOLUTION

Accepted Solutions
debug
Associate III

This has been resolved, I was just missing to start time timer:

HAL_TIM_Encoder_Start(&htim1, TIM_CHANNEL_ALL);

View solution in original post

1 REPLY 1
debug
Associate III

This has been resolved, I was just missing to start time timer:

HAL_TIM_Encoder_Start(&htim1, TIM_CHANNEL_ALL);