What is causing the random noise on gpio pin

Simple toggling of pin 40 at 1khz. This is very high amplitude and random.

Any suggestions on how to find or eliminate this. Some times it will last for 2 cycles.