So, what I did is I placed a Cap between the input of the buffer and GND.
Everything is working properly now. The only thing is that I don't know why…
There is nothing dirty in the original signal, however it might appear as "dirty" for your counter, and here is why.
There are
signal reflections ( <--- words written in italics are dedicated terms) in the wires between the GPS and the input gate.
- any piece of wire acts as a
transmission line- signals travels through wires at almost the speed of light (to be more precise at the
velocity factor * speed of light, where the velocity factor is less than one, can be for example 0.6 to 0.8 or so, it depends of the transmission line)
- when the signal arrives at the end of the wire, only a part of it is continuing its travel into the IC's pin, the other part is reflected back (but only when there is an impedance mismatch between the impedance of the transmission line and the impedance of the input gate)
- the voltage of the signal reflected back can have the same sign or opposite sign relative to the original signal. The sign is given by the ratio between Zline and Zgate (Z means impedance)
- then the reflected signal arrives back from where it started, arrives at the output of the GPS again
- then a part of it enters back into the GPS and an even smaller part reflects a second time going again to the input gate of your IC, and so on back and forth
- each edge suffers from this ping-pong back and forth between the two ends of a wire
- the ugly part is that the voltage of the reflected signals adds up with the original signal, making it to double in voltage or to go to zero, therefore it distorts the original signals and can lead to the apparition of fake edges detected by the counter
The only way to avoid the reflections is to remove any sudden changes in impedance along the path of the signal, or other said to
match the impedance between the source and the load.
https://en.wikipedia.org/wiki/Reflections_of_signals_on_conducting_linesThe video linked above was for showing on the oscilloscope how the waveform changes at the interactions between the original and the reflected signal.
Another different cause can be that the stray capacitance and the inductance of the wires makes an LC circuit that has a tendency to oscillate, thus creating fake spikes at each edge of the original signals.
When you put that capacitor to the ground, you make a low pass filter that is killing the spikes produced by the reflections or by the parasitic oscillations in the wires.