I have an encoder that gives 4300 increments per rev. And I need at least 3 turns in either direction. (for a steering wheel) However, when I turn it just a bit, it already hits the extremums. This is after a few degrees clockwise:
This is my descripor:
My code:
while (1)
{
steer.direction = position - position_p;
position_p = position;
USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, &steer, sizeof(steer));
HAL_Delay(5);
}
I have tried using an absolute value. With 8 bits it just overflows after a few degrees and comes back to the opposite extremum. Maybe 16 bits could solve that but I can't get it to work that way.
I managed to use a 16 bit absolute position. I think it didn't work because the "send" function only took 8-bit values. So I've split the 16 bit variable into a 2x8-bit array. (im using cubeIDE)
steer.direction[0] = position & 0x00FF;
steer.direction[1] = position >> 8;