Skip to main content
Explorer II
December 19, 2024
Solved

STM32 Timer encoder mode with synchronization

  • December 19, 2024
  • 4 replies
  • 1409 views

I am using STM32H753.

My TIM2 is in Encoder mode, and I give two external signals from my incremental encoder to TIM2_CH1 and TIM2_CH2. My TIM2 is counts perfectly (Up or Down) when I move the encoder clockwise or anticlockwise.

Now i want to syncronize another two timer TIM1 and TIM8 (or any other ) with TIM2. so that when i move encoder Clockwise or Anticlockwise then conunts of all three timers are increase or decrease togather.

 

Is it possible ? How ? 

 

As per Reference Manual Chepter of Timer synchronization, I can connect TRGO internally (For Update Event) to another Timer but will it be work in Encoder mode ? I mean how single line (TRGO) can send increment or decrement data to another timer ?

 

MJ_1992_0-1734619617197.png

 

 

 

    This topic has been closed for replies.
    Best answer by waclawek.jan

    As others said above, there's no way you can transfer the clock and direction from one timer to other, so you have to look for workarounds.

    You certainly can use the remaining two channels of given timer (TIM2) to do the capture.

    As suggested by @mƎALLEm above, you can connect several timers in parallel, all of them in encoder mode, so you'd need four timers for the eight input signals. That's not that far fetched and easy to accomplish, but will cost the extra pins.

    Another option might be to trigger DMA transfer from TIM2_CNT to memory by the pins. There is some latency involved and that may or may not be an issue in your case. This is traditionally done via timer input capture, too, that capture not performing the capture itself but serving as a DMA trigger; but maybe in your 'H7 there are ways to trigger DMA from pins directly (EXTI), I am not familiar with the 'H7 and its DMAMUX.

    JW

    4 replies

    Technical Moderator
    December 19, 2024

    Hello,

    I don't think you can propagate the increment/decrement behavior between timers. But what is your use case?

    Why don't connect the encoder output in parallel to other TIMs channels then?

    Graduate II
    December 19, 2024

    Why would you want two additional timers in sync doing the same thing? If it was possible, the CNT would be the same on all 3 timers and would not benefit you.

    If you are trying to do something else using 3 timers in sync, maybe explain in more detail what you're trying to accomplish?

    MJ_1992Author
    Explorer II
    December 20, 2024

    @Karl Yamashita and @mƎALLEm  Thanks for your replay.

    I need to use other timers for scanning other external Eight Signals with respect to Encoder signals ( As Input capture ) So that i can get encoder count (Or encoder position) at Rissing or Falling Eadge of that Eight Signals.

    Super User
    December 20, 2024

    As others said above, there's no way you can transfer the clock and direction from one timer to other, so you have to look for workarounds.

    You certainly can use the remaining two channels of given timer (TIM2) to do the capture.

    As suggested by @mƎALLEm above, you can connect several timers in parallel, all of them in encoder mode, so you'd need four timers for the eight input signals. That's not that far fetched and easy to accomplish, but will cost the extra pins.

    Another option might be to trigger DMA transfer from TIM2_CNT to memory by the pins. There is some latency involved and that may or may not be an issue in your case. This is traditionally done via timer input capture, too, that capture not performing the capture itself but serving as a DMA trigger; but maybe in your 'H7 there are ways to trigger DMA from pins directly (EXTI), I am not familiar with the 'H7 and its DMAMUX.

    JW