|
return (ticks - min_ticks) * _2PI / (max_ticks - min_ticks); |
Current behavior:
uint32_t ticks = getDutyCycleTicks();
return (ticks - min_ticks) * _2PI / (max_ticks - min_ticks);
Since ticks and min_ticks are unsigned, ticks < min_ticks wraps to a huge value. On an AS5048A PWM sensor near the zero boundary I see:
duty_ticks=152 angle=705512.000000 velocity=7055119.500000
Expected: values below min_ticks should clamp or be rejected.
Possible fix:
uint32_t ticks = getDutyCycleTicks();
ticks = constrain(ticks, min_ticks, max_ticks);
return (ticks - min_ticks) * _2PI / (max_ticks - min_ticks);
Arduino-FOC-drivers/src/encoders/stm32pwmsensor/STM32MagneticSensorPWM.cpp
Line 29 in ed05aa1
Current behavior:
Since ticks and min_ticks are unsigned, ticks < min_ticks wraps to a huge value. On an AS5048A PWM sensor near the zero boundary I see:
duty_ticks=152 angle=705512.000000 velocity=7055119.500000
Expected: values below min_ticks should clamp or be rejected.
Possible fix: