The most common source of this type of problem is electrical noise generated
by a VFD or brushes in a DC spindle motor. Try running without turning on the
spindle to verify if this is indeed the source of the problem.
Things to try:
If it is, and you are using a VFD, try using a shielded cable from the VFD to
the spindle and ground the shield to the Earth or safety ground terminal on
the VFD.
Keep power wiring to and from the VFD as far from other wiring as possible.
Try a "common mode choke" near the VFD output and possibly on the input.
All three wires of 3 phase must go through the same choke.
http://www.pmdx.com/VFD-ChokeTry even more debounce in software.