oooh, thanks for finding it - that will be due to the custom getVelocity again.
I think I will change the code as I described above, to just use the timer and set the timer limit to the CPR - then the timer will overflow once per full rotation, and I’ll just let the Sensor base class handle velocity and full rotations in the normal way. If the code had been that way from the beginning you would not have all these problems.
You have to pass normal pin-ids (PB6, PB7) to the constructor. Afterwards, you can set the pins manually using sensor._pinA = PB_6 and sensor._pinB = PB_7_ALT1. Then you call sensor.init(), and if your PinMap_TIM is correct, everything will work.
So like this:
STM32HWEncoder encoder = STM32HWEncoder(ENCODER_PPR, PA11, PA12); // TIM4
void setup() {
encoder._pinA = PA_11_ALT2;
encoder._pinB = PA_12_ALT1;
encoder.init();
}
I’ve tried it out myself using alternate timers and this works. So if you’re still having troubles with this procedure, I think it now down to the incorrect PinMap.