From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

While loop Interation counter

I was doing some system performance testing using LabVIEW and noticed that the while loop iteration counter counts up to 2147483647 and stops. I understand that that is the i32 limit, but that seems like a problem for software that needs to run forever. Depending on the speed of your loop you can run into that limit quickly, at which point the built in iteration counter is useless.

 

Anyone run into this? I can think of RT code that I've written in years past that likely died for this reason after a few months and started back up when I rebooted and ran fine for a few months before it did the same thing. Curious what people's thoughts are.

0 Kudos
Message 1 of 8
(1,851 Views)

Hi AMyth,

 

use a shift register and create your own counter, using an U64...

 

This "problem" is even more prominent on FPGA, with loop rates at 40MHz or more.

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 8
(1,838 Views)

Gerd is correct, of course. The question is why your code even depends on [i] if it should run and thus grow forever?

Message 3 of 8
(1,808 Views)

@AMyth wrote:

Depending on the speed of your loop you can run into that limit quickly, at which point the built in iteration counter is useless.


That's why you can hide the Iteration Terminal in >LV20 😁.

 


@AMyth wrote:

Anyone run into this?


Sure, 21 years ago.

 

If you program long enough you'll run into this, make a palm face, and hopefully remember it...

 

I'm sure everyone programming an FPGA for the first time makes this mistake at least once.

 

Note the huge difference between an U64 and an I32 on an FPGA. It won't run forever, but even at 25 ns iterations, it will last long enough.

0 Kudos
Message 4 of 8
(1,760 Views)

Well now I know better :). I just assumed that "i" would roll over when ti reached a limit. But it stops! That's what was shocking.

0 Kudos
Message 5 of 8
(1,717 Views)

@AMyth wrote:

Well now I know better :). I just assumed that "i" would roll over when ti reached a limit. But it stops! That's what was shocking.


I would be even more shocked if it would roll over and output negative values starting with -2147483648! 😄

 

(It really depends on the use case. For example if you just want to distinguish odd vs even iterations, a rollover would be preferable, but there are probably better alternatives. 🙂 )

0 Kudos
Message 6 of 8
(1,716 Views)

Of course it depends on what you are doing with it. I think I assumed behavior without testing and that's my fault. I now know better and will have to go check all my long running code and ensure it's not dependent on "i".

0 Kudos
Message 7 of 8
(1,704 Views)

This one takes about 4 seconds on my rig (And 1-2 seconds longer with debugging enabled). 😄

 

altenbach_0-1639168393627.png

 

Message 8 of 8
(1,699 Views)