Skip to main content
Explorer
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

    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