LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

indexing a loop

Can anybody explain why the i value in for or while loop might increment by 2 instead of one?
Thanks.
0 Kudos
Message 1 of 21
(3,713 Views)
It shouldn't be.  How are you reading it?  With an indicator?  Writing it to a file?  Any case structures that might prevent the display of the data for an iteration?  Just thinking that you missed seeing it one way or another.
0 Kudos
Message 2 of 21
(3,707 Views)

Displays are asynchronous, so if your loops spin very fast, the indicator will not update at every iteration.

If you think something is still wrong, please attach an example that shows the problem.

0 Kudos
Message 3 of 21
(3,704 Views)
I'll have to send the code later tonight or tomorrow but it's very strange. The time between each iteration is long: on the order of seconds. When I print out i, it goes from 0 to 2; when i changes the third row of an array is read; the second row is never processed; the first is when the loop starts. It doesn't matter whether I use a for loop or a while loop. N is set by the array size. I've had a another knowledgeable LV programmer look at and we're stumped.
0 Kudos
Message 4 of 21
(3,698 Views)
Something similar to this was happening to me earlier this week. I narrowed it down to an easy-to-miss race condition. See attached for a rough example of what you may be encountering.

Hope this helps!
0 Kudos
Message 5 of 21
(3,678 Views)
Here's the section of the code that's not working as well as the whole code. The whole code goes prime time next week and you and many of the ni regulars are to be thanked again for your help.

We did manage to get the loop working by adding a long delay but I still don't understand.
Download All
0 Kudos
Message 6 of 21
(3,637 Views)
have you placed a breakpoint on the index wire and analyzed step by step? This would most likely uncover your issue, as index cannot possibly skip numbers.
0 Kudos
Message 7 of 21
(3,630 Views)
No, I'll try it.
0 Kudos
Message 8 of 21
(3,626 Views)
Way too many local variables and a lot of unused terminals.  If you have an unused terminal (and you have several scattered miles away on the block diagram), you could be using that in place of one of the local variables.
 
You have a huge problem in the attached screen shot.
 
You have a while loop that runs extremely fast as long as "Finished Set" is false.  It is only set to false up higher outside the while loop.  How does it ever get set to True to stop the while loop?
0 Kudos
Message 9 of 21
(3,623 Views)
After a night of taking images, the loop tells the taking image routine to take several sets of "dark images". "Finished set" goes true after each set is finished.

Regarding the unused terminals. They are mostly clustered in the initialization sequence. Local variables are then used to to avoid a mass of wires.
Should I put up with a mass of wires in order to get the code to run faster and more reliably?

Thanks
0 Kudos
Message 10 of 21
(3,616 Views)