Use a zener diode and a resistor in a series combination and then in parallel with a small capacitor to absorb the spikes. The diode should turn on fast and the capacitor should have low lead inductance. Also, the RC charging time of the capacitor should be slightly more than the turn on time of the diode as not to be charged at the spike's voltage before the diode turns on.my square wave output consisit of a few spike occasionally. anyway to remove the spike/noise ?