problem with runtime of sketch

hey folks,

i'm new to arduino world. is there any way that i could adjust the running time of my skecth in the arduino (Duemilanove)? before that i wanted to know the default execution time of a loop in arduino.

i wanted the run time of my sketch not exceeding 25milliseconds. How could i get this done?

help me..!

thnq, chiru

i wanted the run time of my sketch not exceeding 25milliseconds.

And what sketch would that be?

the time it takes 'loop()' to loop is dependant on how much code is inside it. Using port mapping can reduce pin access times. Optimise the code to gain even more speed increases.

Depending on your needs you could make a DIY non standard 20Mhz board, giving you that extra edge.

the time it takes ‘loop()’ to loop is dependant on how much code is inside it.

Not so - it is dependent upon the time it takes to execute the code inside it - there could be, for instance, a tiny amount of code, outputting characters at 300 bits per second to the serial port.

chiru42: i wanted the run time of my sketch not exceeding 25milliseconds. How could i get this done?

25 milliseconds is quite a long time. An empty loop will complete in microseconds, not milliseconds. So, to enable your loop to complete in 25 milliseconds, you need to write your code so that it takes less than 25 milliseconds to execute. Depending what you need to achieve in your loop, that could be very easy or very hard.

I guess another question is: What's an easy way to approximate the execution time of various parts of a functional sketch?

isnt there any way that i can make use of external oscillators?

My purpose of coding in loop() would be, sensing 3 analog inputs and some handful of calculations(say 20lines) of mathematical equations and sending the outputs through 5pins.

can someone tel me if all of these be done in 25milliseconds?

can someone tel me if all of these be done in 25milliseconds?

Until we see your code, who can say? 40Hz should not be a problem, unless the maths is complicated.

some handful of calculations(say 20lines) of mathematical equations

LOCs is no indication of execution time.

apart from reducing the LOC, is there any other way to take the control over the execution speed of the sketch?

Depends on what is in the Lines Of Code and how complex they are, and especially if there are any floating-point calculations.

A typical optimization of an algorithm is to scale values into integers and do the math there.

Write it, test it, if too slow find a way to optimize, if too fast find a way to slow down. For accurate execution intervals you will want timer interrupts, assuming your code runs in less than 25ms.

You could time how long your code actually takes to execute, and pad out with "delay()" or "delayMicroseconds()". But, without seeing your code (last hint), it's all just guesswork. If you're not willing to share, I'm going to lock this thread, because you're just wasting time.

terryking228: Depends on what is in the Lines Of Code and how complex they are, and especially if there are any floating-point calculations.

A typical optimization of an algorithm is to scale values into integers and do the math there.

i dont think i can eliminte floating point caliculations. so the only way i could reduce the execution time is reducing LOC. is it so?

Please don't feed this particular troll until we see some code.