Encoder pulse capture in STM32