Arduino digitalWrite speed?

Hello, I was scoping out the digital write function to see how fast it goes. I was using the PWM pin digital pin 6 and here's my code.

int ledPin = 6;                // LED connected to digital pin 13

void setup()                    // run once, when the sketch starts
{
  pinMode(ledPin, OUTPUT);      // sets the digital pin as output
}

void loop()                     // run over and over again
{
  digitalWrite(ledPin, HIGH);   // sets the LED on
  digitalWrite(ledPin, LOW);    // sets the LED off
}

Here's a video of my scoping. Arduino pin speed test - testing digital pin 6 - YouTube

I was using "single shot" because my o'scope couldn't get a lock on my signal. It appears that the HIGH and LOW signal lasts for about 5 uS on average but sometimes it takes 17 uS! Anyone know why it takes so long sometimes? This "lengthening" seems to be pretty regular.

While looking for a way to speed this up, I found Arduino Reference - Arduino Reference and it appears I can manipulate the port directly. Anyone know how fast I could get this pin to change if I used assembly or something faster?

I'm using the Arduino Diecimila ran at 16 mhz.

Running a processor at a weedy 16 milli Hertz is not recommended ;D

but sometimes it takes 17 uS!

This "lengthening" seems to be pretty regular

Clock interrupts?

Have a look here

http://news.jeelabs.org/2010/01/06/pin-io-performance/

Theoretical limit is to output the clock frequency. This is achieved by setting proper fuses. With PWM you can get clock frequency/2. With assembler you can get clock frequency/2 for short periods of time. If you allow != 50% duty cycle you can get clock speed/4 with assembler. If you insist on 50% duty cycle clock speed/6 can be achieved.

I have no clue what you mean by "faster than assembler".

Udo

if I used assembly or something faster?

Assembler is the basic machine code of the processor, it doesn't go any faster.

major discussion here:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1230286016