How fast can I turn a single output on and off on my arduino uno?

I am working on a project in which I need to make a single output go on and off with a frequency of 100KHz. I currently have a simple code segment written that toggles the output on then delays then off then delay. I hooked it up to a scope and it seems the fastest I am able to get is about 46KHz.

Between 2 and 4 MHz


I think with fast PWM mode you can get 8mhz...?

Use one of the PWM pins, and take over the timer, put it into fast pwm mode with an appropriate prescaller for the speed you want, and adjust the TOP value to get the right frequency. For 100khz, that's 1/160th the clock speed, so you can use prescaler of 1 and TOP of.. 159 is it? (Edit: oh, and the compare value of 79) See the timer section of the datasheet for more information.

See for benchmarks (this is a stickied post in the Microcontrollers subforum).

That thread is for digitalWrite() and company - which is not how you generate a high speed square wave (though it's still an interesting resource) - that's what the hardware timers is for.

You can output the CPU clock (normally 16 MHz) on PortB0, digital pin 8, using a fuse setting.

I am new to arduino but not so much C. How do I set a fuse setting?

If you don't want to directly play with timers, you could try the "PWMFrequency" library. I got a pretty good square wave at 470kHz, and it goes up to 2MHz. PWM resolution drops with frequency, but if you just want a square wave without varying the duty-cycle, it's fine right to 2MHz. PWM Frequency Library

Fuses - change them in boards.txt, then use a Programmer and re-burn the bootloader.

ILLUSION2222: I am new to arduino but not so much C. How do I set a fuse setting?

In view of your stated requirement, what use would you get from a 16MHz signal?

Read about Port Manipulation - you can change the state of an I/O pin in a single clock cycle.

When you want to do anything that goes beyone the standard Arduino features study the Atmel datasheet.