LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How long can a while loop run?

I'm using Labview 7 and wonder how long a while loop can run, i.e. up to which size does the i- variable increment until it gets set back to zero?
What I want to do is set a boolean true whenever the while loop has executed ten times. How should I do this? Should I just wire the i - count to a modulo 10 operator? Will this slow down the process if the value of i gets very large, let's say over a million or so. Is there a way how to reset the i- count back to zero whilst the while loop is running?

Thanks a bunch

Georg
0 Kudos
Message 1 of 11
(4,057 Views)
The iteration terminal is an I32 so when it reaches 2,147,483,647 it will wrap back to zero. You are correct that using modulo 10 (Quotient & Remainder function) will indicate every tenth run. I have never noticed any slowing down of the process. Integer math is pretty effecient. There is no way to reset the iteration count except stopping the while loop.
Message 2 of 11
(4,057 Views)
Adding to Dennis...

You can use a shift register instead of the i terminal. The shift register can be reset when required.

RE how long can a while loop run?
FYI: I have a cFP2010 on my desk that has been running a while loop for 7 months.

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 3 of 11
(4,057 Views)
OK thanks for your answers.
Two questions:

- Where can I find the modulo function on the control box?

- How can I reset the running count of a shift register?

If anybody of your guys have a sample vi handy, I'd be grateful!

Cheerio,

Georg
0 Kudos
Message 4 of 11
(4,057 Views)
If you need to count higher than the capacity of an I32, the shift register is the way to go since it can utilize other data types, e.g. DBL can reliably count quite a bit higher (52 bit mantissa). You could even utilise arbitrary precision arithmetic by representing the counter as an array of numbers. (see e.g. the factorials challenge (Results) which required integers with tens of thousands of exact digits).

Attached is an image that uses a DBL for the loop counters. There is also a way to reset the counter via a latched boolean button.

The quotient&reminder is in the numeric palette (near the upper right corner.
Wiret the loop count to x, a constant n to y and the "remainder" terminal to a case structure. The default case should be empty and the case "0" should contain the code that should execute every n'th iteration.
0 Kudos
Message 5 of 11
(4,057 Views)
As I mentioned, you use Quotient & Remainder for modulo moth. Here's an example that shows this and how to use a shift register with reset.
0 Kudos
Message 6 of 11
(4,057 Views)
Actually the iteration count does not wrap to zero: it stops at 2147483647. So the solution for higher counts is to implement a counter with a shift register. See Altenbach's solution.


LabVIEW, C'est LabVIEW

0 Kudos
Message 7 of 11
(4,057 Views)
Here's a simple example of code that executes every 10th iteration only.
0 Kudos
Message 8 of 11
(3,843 Views)
That really helped me out, thanks a lot!


Cheerio
0 Kudos
Message 9 of 11
(4,057 Views)
I guess I've never run a while loop for such an extended period of time. Thanks for correcting me.
0 Kudos
Message 10 of 11
(4,057 Views)