Pages: [1]   Go Down
Author Topic: void loop speed?  (Read 6897 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 23
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

Simple question that I can't find a specific answer to:

What speed/frequency does the void loop () run at? - or what sets what speed/frequency it runs at?

I'm calling a function from the void loop that sets a Digital I/O High or Low - just wondering how fast it's going.

Thanks - J.
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 614
Posts: 49358
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The loop function is called in an infinite loop from within main.

As soon as loop returns, it is called again.

The length of time between the end of one execution of loop and the start of the next execution of loop calls is a few clock cycles while the return address is popped off the stack, jumped to, pushed back on the stack, and a jump to the loop function location in memory is made.

The length of time that loop takes to execute is a function of what you have it doing.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 23
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Paul - that makes sense.

Might stick a frequency counter on it to see exactly what it's doing.
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 614
Posts: 49358
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Everything you do in loop affects it's execution time. Don't think that you can DO anything with knowing how long a single pass through loop takes.

The act of measuring how long it takes affects how long it takes.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The act of measuring how long it takes affects how long it takes.

Ah, just as my signature line states, measurement changes behaviour.  smiley-wink

Lefty
« Last Edit: November 21, 2009, 09:39:30 am by retrolefty » Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 614
Posts: 49358
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I was trying to remember who's line that was.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 23
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The act of measuring how long it takes affects how long it takes.

Heh, yeah, fair point. I actually meant sticking a hardware frequency counter on the pin I'm changing the state of...

...which will put a load on it... but I'll stop there before I start questioning whether or not I'm *really* typing this.  smiley-wink
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 614
Posts: 49358
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just as a matter of curiosity, why are you doing this?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 23
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm using a 4052 multiplexer to 'multiply' the outputs of a TLV5618 DAC (from 2 - to 2 x 4).

The mux is being run (or clocked or whatever) by the Arduino.

Each output of the mux feeds a sample and hold.

I need to run the mux as fast as I can - but still give the DAC and the S&H time to do their thing and settle.

This is all pretty new to me - so I was just curious what the 'fastest' real world speed out of the Arduino might be.

Hope that makes sense - I'm kind of making this up as I go right now.

Thanks.
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Assuming you only have the two digital writes in loop the frequency is just under 130 kHz (the period is 7.75us). Around half the time is taken by the digital writes, the remainder by the loop code. If you want to generate high frequencies you would be better served by using one of the timers, for example: http://www.arduino.cc/playground/Code/FrequencyTimer2.

This is one of those cases where measurement does not affect the readings in any meaningful way if you use something like a logic analyzer.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 23
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks mem - that's a help.

Appreciated.

J
Logged

Pages: [1]   Go Up
Jump to: