Skip to main content
Visitor II
July 31, 2024
Solved

STM32 Timer Encoder mode delayed by 400ms

  • July 31, 2024
  • 1 reply
  • 908 views

I am using two quadrature encoders through the STM32F411CEU6 timer encoder mode. Here is the graph for one of their CNT values:

Jfkd5b2C

As you can see, it takes about 400ms to update the value, but when it does, it seems accurate. How can I make it so that it doesn't do this? Timer settings (the same for both):

MgN1v9pB

The PLL is at 98 MHz and it says the peripheral clocks are at 48 MHz, although I'm not sure if that's the right number to read. I've tried changing:

- Encoder Mode
- Input Filter
- Some values of the Trigger Output Parameters, although not all of them

 

I am positive that the encoders are hooked up correctly and I took a look with the oscilloscope and the signal looks good. I'm simply plotting htim3.Instance->CNT to make this chart.

    This topic has been closed for replies.
    Best answer by Nv7

    Wow, I was using if (HAL_GetTick() % 50 == 0) to try to print every 50ms, but it turns out that doesn't work? I'm not sure why because I know the loop is running at much higher than 1000Hz but now that I switched to properly printing it works!

    1 reply

    Super User
    August 1, 2024

    The encoder is a hardware state machine. Its architecture precludes the possibility of a large delay. More likely to be an issue with your data transfer.

    > I'm simply plotting htim3.Instance->CNT to make this chart.

    How are you obtaining the values of TIM3->CNT? Why do the values jump? Perhaps you are using UART and the values are getting buffered/lost.

    Nv7AuthorAnswer
    Visitor II
    August 1, 2024

    Wow, I was using if (HAL_GetTick() % 50 == 0) to try to print every 50ms, but it turns out that doesn't work? I'm not sure why because I know the loop is running at much higher than 1000Hz but now that I switched to properly printing it works!