LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do you pass values between case structures?

Hi,

 

I have a simple vi where I am measuring voltage in a WHILE LOOP. The WHILE LOOP contains 2 case structures.  Under some measured voltages,  case 1 or case 2 will execute, and under some other voltages, neither case will execute, and the WHILE LOOP simply iterates again. 

 

Case 1 and Case 2 both issue commands that are calculated using both the measured voltage and the PREVIOUS command value, using a very simple addition/subtraction sequence.  Case 1 and Case 2 are likely to execute many times before the voltage changes enough to pass into the "in between" range.  Each time either case executes, a new command is issued.  Each new command is a modification of the previous command by the addition/subtraction process.

 

The two cases refer to an upper threshold and a lower threshold.voltage value.  There is also a voltage range in between the lower and upper threshold values where we do not issue any commands.  Commands are issued only when Case 1 (voltage<lower threshold) or Case 2 (voltage>upper threshold) is TRUE.

 

In the case structures, the measured voltage is used to calculate a command value by adding or subtracting to the previously calculated command, where either Case 1 or Case 2 are TRUE.  The case structures do NOT use any of the voltage values measured in the "in between" range. 

 

Suppose that Case 1 is executing and sending commands properly, and then, the voltage value changes to the in-between range and continues to the Case 2 range.  What I want is for the Case 2 to use the last command issued by Case 1 for the Addition/Subtraction.  Recall that many voltage values are likely to be measured in the "in between" range and none of these will result in issued commands.  How do I capture the last command from Case 1.  Of course, I want to go both directions.  A total of four differen sequences are possible:

 

Case 1--> In between --> Case 2

and

Case 2 -->In between --> Case 1

and

Case 1 -->In between --> Case 1

and

Case 2 -->In between --> Case 2

 

How do I capture that last command issued, and store it until either case becomes TRUE again, and then make the case use this command?  I don't think that a shift register will work because the "in between" range will change the value in the shift register, and I don't see how to implement a shift register with a Case structures.  Will the feedback function work for this?

 

Thanks for your thoughts.

Dave

0 Kudos
Message 1 of 4
(7,126 Views)

This sounds like a pretty good candidate for a state machine.

 

Looks like an Acquire State which can transition to Command 1, Command 2 or back to Acquire.

 

A single shift register to hold Previous Value.

 

In your Acquire state, simply wire through your Previous Value back to the shift register without updating it.

0 Kudos
Message 2 of 4
(7,124 Views)

Take a look at my Action Engine Nugget here.

 

It exaplins what they are and their benefits and how they can be used to share data between threads.

 

Ben

 

 

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

Action Engines probably are a good idea.

 

I think the state machine in the attached vi should also be sufficient.

0 Kudos
Message 4 of 4
(7,112 Views)