09-11-2013 01:30 AM
Hello everyone!
Is there a certain way you program to make labview execute ALL commands within a loop before going into another loop? For example, I have a while loop that stops if either the stop button is pushed or if the set point input is greater than 8. If both of these are false, then the code entered a case structure where it controls the output from a plant model. However, labview will enter the case structure without checking if both conditions are met. I've attached the VI and in the next message will post the VIs from the plant. I want it to do the below code,
IF (Set Point > 8 OR Set Point < 0) THEN
SET_Point OK= False
ELSe
SET_Point OK = True
END IF
IF (SET_Point OK = FALSE OR Stop Button pushed) THEN
! STOP VI
ELSE
! Enter PID Control Loop
END IF
But labview likes to just jump around and skip parts for some reason. So when it for example, skips the OR check it uses the default value of true for the next case structure. It's driving me crazy. Can anyone please tell me why its doing this??
Thanks.
Solved! Go to Solution.
09-11-2013 01:30 AM
Here's the other VIs.
09-11-2013 01:34 AM
Here's a picture of what its skipping.
09-11-2013 01:45 AM
@andrewjoe777 wrote:
Here's a picture of what its skipping.
LV doesn't skip anything. If it's only sending True to the case structure, then your global is True all the time.
/Y
09-11-2013 01:53 AM - edited 09-11-2013 01:55 AM
@andrewjoe777 wrote:
But labview likes to just jump around and skip parts for some reason. So when it for example, skips the OR check it uses the default value of true for the next case structure. It's driving me crazy. Can anyone please tell me why its doing this??
LabVIEW does exactly what you ask it to do. Since you do a logical OR, the output depends on the "set point OK global" as well as the negated stop button value. Since stop is false, NOT.Stop is true and the output of the OR function is also true, independent of the global.
You should really simplify your code. Do you really need a global variable to send a value to the next sequence frame? Just use a wire. Same for the set point global. Why do you need a global in both cases?
You should simplify your logic. Call the boolean "Set point error", use "stop if true" on the loop condition, and switch the two cases. Also look into the "in range and coerce" function
09-11-2013 02:02 AM
The vi code does not implement your pseudocode: as you negated both conditions about SET_POINT and STOP, you must use an AND instead of an OR.
Otherwise, as long as you don't click STOP (not STOP = true), the OR result will be TRUE.
09-11-2013 02:17 AM
Ah! I can't believe I made that dumb of a mistake. And thanks for the advice altenbach. My overcomplicated diagram probably lead me to making that error.
I have another question though. How come when I use the Write to measurement file VI it will start the process variable at like 40 inches but when I don't use it, it'll start it at 0 and do as its supposed to? I've attached my updated VI with the write to measurement file VI in it. You'll see that if you delete it then it'll do as its supposed to. I don't understand why though..
09-11-2013 02:18 AM
Here's the VIs for the plant. They didn't change though.
09-11-2013 02:22 AM - edited 09-11-2013 02:25 AM
Here;s a picture of it giving the wrong initialization when using the write to measurement VI as well the a picture of it giving the right initialization when NOT using write to measurement VI.
09-11-2013 02:30 AM
I cant open your code, but it sounds like a race condition, especially as writing takes time. That's a common problem when using local variables instead of wires.
/Y