I've read that Arduino runs at 16 MHz (btw is that true?) and I thought it would not be a problem to execute (more or less) 60 float operations every 1 ms: it indeed is a problem and I have to slow down to 250 Hz (once every 4 ms).

Simply because I didn't read it on the datasheet... but I guess I can trust Massimo!

Quote

If you are using an original arduino you can see by yourself by looking at the quartz next to the processor.It should say S16B00K7 the 16 means 16MHz

Nice!

Quote

in terms of floating point speed it all depends on the quality of the software implementation as the processor doesn't have a floating point coprocessorwe are using the one that comes with avr-gcc so you should check if there is any indication on the avr-libc website

PS: I thought I might calculate how much time it takes for two floats to be added or multiplied but I need a more precise version of the millis() function... does a version of millis() that work with microseconds (instead of milliseconds) exist?Thank you.

PS: I thought I might calculate how much time it takes for two floats to be added or multiplied but I need a more precise version of the millis() function... does a version of millis() that work with microseconds (instead of milliseconds) exist?Thank you.

You can use timer1 which can be accurate to a fraction of a microsecond but its easier just doing a big loop of floating points and using millis. If you do a say ten thousand fp operations you should get a pretty good estimate of how long one would take

You can use timer1 which can be accurate to a fraction of a microsecond but its easier just doing a big loop of floating points and using millis. If you do a say ten thousand fp operations you should get a pretty good estimate of how long one would take

I used a program to separately calculate ADD and MULT time.The results were: 12 microseconds and 5 microseconds respectively.

My code has 28 multiplies and 36 sums for a total of 572 microseconds.In addition it must be considered that I'm working with matrixes and that I'm handling 4 PWM outputs and one analog input.

...Is it enough to exceed 3 milliseconds?

PS:This is the code I wrote (the printDouble function was created by mem!):

Serial.begin(9600); Serial.print("It has taken "); Serial.print( total ); Serial.println(" milliseconds in total."); time = (total*1000)/prec; printDouble( time, 6 ); Serial.println(" microseconds per one ADD");

Serial.begin(9600); Serial.print("It has taken "); Serial.print( total ); Serial.println(" milliseconds in total."); time = (total*1000)/prec; printDouble( time, 6 ); Serial.println(" microseconds per one MULT");

It's definitely good to consider things like that to make sure that your estimates are reliable. If he was trying to time how long it takes to add and multiply integers, the overhead of the for loop would be significant. In this case it seems the overhead is maybe about 5 - 10% of the total time, so it can be safely ignored if all we care about is an order of magnitude estimate.

I doubt that worrying about the time spent in the for loop is the right place for your efforts to improve speed. I think you would get a far greater performance improvement if you can do the math using longs rather than floats. In many applications one can scale floats to longs with sufficient precision and if yours is one than you will considerably speed up your execution time. You can probably find a number of examples of how to do this on these and other AVR forums.