LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using a case statement within sequence structure

I have a simple 3 step sequence structure. Steps 1 and 3 are basically set periods of time for waiting (with no other functionality) -- during the second step of my sequence I have used a case statement (simple T or F, each case timed for a certain user set period of time). During the true or false cases LabVIEW outputs a set voltage for a set period of time, which I am using to control a power supply. Problem is, once the case begins, if I can the boolean to false, then the case does not change immediately but remains the same until the timer expires, and on the next execution of the for loop (this is all inside a for loop) the case changes accordingly as I previously indicated. I want to be able to change between cas
es (which are timed) immediately -- is this possible?

Thanks a ton, I a new to LabVIEW,
Travis
0 Kudos
Message 1 of 12
(4,073 Views)
So when you change a selector (on the front panel?) are wanting to be able to essentially bail-out on the time period set in the old case and go right to the other case. Yes?

One basic way of accomplishing this task is to use lots of smaller output updates rather than one long one. For example, you update the output every 100 msec for 1000 updates and you effectively have a 1 second period that you can bail-out of within 100msec.

Hope this helps...

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 2 of 12
(4,073 Views)
Hi Travis,

Welcome to the world of virtual wires.

Going with the theory of "teach a man to fish and he will never go hungry" I would like to suggest the following.

Go to the diagram of your VI and set the diagram for "execution highlighting" (i.e. click on the light bulb).

Then run your VI.

What I want you to watch for is WHEN DOES LV read the boolean?

Let us know if you still need help after this experiment.

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 3 of 12
(4,073 Views)
I got the boolean working how I would like yesterday. However, I am still running in to trouble breaking out of a timed case statement. Can I change the update rate some how so that boolean that selects the case overpowers my timer within my case.

Thanks,
Travis
0 Kudos
Message 4 of 12
(4,073 Views)
I think that if you had done as Ben suggested, you would see that with your present architecture, you can't accomplish what you want. You can't break out of a case statement. Once inside the case statement, whatever is inside there will have to finish first. Then you will always go to the next frame of the sequences structure and only when all sequences are done, will the Boolean be read by LabVIEW again. You're going to have to rewrite your program to do what you want and the first thing to go will be the sequence structure. Replace it with a state machine or try the event structure.
0 Kudos
Message 5 of 12
(4,073 Views)
If I understand your problem correctly, I would suggest using a for loop to control the timing of your output. That way could could have your set time limit and constant updates of the boolean state. In other words, instead of having a set period of time in the case structure, you would just have the value that you would like to output set inside the case. As the for loop iterates, it would check to see if the proper amount of time has elapsed and it would check the boolean (assuming its INSIDE the for loop as well). If you change the boolean state, then it will be recognized almost immediately, instead of having to wait for a time limit to expire.

Regards,

Steve.
0 Kudos
Message 6 of 12
(3,852 Views)
From my understanding a state machine is based on a case statement -- so regardless of whether or not I redesign, aren't I still left with the same problem of breaking a timed event in the middle of its execution? A state machine will leave me with the same problem. Is there a way to override a timed event? If not, could I feed the timer into some type of OR to some type of a stop, so that the case stops at the full count of the timer or when I specify (utilizing the OR).

Thanks,
Travis
0 Kudos
Message 7 of 12
(4,073 Views)
A state machine would work if you didn't have a fixed delay (i.e. Wait (ms)) for had a first a state that applied your voltage, would compare current time to start time, if time limit hasn't elapsed, check for user input, go back to the time check if no user input, if user input then change the time limit, go to check the elapsed time, and finally when elapsed time is equal or greater to the limit then run ooff the voltage. It's pretty hard to do a state diagram without pictures (at least for me), but I hope you get the idea. You can't override the fixed waits in LabVIEW nor can you override the sequence structure. The only way to over ride a delay is use some kind of mechanism where before you start, you get the start tim
e and then you get current time and subtract from it the start time.
0 Kudos
Message 8 of 12
(4,073 Views)
I try to create the vi to that of what you have described... hope this will help.

regards
ian
Ian F
Since LabVIEW 5.1... 7.1.1... 2009, 2010, 2014
依恩与LabVIEW
LVVILIB.blogspot.com
0 Kudos
Message 9 of 12
(3,852 Views)
I kind of went on a rant about state machines and I want to apologize for that. The point I was trying to make is that with a Boolean outside a case structure, LabVIEW will not read the boolean again until what is inside the case structure completes. Do away with the case and use a while loop that compares elapsed time to a start time and have your time selector inside the while loop so that for every iteration, the Boolean state is read. I think someone else posted an example using a for loop but I would use a while loop.
0 Kudos
Message 10 of 12
(4,073 Views)