Skip to main content
APoto.2
Associate
February 15, 2023
Solved

Counting pulse + direction encoder

  • February 15, 2023
  • 2 replies
  • 3046 views

Hello,

I'm trying to read the pulse counter with a timer on STM32H747. The counter produces pulses up to 100KHz on one timer channel and high \ low signal to define the direction.

I tried two approaches.

  1. Reference manual says, as I understand, that such signals are supported out of the box. Section 40.3.22 says "To select Encoder Interface mode write SMS=‘001’ in the TIMx_SMCR register if the counter is counting on TI2 edges only, SMS=’010’ if it is counting on TI1 edges only and SMS=’011’ if it is counting on both TI1 and TI2 edges." But setting it to TI1 only mode still behaves as TI1 & TI2. So, it reads quadrature signal, not pulses.
  2. Then I tried to use the timer in counter mode. It didn't work for me.

My questions are: does encoder mode supports pulse + direction signal, and is there a good example of using a timer in counter mode (mode 1)?

Thanks.

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

The "Encoder mode" is for quadrature encoders. Timers in 'H7 don't have the direction-step mode (only 'G4 and 'U5 timers support this).

@berendi​ posted here a possible workaround, but you may want to use an undocumented feature or give up a couple of pins.

JW

2 replies

waclawek.jan
waclawek.janBest answer
Super User
February 15, 2023

The "Encoder mode" is for quadrature encoders. Timers in 'H7 don't have the direction-step mode (only 'G4 and 'U5 timers support this).

@berendi​ posted here a possible workaround, but you may want to use an undocumented feature or give up a couple of pins.

JW

APoto.2
APoto.2Author
Associate
February 15, 2023

Thank you. Very interesting links.