cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G431 Encoder Mode Issue

Danu_Park
Associate II

JPark17_0-1725951500574.png

JPark17_1-1725951574439.png

 

I have configured the timer clock to 170MHz. According to the datasheet, the maximum fENC value is 42.5MHz when the timer clock is 170MHz, and the tW is specified as 2~3Tck.

I am using a quadrature encoder with two channels that provides 1024 pulses per revolution.

I have set TIM4 to encoder mode, as shown in the attached image, and I am monitoring the htim4->Instance->CNT value using the debugger.

The issue is that when I turn the motor slowly by hand, the counter works correctly, counting from 0 to 4095 as expected. However, when I start rotating it faster, the counter starts missing counts, and at higher speeds, the counter doesn't increase at all.

I'm not sure what the issue could be. Where should I start looking to troubleshoot this problem?

Danu
1 ACCEPTED SOLUTION

Accepted Solutions

Is this a "known good" hardware such as Nucleo/Disco, or your own hardware?

In the former case, isn't something on-board connected to the given pins?

In the latter, make sure the signal connections are OK (think bad solder joints, shorts, poor connector contacts).

In any case, make sure that GND connections are rock solid.

One test may be, in a tight loop, read one of the input pin's state and set a GPIO output pin accordingly, observing that output on oscilloscope (then try with the other input pin).

When observing with oscilloscope, use the board's (STM32's) GND, and probe the signals as close as possible to the physical STM32 pins (ideally, directly on them).

JW

View solution in original post

6 REPLIES 6

Observe the waveforms on oscilloscope.

Is the duty cycle of both waveforms close to 50% and the phase shift between them close to 90deg. at the high rotation speeds, too?

JW

 

Danu_Park_0-1725956835922.png

The oscilloscope waveform looks like this. Currently, speed control is not working properly, so the duty cycle is not at 50%.

Danu

This looks OK.

And this is the speed where it starts to lose pulses?

JW

When I spin the motor as fast as I can by hand, the count should be 0 when it reaches the home position, but it ends up around 3200, so counts are missing. The motor is currently running with the code generated from MC Workbench, so I cannot determine at which speed the counts are missing because the encoder counter is abnormal, and RPM control is impossible. When I checked the encoder signal with an oscilloscope, the signal was about 100kHz, which corresponds to around 5000 RPM. At 5000 RPM, the counter doesn’t increase at all.

 

Thank you

Danu

Is this a "known good" hardware such as Nucleo/Disco, or your own hardware?

In the former case, isn't something on-board connected to the given pins?

In the latter, make sure the signal connections are OK (think bad solder joints, shorts, poor connector contacts).

In any case, make sure that GND connections are rock solid.

One test may be, in a tight loop, read one of the input pin's state and set a GPIO output pin accordingly, observing that output on oscilloscope (then try with the other input pin).

When observing with oscilloscope, use the board's (STM32's) GND, and probe the signals as close as possible to the physical STM32 pins (ideally, directly on them).

JW

Danu_Park_0-1726012266042.png

Danu_Park_1-1726012305213.png

 

I am using the EVLSPIN32G4-ACT board. When measuring the encoder waveform from the GPIO port, I noticed signal distortion.

After checking the circuit diagram of the EVLSPIN32G4-ACT board, I found a 10kΩ + 1nF RC filter on the encoder pins. After removing the 1nF capacitor and reading the counter value, it worked perfectly without any missing counts!

 

hank you very much for your advice!

 

 

Danu