I'm trying to get a handle on the performance of the system
The system runs at 16MHz. Nearly all AVR instructions are executed in one clock cycle, so you'll be executing instructions at about 16 million instructions/s.
When using a high level language (like C), the way you write your program has a serious impact on performance. For example, let's look at the code you posted:
int outPin = 13;
void setup()
{
pinMode(outPin, OUTPUT);
}
void loop()
{
digitalWrite(outPin, HIGH);
digitalWrite(outPin, LOW);
}
The main() function is provided by the Arduino environment. It calls setup() once, then calls loop() once each time through its main event loop, so the sequence of events is:
- main() does some stuff
- main() calls setup()
- main() does some stuff
- main() calls loop()
- loop() calls digitalWrite()
- ldigitalWrite() sets the pin low
- loop() calls digitalWrite()
- digitalWrite() sets the pin low
- main() does some stuff
- ...
Now this is pretty fast - way too fast to generate PWM for a typical servo, for example. I haven't measured the actual resulting clock rate for such a system, and to be honest I'm just too lazy to pull out the o-scope and arduino to set it up and see right now (I'm on vacation

).
We can make the pin toggle faster by looping inside our own loop() function:
#define PIN 13;
void setup()
{
pinMode(PIN, OUTPUT);
}
void loop()
{
while(1)
{
digitalWrite(PIN, HIGH);
digitalWrite(PIN, LOW);
}
}
We never leave our loop function's infinite while loop, so the new sequence of events is:
- main() does some stuff
- main() calls setup()
- main() does some stuff
- main() calls loop()
- loop() calls digitalWrite()
- ldigitalWrite() sets the pin low
- loop() calls digitalWrite()
- digitalWrite() sets the pin low
- loop() calls digitalWrite()
- ldigitalWrite() sets the pin low
- loop() calls digitalWrite()
- digitalWrite() sets the pin low
- ...
Note we're calling a function that does some stuff before it gets around to setting the output pin state. Let's say that is still not fast enough, and we want to see as close to a 16MHz square wave as we can get.
#define PIN 13;
void setup()
{
pinMode(PIN, OUTPUT);
}
void loop()
{
while(1)
{
PORTB = 0x40; // set pin 13 to high, all other port B pins low
PORTB = 0x00; // set pin 13 and all other port B pins low
}
}
As best I can tell, this will get the absolute maximum square wave of 16MHz. Note we're not doing anything else, not even testing to break out of the loop. If we wanted to execute this loop N times, we'd slow down to a maximum of 8MHz or so. Also note we may be occasionally interrupted by a service routine that is triggered by an internal timer, so our square wave could pause every so often.
That's about enough random blathering from me. If you'd like a better answer, tell us what you are trying to do and that will in turn make our answers a bit more meaningful.
-j