Thank you so much, you are right, the problem is the noise, I have connected a oscilocope to the A and Z phase in the encoder, I have attached the image. The machine is connected in a warehouse that has almost 50vfd drivers. How do you think that it can be solved?, all the drivers are connected to earth ground. I have isolated the machine and the encoders from earth ground.
Maybe a EMI filter can solve the problem?