A better implementation of the HAL encoder