Stm32hwencoder - weird results

Hey @Zerpoint ,

Watching through the videos it seems tha the angle is actually fine, its the velocity which is very noisny, isn’t that the case?

I’d probably say that the loop with the interrupts is slower than the one with the hardware encoder and that it calls motor.loopFOC() (where the velocity is calculated) less often. That way it calculates the velocity less often and has larger difference in the encoder counts between the calls.
Whereas the hardware encoder calculates the velocity too fast and in some cases it has 0 changes between the two call of the motor.loopFOC().

So there is avariable in the sensor class to force a minimal time between the velocity calculations, it can be set using the min_elapsed_time property of your ecoder class.
By default is 0.1ms.
Try setting it at 1 or 2 ms.
sensor.min_elapsed_time = 0.001; // 1ms

It should make the velocity much better if this is the origin of the issue.