Jump to content

How to exit from switch statement when condition is met first time


Recommended Posts

Hi there,

I am trying to implement a blood pressure (BP) monitor in Labview using NI 9239 and NI 9263.

At this time, all I want is that the motor (pump) runs until a user-specified pressure is reached in the cuff. When that pressure is reached, the motor should stop but not the Labview program. As the cuff is deflating slowly through a pressure leakage valve, I want to record the pulses during cuff deflation.

I used a switch statement. Gave it input from a comparator which compares the real-time pressure with user-set pressure. I put the DAQ Assistant inside this switch. I said to NI 9263, keep supplying my motor relay with rated voltage until the pressure is lower than the user-specified pressure. When this pressure exceed the user-specified pressure, I set the DAQ Assistant voltage to relay as zero, since I want the motor to stop.

The above is OK. But when the cuff starts to deflate, again, the pressure becomes lower than the reference (user-defined) pressure. As a result the switch statement switches again and sends voltage to relay to run the motor again.

I want something which can start off my supplying the relay with rated voltage to run the motor. As soon as real-time pressure exceeds user-defined pressure for the 1st time, I want the relay voltage to be set to zero, being unaffected by the fact that during cuff deflation, the real-time pressure will fall again below the reference pressure. I don't want the motor to run after it has pumped to a desired pressure, the first time.

Thanks a lot!

Saif

post-27603-0-92104600-1345168901_thumb.j

post-27603-0-89444000-1345168905_thumb.j

Link to comment

Hi Shaun and Asbo,

Thank you for your replies!

I tried what Shaun suggested. Please see pictures.

The Boolean cross-over is detected and the motor stops momentarily. But then turns back on. Sorry but I am still a bit new to Labview.

How do I utilize that cross-over trigger to keep it off for the rest of the recording?

Thanks again!

Saif

post-27603-0-77783600-1345184582_thumb.j

post-27603-0-97819500-1345184586_thumb.j

Link to comment
There are several ways. For example, you can use this VI to detect the "direction" of your boolean change.

Thank you I didn't know this VI existed I've always been using the OpenG Boolean Trigger VI, which seems to have a better name, and icon, for the function it performs, but I would rather use a NI VI than an OpenG VI if their functions are the same.

Link to comment

Hi Shaun and Asbo,

Thank you for your replies!

I tried what Shaun suggested. Please see pictures.

The Boolean cross-over is detected and the motor stops momentarily. But then turns back on. Sorry but I am still a bit new to Labview.

How do I utilize that cross-over trigger to keep it off for the rest of the recording?

Thanks again!

Saif

The output will be "TRUE" if the direction is detected. It looks like your case structure is set to "False" to turn off. Try swapping the cases around.

It is usually better to post your VI or an example of what you are trying to achieve rather than an image. For simple VIs you sometimes get back the VI with the changes.

Thank you I didn't know this VI existed I've always been using the OpenG Boolean Trigger VI, which seems to have a better name, and icon, for the function it performs, but I would rather use a NI VI than an OpenG VI if their functions are the same.

There is a lot of replication in the openG VIs, presumably for completeness. Not using the openG stuff forces me to look in some of the more obscure palettes.

Link to comment

Hi Shaun,

Thank you so much for your response!

I think I tried what you suggested. But it seems to only work with what I have. Do you mean change the initialization pin to TRUE? When I do that, nothing happens.

I am attaching the VI now. I would be very grateful If you could please advise what I might be doing wrong!

Cheers,

Saif

Ex_7a.vi

Link to comment

Hi Shaun and Asbo,

Thanks so much for your responses.

Shaun, the VI you uploaded works just fine! I used help commands to understand it. The feedback loop combined with AND and OR gate to achieve "latching" is a great idea! Also, the use of selector function for sending command to the motor is simple and straightforward.

Can I please ask another question? Suppose a USER hits the stop button during cuff inflation (motor ON). At that point I would like the motor to stop. The program does EXIT, which is fine. But if the motor could also stop, that would be great!

Hope this is possible :)

Thanks again for all your help!

Saif

Link to comment

Suppose a USER hits the stop button during cuff inflation (motor ON). At that point I would like the motor to stop. The program does EXIT, which is fine. But if the motor could also stop, that would be great!

Just put another motor stop (set the motor value to zero) outside the while loop so that it gets executed after the while loop stops. I'll leave you to figure out how to sequence it to make sure it happens after the loop stops rather than while the loop is running (hint, don't use sequence frames, ever!)

Link to comment

Hi Shaun,

Thank you so much for all your guidance!

What I did was that I wired the STOP button to the motor voltage module (inside a SWITCH statement) that I kept outside the WHILE loop. So, when STOP is true, I send zero voltage to the motor. This EXITS the program as well as STOPS the motor.

Please see attached VI.

I have two questions:

1. Is this a smart way of doing it?

2. This does not work if the user hits the ABORT button instead of STOP button! So, I went into File --> VI Properties and made the ABORT button invisible when the VI runs. In this situation, the user can only see my STOP button and is forced to use that to exit. Is is this OK?

Thanks again!

Saif

Ex_7b.vi

Link to comment

What I did was that I wired the STOP button to the motor voltage module (inside a SWITCH statement) that I kept outside the WHILE loop. So, when STOP is true, I send zero voltage to the motor. This EXITS the program as well as STOPS the motor.

If it works. It's good.

1. Is this a smart way of doing it?

There are many ways of doing things and whilst there are "accepted" solutions to common problems; "Smart" is subjective. Your only objective was to "sequence" the drive shutdown since LabVIEW is inherently parallel, and there are a lot of ways you could have achieved that.

For example. In addition to your solution, you could also have wired the error terminals on the express VIs to outside the loop (a very common way of sequencing VIs). or for that matter, the 0. You could also have OR'd the STOP boolean to the selector. Worry about "smart" when you know where all the things are in the palettes, you've got a few utilities in your toolbox, written a few programs and been on some courses.

This program is the "first pass" (your prototype, if you like). I can guarantee you will be revisiting it making it "smarter", prettier or more flexible.

2. This does not work if the user hits the ABORT button instead of STOP button! So, I went into File --> VI Properties and made the ABORT button invisible when the VI runs. In this situation, the user can only see my STOP button and is forced to use that to exit. Is is this OK?

The stop button in the IDE is for the developer only. In deployed applications, users should not have access to it since it circumvents shutdown procedures by stopping the code dead. Never give the user any opportunity to do something you are not expecting otherwise he/she will!

Edited by ShaunR
  • Like 1
Link to comment

2. This does not work if the user hits the ABORT button instead of STOP button! So, I went into File --> VI Properties and made the ABORT button invisible when the VI runs. In this situation, the user can only see my STOP button and is forced to use that to exit. Is is this OK?

Consider the abort button as a synonym to using a concrete wall to stop your car with. It works but can have undesirable effects! :D

  • Like 1
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.