LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

stop while loop with local variable

Hallo,

 

when the while loop will be started when the SP=PV is true. and the iteration will be started. the time elapsed will be compared with the time(s).when the time elapsed is greater than the time(s), the while loop will be stopped. but for my case, that signal does not stop my while loop. can anyone tell me why?

thanks 

0 Kudos
Message 1 of 6
(4,008 Views)

fmpfmpf wrote:

Hallo,

 

when the while loop will be started when the SP=PV is true. and the iteration will be started. the time elapsed will be compared with the time(s).when the time elapsed is greater than the time(s), the while loop will be stopped. but for my case, that signal does not stop my while loop. can anyone tell me why?

thanks 


THe only time I ever saw an exact compare of real world number ever work is when I was looking for zero and the hardware was broke... giving me zeros.

 

Check for a range and not an exact match.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 2 of 6
(3,997 Views)

Hey,

 

I can't open your VI as I have 8.5 ... but based on ur words and already suggestion given by Ben on SP=PV .. I m just suggesting to use while loop with elapsed timed express VI and connect this boolen to while loop stop control like below.. If you can post the screenshot of while loop control logic.. i can try some to find something..

elapsetime.JPG

0 Kudos
Message 3 of 6
(3,979 Views)

"In Range" (found on the compare palette) returns aboolean indicating in or out of range.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 4 of 6
(3,972 Views)

Your inner loop condition is set to continue while true.  If SP=PV, the loop will start and it will continue without stopping.  Even if SP and PV become not equal, the timed loop has already been executed and will not update the boolean output.  This is because the inner loop has not stopped.  The inner loop must stop before the outer loop can go to the next iteration, which will trigger the timed loop to update the SV=PV boolean.  So your program will hang up every time.  You need to change your architecture.  Perhaps parallel processes where one loop just runs the timed loop, and the other loop being the inner loop.  You would need to send the SP=PV boolean from one loop to the other by using a notifier.  You cannot have wires between the two loops because the process will become serial instead of parallel.

 

Also, you are using a local variable to stop the outer loop.  There is a possible race condition here.  Does the local get read before the inner loop starts, or after?  No way of knowing.  Use a wire from x>=y indicator to the stop sign.  This way, the inner loop must execute before the outer loop gets the boolean data.

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 5 of 6
(3,960 Views)

Hi fmpfmpf,

 

You need to think dataflow as there are some race conditions in your code which will probably prevent it working as intended.

 

Your *inner* while loop (the one attached to the end of the timed structure) will start after timed structure has run. It will be passed the value of SP=PV an the time that the comparison was made. Therfore depending on the result at the one time that the comparison has run (as shown on the SP=PV lamp) the loop will run either once or forever as the continue if true test will get the SAME value every time.

 

The for loop (with the text array of opc:// at its left hand side can run at the same time as the timed structure as there is no data dependancy between them. When the for loop finishes, you will set TIC_SP and TIC_PV, but as this is asynchronous with the point at which you READ them you have no way of telling wheteher your comparisons are done before or after the indicators are set. Thus you have no way to tell what values are going to be used in your SP=PV comparison

 

Now while the INNER while loop is running, the outer while loop may already have read the local variable of the test x>=y, but this may be before you have made the comparison and set the indicator, so you don't know what the end condition of the outer while loop will be seeing. Remember that the inner loop MAY be infinite, so you may never get the termination condition of the outer loop to have any effect at all.

 

All the uses of "may" in my description are due to race conditions. Eliminate those and you will go a long way towards making the code behave as you want. You will also need to attend to the termination condition of the inner while loop. Recall that at present when the while loop starts, the end condition boolean is the same value every time (the value at the output of the timed structure) BTW, why are you using a timed structure here?

 

Rod.

 

 

 

 

0 Kudos
Message 6 of 6
(3,950 Views)