Measuring Motor RPM using Hall Encoder Mode of TIM2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-04-30 4:37 PM
I'm controlling a BLDC motor with an STM32F401 and am using TIM1 to generate the PWM waveforms to drive the motor and TIM2 in encoder mode to read the Hall encoder inputs from the motor.
This setup is driving the motor well, but I'm setting a lot of variance on the timings from TIM2. I have TIM2 set up to capture a count into CC1 every time it sees a new edge (rising or falling) on any of the three Hall inputs. I'm then using this count to compute the spin rate of the motor in RPMs.
To test this, I set up the motor running at 5000 RPM in open-loop mode (no changes to the PWM settings), and the unloaded motor is holding a very steady RPM as measured with an external laser tachometer. When I compute the rotation rate using the TIM2 CC1 count between Hall encoder edges, I get what looks like random noise between 4500 RPM and 5500 RPM, but when this is filtered, it's very close to 5000 RPM. See the plot below. The green trace is the raw RPM values computed from the TIM2 timer counts and the red trace is the averaged RPM.
What I wondering here is why measuring the time between Hall encoder edges shows so much variation? The motor itself is running very smoothly and steadily at 5000 RPM as measured by the tach. TIM2 is a 32-bit timer, so I'm not overflowing it (it would take ~50 seconds to overflow). Anyone have any ideas?
- Labels:
-
STM32 Motor Control
-
STM32F4 Series
-
TIM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-04-30 11:20 PM
The diagram shows only very few different discrete rpm values repeatedly occurring in a random looking pattern. Why is ist?
At what speed does the TIM2 counter run? How does the raw sequence of TIM2 captured values (TIM2 CCR1) look like?
hth
KnarfB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-05-01 1:09 AM
What you see is probably asymmetry in mounting and sensitivity of the three Hall sensors. Try to calculate RPM by taking into account only every third rising edge (or don't use the XOR).
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-05-02 9:17 AM
TIM2 is running at 84 MHz. I will collect and post a sequence of captured TIM2 CCR1 values soon.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-06-27 12:28 PM
Can you share the code for us to clearly inspect?
