Need help encoder

Hi friends
I only use a portion of code of encoder class to determine velocity and position i connect my self made stm32f407zg board to industrial ac servo’s encoder and put encoder_update function on infinite loop every thing ok but when i revolve motor with constant soeed low or low vel_estimate and pos_estimate become very very large valur that i think incorrect because servo drive display show fix and stable velocity
Servo drive encoder 2500 pulse and i sampleing just like odrive
So i need to correct my mistake that how can i obtain stable and reliable velocity and position from that code
Thank you very much