LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

for-loops that inherit the number of iterations from previous for-loops.

I am a newbie to Labview, and am trying to generate a hysteresis curve, that generates current that goes from 0 to +5, then down to -5, then all the way back up to +5 before returning back down to 0. Let's assume the current increments in steps of 1A.
 
 
So, I have a flat sequence structure, containing 4 boxes, and within each I have one 'for' loop, one for each part of my curve. Each for loop needs to have a different number of iterations, let;s say, 5, 10, 10, and 5.
 
But when I run this sequence, the first two always have 5 iterations (ie the same as the first for loop), the second 2 (usually) have 10 (ie the same as the 3rd for loop). Sometimes, they ALL will have 5 iterations! I have checked by wiring controls directly to N but this seems to have no effect on the number of iterations the loop will perform. The usual re-starting the computer and hardware doesn't work either 😞
 
I suppose it's possible to have 6 for-loops each with 5 iterations but this is not very elegant and I'm sure there is something wrong or that needs tweaking.
 
Sorry about the long explanation and lack of VIs but they are all hooked up to hardware and on another computer. Sigh.
 
Any help or just a pointer to documentation that would help would be greatly appreciated.
0 Kudos
Message 1 of 4
(2,354 Views)


@~Sophie~ wrote:
IBut when I run this sequence, the first two always have 5 iterations (ie the same as the first for loop), the second 2 (usually) have 10 (ie the same as the 3rd for loop). Sometimes, they ALL will have 5 iterations! I have checked by wiring controls directly to N but this seems to have no effect on the number of iterations the loop will perform. The usual re-starting the computer and hardware doesn't work either 😞


You should show us your code. Most likely, you have an autoindexing array going into the FOR loops. The numer of iterations is the smallest number of whaever you wire to the N terminal and the array size of the smallest autoindexing array entering the FOR loop. For example if you autoindex an array of size 2, the loop will spin only twice, even if you wire a million to N. 🙂

Message 2 of 4
(2,340 Views)
Sophie,

It is hard to tell what your problem is without seeing the code.

Some suggestions.

One loop is sufficient to do what you want. Just create an array with the pattern (0 1 2 3 4 5 4 3 2 1 0 -1 -2 -3 -4 -5 -4 -3 -2 -1 0) and feed that to the loop.

The sequence structure is almost certainly not needed. Use dataflow. A state machine might be useful also.

If you are feeding arrays to the loops with autoindexing, that might explain your iteration count variations. An autoindexed loop will stop when last element of the smallest arry is reached or when the value wired to N, which ever is less.

Lynn
Message 3 of 4
(2,341 Views)
Thanks guys!

Auto-indexing seems to be the culprit. Also, I'll try re-working my code into a more compact form using arrays 🙂

Thank you again

Sophie
0 Kudos
Message 4 of 4
(2,304 Views)