Loop frequency

Hey,
since I couldn't get this figured out myself, here's is my question:

In what scale is the frequency in that the Arduino (Leonardo) processes a program (resp. its main loop)? I do know of course that this is strongly tied to the number and types of commands that are used, so here is a very rough calculation that may give an insight about the probable size:

  • Measuring the voltage on around 10 pins
  • Comparing values, maybe 150 times; calculating and saving values 50 times
  • Occasionally switching on and off some pins

I am not asking for an exact number (for I know that this would be way too much). Values that are maybe 10 times higher or lower than the actual value will probably help me out very much already.

(In case anyone is interested in for what I need to know that: I want to detect square-wave infrared light and for this I think the program's loop should run at least 6 times during one period of the square-wave.)

Thanks to everyone who read this and especially to those who will answer. :slight_smile:
Best regards.

Write the program using Blink Without Delay - then you can sample at whatever frequency you want, and do the other stuff in the remaining time.

vex7:
I do know of course that this is strongly tied to the number and types of commands that are used, so

Replace "strongly tied" with "directly dependent" to fix the error in your statement.

CrossRoads:
Write the program using Blink Without Delay - then you can sample at whatever frequency you want, and do the other stuff in the remaining time.

Hi and thank you, this will probably be helpful for the opposite procedure.
What I was thinking about is the measuring. Is there a similar function for saving the pin's voltage values "in between"?

Write it into a variable - it remains that value until you change it.

Yeah, that's what I would do. So if I measure just one value per loop, the loop's frequency needs to be way higher than the square-wave's one. Which should be no lower than 20Hz.
(And if I would measure the values at several points whithin one iteration, things might become ugly, I guess.)

Probably a loop frequency of 500Hz would be awesome, although I guess 250Hz could be enough already. Are these values realistic then?

1/500 = 2mS.
So do your sample every 2mS - youv'e got 32,000 clock cycles to do your couple of hundred calculations.

Alright, now I got it.
Thanks very much for your help!