STM32G431 Encoder Mode Issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-09-10 12:03 AM - edited ‎2024-09-10 12:09 AM
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?
Solved! Go to Solution.
- Labels:
-
HRTIM
-
STM32G4 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-09-10 03:46 AM - edited ‎2024-09-10 03:48 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-09-10 01:07 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-09-10 01:28 AM - edited ‎2024-09-10 01:28 AM
The oscilloscope waveform looks like this. Currently, speed control is not working properly, so the duty cycle is not at 50%.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-09-10 02:15 AM
This looks OK.
And this is the speed where it starts to lose pulses?
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-09-10 03:20 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-09-10 03:46 AM - edited ‎2024-09-10 03:48 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-09-10 05:29 PM
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!