LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Parallel Case Statement Priorities

Lets say I have 2 case statements inside of a while loop. Is there a way to make one of the case statements a higher priority? For example, both statements A and B (see pic below) modify the same data. Statement B will run more often, but I want it so that if statement A is triggered to execute then it will execute immediately and pull out of statement B even if it hasn't finished. Currently, I'm running into an issue where statement A is triggered to execute but it doesn't always execute because the program is currently in statement B. Thanks!

 

LabVIEW.PNG

0 Kudos
Message 1 of 13
(4,427 Views)

Can you explain what you mean by "pull out of statement B"?

 

What do you mean by "higher priority"?

 

I think you might not have fully grasped the concept of data flow.  Look at the LabVIEW tutorials.

A piece of code will execute whenever all of its inputs have data.  A structure (such as a case structure) will not finish and release data on its outputs until all of the code inside of it has finished.  If a section of code has no dependency on another section of code, they can run in parallel, or one can execute before the other based on how the CPU schedules it.  If you need to have code execute after another, then you need to guarantee a data dependency either by a wire or by using a structure like a flat sequence structure..

0 Kudos
Message 2 of 13
(4,418 Views)

The way I have it setup is that statement A provides my desired current value while statement B does the calibration on the desired current value to adjust the input current up/down a bit in order to get closer to the desired current. I have statement B executing every 200ms (ideally I would like to make this even faster). As a result, there are times where I will change the desired current but the change will not be reflected since the calibration value will still be done on the previous old value. Therefore the current output will be wrong as the desired current was never updated. By priority, I want to make it so that if the desired current changes, than statement B will use this new value rather than proceed with the older one.

 

Edit: I believe I have solved the issue my adding some boolean logic for additional checking.

 

0 Kudos
Message 3 of 13
(4,408 Views)

If you wire something from A to B then A will always execute before B.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 4 of 13
(4,376 Views)

@riahim wrote:

The way I have it setup is that statement A provides my desired current value while statement B does the calibration on the desired current value to adjust the input current up/down a bit in order to get closer to the desired current. I have statement B executing every 200ms (ideally I would like to make this even faster). As a result, there are times where I will change the desired current but the change will not be reflected since the calibration value will still be done on the previous old value. Therefore the current output will be wrong as the desired current was never updated. By priority, I want to make it so that if the desired current changes, than statement B will use this new value rather than proceed with the older one. 


You really need to be more specific describing the problem. If you say that B executes every 200ms, you should also say how often A is running and how often the outer loop spins (If A and B would run at the loop rate, they would not need a case structure, right).

 

From reading between the lines, we are talking about a feedback control mechanism where B is used to bring A int the desired range. What does "calibration" actually involve? Is it mathematically really that expensive that you need to limit how often in runs? Why can't you simply implement something along the lines of PID? What is the overall loop rate?

 

Can you shows us more details on what you are actually doing, e.g. attach some code?

0 Kudos
Message 5 of 13
(4,363 Views)

@riahim wrote:

The way I have it setup is that statement A provides my desired current value while statement B does the calibration on the desired current value to adjust the input current up/down a bit in order to get closer to the desired current. I have statement B executing every 200ms (ideally I would like to make this even faster). As a result, there are times where I will change the desired current but the change will not be reflected since the calibration value will still be done on the previous old value. Therefore the current output will be wrong as the desired current was never updated. By priority, I want to make it so that if the desired current changes, than statement B will use this new value rather than proceed with the older one.

 

Edit: I believe I have solved the issue my adding some boolean logic for additional checking.

 


I don't think you have fully defined your code enough enough.  You have a single loop.  In that you have two case structures, but haven't defined what are the conditions that drive them.  Are there any other loops that exist inside of either case structure?

0 Kudos
Message 6 of 13
(4,356 Views)

riahim wrote:

Edit: I believe I have solved the issue my adding some boolean logic for additional checking.


All you need to do is pass the desired current from A to B.  Then you have a data dependency and B will use the latest value that comes out of A.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 13
(4,351 Views)

I'm a little loathe to suggest something that might only complicate matters, but it looks to me as though you have some iterative process occurring in B and want to cancel that process if the value from A changes (and presumably restart B).

 

If that's the case, you might consider a State Machine with an Idle/Checkup case containing an Event Structure with a zero timeout. By cycling through the Event case, you can check if A has changed but then go right back into tuning B via the timeout case of the EvStr. 

 

The Event Structure also then makes it easier to add additional buttons, for example to pause or stop the loop and so on.


GCentral
0 Kudos
Message 8 of 13
(4,341 Views)

Thank you everyone for the help! I believe that I have solved the issue. Using a state machine would probably have been more efficient/easier if I has stared down this route, but unfortunately would require changing my entire program. Currently I have a work around that works well, but I think crossrulz solution would also work.

0 Kudos
Message 9 of 13
(4,331 Views)

Unless this is some kind of homework assignment where you'll never look at it again after this, you probably should read up on the tutorials, ask questions and take some advice to make it the best it can be.  The more uses you find for it, the more important it will be to code properly and with "best LabVIEW practices".

 

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 10 of 13
(4,310 Views)