Time to actually send a "1"

Hi,

I'm working on a project for school and I would really like to know how long it takes for the arduino to send a logic "1" to a pin (for ex. pin 13) when I have:

int led = 13;

void setup() { pinMode(led, OUTPUT); }

void loop() { digitalWrite(led, HIGH); }

so actually I want to know the time between telling the pin to go HIGH and the pin actually being HIGH..
I know it ain't long but I need it to make a prediction of the accuracy of a steppermotor driven project..

--Thx in advance, NklsP

Do it using Direct Port Manipulation:

Assuming D15 is Port B bit 5 (going from memory only)

PORTB = PORTB | 0b00100000; // set D13, leave rest alone
PORTB = PORTB & 0b11011111; // clear D13, leave rest alone

Either one takes just a couple clock cycles, so something like 130-200nS. 0.13 to 0.2uS. 0.00013 to 0.0002mS

The bootloader startup, other sketch startup, setup() and then loop() will add some time between power on and the pin actually going high (assuming you have a small pulldown like 10K to Gnd so the pin ins't floating until actually commanded high).

The loop() { } function adds something like 12uS for each pass, so if your code was

void loop(){
PORTB = PORTB | 0b00100000; // set D13, leave rest alone
PORTB = PORTB & 0b11011111; // clear D13, leave rest alone
}

You would see high pulses at ~ 80-85KHz rate I think.

Oh, ok man so actually I would never notice it for my use we are making a simple engraving machine the only thing that will affect the acuracy will be the degree of the stepper.

Thank you for the quick response, it's my first post on the forum and I really like it already :smiley:

-- NklsP