FOC algorithm anomaly issue
I encountered a problem where I used ST's open-source FOC algorithm. Currently, my motor often shakes at a speed of 22k. Upon inspection, I found that the Hall output of the motor has some fluctuations, which is a problem with the motor itself. However, the important issue is that when the timer input captures the Hall sensor signal, there is a problem where both the capture value of 65535 and the overflow flag exist. As a result, the calculated capture value becomes 65535+65536, causing shaking. I think it's because when 65535 was captured, the program didn't process the callback function in a timely manner and only processed the timer callback function after overflowing. What if we solve this problem?
As shown in the blue curve in the figure below, when a peak appears, it is an abnormal moment:

