Millis, and the length of time for operations.

 time = millis();
  x = (time - oldtime);
  if (x == 900);{  
     zax = analogRead(zpin); 
     zax = zax/10;}

In an atmega168, how long does it take for the operations:
zax = analogRead(zpin);
zax = zax/10;}
to occur?

I presume, less than one millisecond, am I correct?
If so, how many operations could be performed within 1 msec ?

PO'T

Yes much less.

I made a system wit 16 slide pots read with analogRead().

I could read all 16 pots, format the data, and send it over serial to a PC program every 10 mS. Could probably have done it a bit faster but i never tried.

Thanks Mik,
So, using analogRead(); to read from an accelerometer, I could read three of its axis, name the results (xax, yax & zax), and maybe some other operations, within one millisecond, correct?

po't :slight_smile:

assuming you run at 16mhz, one instruction takes 1/16th of a Microsecond.
I dont know, if the Atmega has a fixes instruction length, but even if one instruction is 4 byte long, you have 4000 instructions in one millisecond.
I guess, you can process your needs (and some more operations) within one ms.
If you make more complex mathmatics with floats, the margin would get thinner, cause the AVR has no native support for that in hardware.
:smiley:

sure, just recognize that some arduino instructions (like analogRead() and float math) will be dozens of native instructions.

also serial i/o at 9600 baud is about 1 ms/character.