Skip to main content
dungeonlords789
Associate III
February 8, 2021
Solved

When I use both chanels, what args I need in HAL_TIM_Encoder_Start?

  • February 8, 2021
  • 1 reply
  • 1521 views

I use CubeMX to configure my timer 2 to use Encoder Mode: "Encoder Mode TI1 and TI2". In my code should I use

HAL_TIM_Encoder_Start(&htim2, TIM_CHANNEL_1)

or

HAL_TIM_Encoder_Start(&htim2, TIM_CHANNEL_2)

or

HAL_TIM_Encoder_Start(&htim2, TIM_CHANNEL_ALL)

or something else?

P.S. What means TI1?

This topic has been closed for replies.
Best answer by Amel NASRI

Hi @dungeonlords789​ ,

Looking to the description of HAL_TIM_Encoder_Start in the driver stm32f4xx_hal_tim.c (for example):

/**

 * @brief Starts the TIM Encoder Interface.

 * @param htim TIM Encoder Interface handle

 * @param Channel TIM Channels to be enabled

 *     This parameter can be one of the following values:

 *      @arg TIM_CHANNEL_1: TIM Channel 1 selected

 *      @arg TIM_CHANNEL_2: TIM Channel 2 selected

 *      @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected

 * @retval HAL status

 */

So the last option is what you need to use.

-Amel

1 reply

Amel NASRI
Technical Moderator
February 10, 2021

Hi @dungeonlords789​ ,

Looking to the description of HAL_TIM_Encoder_Start in the driver stm32f4xx_hal_tim.c (for example):

/**

 * @brief Starts the TIM Encoder Interface.

 * @param htim TIM Encoder Interface handle

 * @param Channel TIM Channels to be enabled

 *     This parameter can be one of the following values:

 *      @arg TIM_CHANNEL_1: TIM Channel 1 selected

 *      @arg TIM_CHANNEL_2: TIM Channel 2 selected

 *      @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected

 * @retval HAL status

 */

So the last option is what you need to use.

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.