How to handle encoders overflow

Hi guys,

Does the Encoder library (of Paul Stoffregen) handle the overflow of encoders?
If not, any suggest on how to handle that event?
Thank you in advance for your collaboration.

Regards,
Marco

What does “handle overflow” mean in your case? What should happen?

Common encoders either report an incremental change in position, or absolute shaft orientation. Where do you think "overflow" might take place?

Fixed sized counter variables will wrap-around, just like the output of millis() and micros(), and you can deal with
this the same way, by using the difference between two values, or making the count variable have more bits.

For motion control this isn't an issue as the hardware constrains the limits of travel, just choose enough
bits for the encoder count variable.

Hi guys,

I would have appreciated to receive some suggestions about how to avoid wrong readings due to the limited size of the variables (Encoder library increments an int32_t variable for each impulse read, so after it has been read 4294967296 impulses from -2147483648 to 2147483647 it has to restart necessarily).
Referring to this it isn't even defined if an int32_t variable will roll over or not!
Anyway, after these considerations I realized that if the encoder would read only 2147483648 impuleses (that generates an overflow starting from 0), the robot would have done around 200 km, so, yes, I stopped thinking about the overflow possibility.
Thank you for your attention and collaboration.

Best regards,
Marco