AnsweredAssumed Answered

STM32F4 HAL for TIM PWM and Encoder Input

Question asked by metzler.matthew on Nov 9, 2015
Latest reply on Aug 22, 2017 by Massimiliano Gilli

I am trying to use the STM32F4 HAL Drivers to read a 50 Hz PWM input signal and an A quad B encoder signal on an STM32F4 Discovery board, but the TIMx_CNT register is NOT incrementing on the external triggers. 

I used the STM32CubeMX program to configure TIM2 for encoder input on Channels 1 and 2, and tried to start reading using the HAL_TIM_Encoder_Start_IT(&huart2, TIM_CHANNEL_ALL).  I have confirmed that the timer is recognizing the signal edges because I can successfully generate interrupts off of the edges.  However, I would like to use the SysTick interrupt to read the change in encoder position periodically (In this case, I start the timer using HAL_TIM_Encoder_Start();), but the TIM2_CNT register always reads 0.

I have the same issue when trying to read the pulse width of a PWM input signal using TIM9.  I can successfully generate interrupts by starting the timer using HAL_TIM_IC_Start_IT(&huart9, TIM_CHANNEL_1), but when I read the TIM9_CCR1 register, nothing is there.  Debugging has shown me that the TIM9_CNT never starts incrementing, even though it must have recognized the pulse edge in order to generate an interrupt.

I have stepped through the TIM2_Init() and TIM9_Init() functions (which were generated by the STM32CubeMX program), and as far as I can tell they line up with the instructions for PWN input capture and encoder modes listed in the STM32F4 Reference Manual.

There are no specific functions for reading PWM input or Encoder input in the HAL library, but since the counter never starts incrementing, I suspect reading the registers is not the issue.  Any guidance would be much appreciated!