# Quick Questions on clock "Arduino Uno"

I want to know how much time the Arduino Uno Atmega328 16MHz clock take to complete a program. Do you have to calculate the number of instruction and then apply a formula?
For example how much time it take to run the blink LED code as shown below:

int led = 13;

// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

1. And what would happen if the clock is lower than 16MHz, the micro-controller will execute the program slower?
2. How long it take for one instruction for example digitalWrite to be executed? All the instruction take same amount if not where can you see the how long the instruction take to be executed?
3. How many instruction is executed in one second? How can you calculated the amount of time it take the clock to ticks, it is 1/16MHz=6.25*10^-8?
4. Anyone got a good website with good example of clock calculations?

You'll have to dig out the spec sheet for the chip (e.g., Smart | Connected | Secure | Microchip Technology) and look at the clock cycles for each instruction generated by the compiler if you need an actual count. Some instructions only take one clock cycle, while others may take 3 clock cycles. In short, there is no simple answer to your question that gives a precise answer without plowing through the generated assembler code. You could get an approximation by timing several hundreds passes through a loop and calculating an average, if that's close enough.

1. How long it take for one instruction for example digitalWrite to be executed? All the instruction take same amount if not where can you see the how long the instruction take to be executed?

You might first get a handle on the proper word usage for you question. First digitalWrite() is a C++ function, not an instruction, that may contain dozens of single AVR machine instructions, and as all ready been stated, an AVR instruction can vary (most are single clock cycles, other more) but at 16Mhz clock rate most are executed on 64 nanoseconds.