LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Immediate Stop of 5 While loops

Hi,

 

The objective of this code that I wrote is to operate 5 heaters. I want to turn them on and off in specific order and timings. I turn them on by sending an analog output current to them and I turn them off by sending a 0 A current. When I press stop, I want all of them to receive a 0A current and stop working.
The problem is that with the code that I have at the moment, pressing Stop does not stop the loops immediately and they still go through a flat sequence before stopping. How can I make the stop button to send a zero current signal and shut down the program instantly?

0 Kudos
Message 1 of 6
(3,632 Views)

Hello Exergy,

Unfortunately the flat sequence structure does not have any method to abort execution in the middle. However you could implement this using a state machine implementation that would allow you to stop execution at any state transition.

 

This white paper from NI may help if you are unfamiliar with state machines in LabVIEW

http://www.ni.com/white-paper/3024/en/

 

MikeR2

0 Kudos
Message 2 of 6
(3,617 Views)

Hi Exergy,

 

The problem you are encountering is that you actually cannot stop a flat sequence structure from executing in its entirety once it has started. This is part of the definition of a fss and does not have a workaround.

 

For your application, I would recommend taking a look at the State Machine Architecture, which will allow you to stop all heaters simultaneously whenever the stop button is pressed. Used correctly, this architecture will also enhance your code's readability, scalability, and maintainability.

 

A couple of other notes about the code you have posted:

You are creating a new DAQ Assistant task every time you would like to write to the heater controller. This is going to make your code run much slower than it otherwise would and is unnecessary. A better design would be to have a setup stage in which you create all of your DAQ tasks, followed by a while loop that performs the appropriate reads/writes, followed by a tear-down stage in which you clean up all of your DAQ tasks. I would recommend taking a look at using the DAQmx API to have multiple writes to the same channel. DAQmx also offers more control over your DAQ tasks than the DAQ Assistant.

Generally, I wouldn't recommend using flat sequence structures unless you have a good reason to do so. It is better practice to enforce program execution using data flow dependencies as these are easier to read, debug, and are much more malleable.

 

Based on the code you have posted, I would also recommend checking out some of the training resources made available by NI:

LabVIEW Core 1

LabVIEW Core 2

The NI KnowledgeBase

The NI Example Finder in LabVIEW can also be very helpful as you are learning to use common LabVIEW design architectures.

 

While you may be able to develop code that somewhat works using your current design, I would highly recommend checking out the resources in this post and redesigning your code once you are more familiar with some of these topics. There is a much better way (state machine/DAQmx) to do what you are trying to do here.

 

If you have any additional questions about this issue, feel free to follow-up in this thread!

 

Best,

 

Duncan W.

Message 3 of 6
(3,602 Views)

By definition, a sequence structure must run all the way through before it can be "complete".  What you really need to do is re-architect your code.  Each of your loops can be done without the sequence structure.  Use a State Machine instead.  And instead of the actual Waits for seconds at a time, use the Elapsed Time function.  This way you can check that stop condition faster.


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 4 of 6
(3,596 Views)

Thanks for your reply. I read about the state machine, however, I have three different timings that I need to implement; delay at the start, on time, and off time. These timings are different for specific heaters so I can not send all of them at the same time to the next state. 
Do you know if it is possible to implement the state machine to this problem?
I did not find any examples similar to this, I would appreciate it if someone can share an example

0 Kudos
Message 5 of 6
(3,517 Views)

The functionality you are describing is actually well-suited to a state machine. If my interpretation of your application is correct, then the heaters are independent of each other, are they not? If that is the case, then you could implement this application as separate while loops, separate subVI's, or even separate top-level VI's altogether. For your purpose, I would recommend creating a single subVI that manages a single heater, specified by a reference and a set of timing parameters (these would be your inputs). You can then place multiple instances of this subVI on your top-level block diagram and your heaters will each be managed independently. It will require a little more LabVIEW knowledge to stop all of the subVI's synchronously, but it is not hard. Take a look at this KB for one example of how you might do that.

 

There are a number of ways you could implement your application based on your programming style and any additional details not available in this thread. You might want to reread the documentation on state machines as well before continuing to program. They are an incredibly powerful and versatile design architecture. Ultimately, I would recommend thinking about modularity and how you can use it to your advantage in this problem.

 

Duncan W.

0 Kudos
Message 6 of 6
(3,497 Views)