09-26-2017 08:56 AM
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!
09-26-2017 09:03 AM
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..
09-26-2017 09:10 AM - edited 09-26-2017 09:39 AM
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.
09-26-2017 09:52 AM - edited 09-26-2017 09:52 AM
If you wire something from A to B then A will always execute before B.
/Y
09-26-2017 10:14 AM - edited 09-26-2017 10:14 AM
@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?
09-26-2017 10:23 AM
@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?
09-26-2017 10:25 AM - edited 09-26-2017 10:25 AM
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.
09-26-2017
10:33 AM
- last edited on
05-13-2025
01:47 PM
by
Content Cleaner
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.
09-26-2017 10:55 AM
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.
09-26-2017 12:45 PM - edited 09-26-2017 12:46 PM
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".