Here are several recommendations for encoder connections, in order to avoid loss or perturbation of encoder pulses in environments with strong electromagnetic interference:
1) Shield the encoder cables. Connect the shield to the earth potential, only at one end. Avoid connecting the shield at both ends. 2) In case the connection cable between the encoder and the drive is longer than ~5 m, we recommended that you place a local decoupling capacitor near the encoder, between +5 V and GND. A capacitor of 1 ... 10 µF is a good starting point, rated at 6.3 V. 3) Avoid running the encoder wires in parallel with the motor wires for a distance longer than ~2 m. If this situation cannot be avoided, use shielded cable with low capacitance between the wires, and separate the encoder cables from the motor cables, shielding them separately.