# How many of time to arduino uno run a command?

how many of time to arduino uno r3 run this command?

for (int8_t i=0; i<= 50;i++)
for(int8_j=0;j<=50;j++)
if (a*[j]==1) c++;*

Hi chipcoiga, your question is hard to understand. Can you please re-word.

I have adjusted the size of the array to fit in UNO’s memory

``````uint8_t a[10][51];
volatile int c = 0;

void setup()
{
Serial.begin(115200);

Serial.println("Start ");

uint32_t start = micros();

for(int8_t i=0; i <= 10; i++)
for(int8_t j=0; j <= 50; j++)
if (a[i][j]==1) c++;

uint32_t stop = micros();

Serial.println(stop - start);

}

void loop()
{
}
``````

OUTPUT:
Start
428

so a 51 x 51 matrix takes about 5x as long => ~2200 micros

it is C++ language extended. usually use to write arduino programe.

example:
time (us) for i → i+1 about 8us → this is period.
==> if I have for(i=0;i<125;i++), time is: 8us * 125 = 1000us = 1ms (0.001 sec)

But I don’t know in arduino (16Mhz). how many time for : i → i+1

` uint32_t start = micros();` <== Thank you. I need it

best way is to use objdump.exe and create assembly listing then you can count clock cycles...

Depending on the machine code your speed may increase greatly.

Register-Register operations generally take 1 cycle while fetch from and write to RAM can take 2. I have external RAM for a MEGA, it needs 3 cycles to access. It is worth it for 64K banks of RAM!

16MHz is 16 cycles per usec.

c++; // Increments c. If i is a single byte register variable (likely compiles that way) then this takes 1 cycle.

if (a[j]==1) c++; Fetching values from the 2D array takes a few cycles each, the if() should take perhaps 2.

Values for micros() are rounded to the next 4. AVR is 8 bit CPU, it takes time to get the micros value! The people I see measuring the high degree timing accuracy generally use an oscilloscope to do it.

c++; // Increments c. If i is a single byte register variable (likely compiles that way) then this takes 1 cycle.

if (a[j]==1) c++; Fetching values from the 2D array takes a few cycles each, the if() should take perhaps 2.

I think I understand somethings you said :D Thanks. Close toppic :)

GoForSmoke: I have external RAM for a MEGA, it needs 3 cycles to access.

Interesting! How does that work?

The AVR line that AFAIK ends with the Mega2560 have external RAM capability outlined in the ATMEL docs. I got a 512K board from Rugged Circuits for under \$30 shipped, it plugs right in I and use their software. The 3 cycle access time is from the ATMEL doc.

You don't get to use the whole 512K. It is arranged as 8 banks, 64K each. The internal 8K of the MEGA takes up the low 8K addresses and becomes stack space. You get 56K of heap from whatever 64K bank you select, it is all directly addressable from the MEGA. It looks like bigger internal RAM.

They sell smaller boards but the price is not half or even near for half the RAM, for a few bucks extra get the full. http://174.136.57.214/html/quadram.html

Ah, I see. I didn’t realise that the mega2560’s pins could be configured as an external memory bus. Must use 24+ pins. Not an option for the lowly '328 then…

Not an option on many of the 40-pin AVR’s, only the one line that I’ve seen.
ATmega640, 1280, 1281, 2560, 2561.

You could probably run external RAM with parallel ports (and maybe an address chip) on a 1284P or even a 32A (2 40-pin examples) but it won’t directly address the RAM. It might/should be faster than serial (SPI) RAM that even an ATtiny could use.

I had to Google the QuadRam shield as from the Rugged Circuits Home Page it wasn’t in the Products Page. I dunno what it means. Maybe they buy those from elsewhere or maybe they won’t stock them once they’re sold. Why make and stock what doesn’t return fast enough to be an asset? There’s really no big call for large RAM on a MEGA, I got one just because I liked the idea and not out of any need, but if I find one I have the hardware. I have a decent range of resistors, caps, leds, etc, on the same basis – just to be able to try out what strikes my fancy. Hey, it’s cheaper than collecting power tools and the like!