Nick Gammon's code worked fine for me. Here is an oscilloscope picture of the waveform I've got from his code:

His code above (from Nick Gammon, on Jan 25 '16 at 20:33) worked excellent for me. I used his code on Arduino UNO and got about 7.9 MHz of output frequency on an approximately 1 V amplitude (peak-to-peak, with spikes making it go to about 2 V peak-to-peak amplitude).
The image above was obtained with my 40 MHz Oscilloscope from ICEL Manaus (manufacturer) at pin 9 (I used the Arduino UNO), with a LED and a resistor as a load at pin 9:
- a green LED of about 1.79 V voltage drop
- and a 4.7 Ohms resistor with 5% tolerance
The oscilloscope probe (Channel 2, with fall slope trigger detect) is on the 4.7 Ohms resistor. It follows the connection order out of the pin 9 from Arduino UNO:
PIN 9 > green LED > 4.7 Ohms resistor > GROUND.
The green LED keeps blinking at a normal luminescence, as compared when used at other output frequencies.
I used a external 5 V DC power supply, along with the USB connection on my PC.
If you have any questions just put them here. Thanks and thanks Nick Gammon
while(true){...}
will make it a bit faster, instead of letting the loop function exit.