My wiring on the printer is a little untypical. It is done with unusual thick wires and they are very close to (sometimes even attached to) the iron metal rods and I did twist them with each other. I guess that this contributes to the effect. With thin flat-cable type wiring it does not happen (on both, my board and the mega8 on breadboard). So most people will not suffer from this effect.
I was able to reproduce the exact same problem with just a plain ATmega8 on a breadboard connected to only a 10k resistor, a 4.7uF capacitor and my endstop wiring, without any specific firmware. This made me think of it as a general physical effect. We have a high-impedance input connected to a low-impedance resonant oscillation.
Changing the size of the capacitor does not help. It only influences the frequency of the resonance, not so much the amplitude. To smoothen out the input signal a lowpass filter is needed. Adding a small series resistor does both at the same time: It dampens out the resonance completely and forms an effective RC input filter.
Attached is a LTspice simulation file which matches my oscilloscope findings pretty well: The voltage step excites a damped oscillation, the negative maximum of the first curve is around -1.5V to -2V. This is surprisingly high, as the build-in undervoltage diodes in the CPU should cut this to approx. -0.7V.
I was able to reproduce the exact same problem with just a plain ATmega8 on a breadboard connected to only a 10k resistor, a 4.7uF capacitor and my endstop wiring, without any specific firmware. This made me think of it as a general physical effect. We have a high-impedance input connected to a low-impedance resonant oscillation.
Changing the size of the capacitor does not help. It only influences the frequency of the resonance, not so much the amplitude. To smoothen out the input signal a lowpass filter is needed. Adding a small series resistor does both at the same time: It dampens out the resonance completely and forms an effective RC input filter.
Attached is a LTspice simulation file which matches my oscilloscope findings pretty well: The voltage step excites a damped oscillation, the negative maximum of the first curve is around -1.5V to -2V. This is surprisingly high, as the build-in undervoltage diodes in the CPU should cut this to approx. -0.7V.