LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Breaking out a loop

Solved!
Go to solution

Hello, 

 

I'm trying to write a program with a state machine. One of the state is the ''test'' state. In that state, I have 5 step : Heating, cooling, resistance measures, saving data and emergency stop (AU). Whenever there is a problem, I want to return to emergency stop. My problem is, for heating and cooling, it needs to be timed. I tried a ''wait'', and it works. The only problem is, if one of my emergency stop condition occurs while I'm in heating or cooling, I stay stuck in the state for the time value I put in the ''wait''. It's dangerous for my application, because I'm heating a cable and if the temperature is to high I really need to stop heating and go the emergency stop. 

 

I also tried a Timed loop, but the only way I can stop it is with an event structure that only depends on controls (wich is good for a STOP HEAT button), but my other conditions are global variables that I measure physically and send to labview through a agilent and a labjack that goes into a producer-consumer vi.

 

Any ideas for me ?

0 Kudos
Message 1 of 23
(1,373 Views)

@cookie10 wrote:

Hello, 

 

I'm trying to write a program with a state machine. One of the state is the ''test'' state. In that state, I have 5 step :

Any ideas for me ?


With out even looking at your code: Yes, each of the 5 steps in your "test state" should be a state. 

 

Then instead of using a Wait have a "timer" state that can be aborted.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 2 of 23
(1,350 Views)

you have to add a condition that the emergency stop is monitored all the time so it triggers the EMERgency state, even during wait , heat, coolilng, and when it occur it overrides any other condition. 

0 Kudos
Message 3 of 23
(1,296 Views)

That's exactly what I'm trying to accomplish, but I'm struggling with finding out how, since my wait function forces the state I'm in to stay there until the heat time is over. 

0 Kudos
Message 4 of 23
(1,270 Views)

For something that is safety critical, I highly suggest you refactor your code. I have not looked at it in detail but there are a plethora of global/local variables that can lead to possible race conditions. All those values could be added to a cluster and put on a shift register for your loop, no globals or locals needed.

 

For your problem I suggest something like the JKI State Machine; your have an Event Structure in a loop. In your loop you can go to different states. For your "Wait Case", you could need to change the timeout of the Event Structure and go into an "Idle" State. If the event structure times out then you complete your test. If the time out of  event structure is interrupted by an Event, like an Emergency Stop, you can go to that case. That is the beauty of using the timeout of an event structure it can be interrupted and stopped if needed.

0 Kudos
Message 5 of 23
(1,268 Views)

Do you mean a timed loop with an ''abort'' event structure ? I tried, but it only works with a controlled button that the user has to press. I need it to also depend on 2 global variables that are EMERGY STOP BUTTON PUSHED and TMAX REACHED.

My application needs to run even when no user is around to press the stop heat button

0 Kudos
Message 6 of 23
(1,266 Views)

@cookie10 wrote:

Do you mean a timed loop with an ''abort'' event structure ?


No. I mean an event structure.

 


@cookie10 wrote:


My application needs to run even when no user is around to press the stop heat button


A proper State machine can handle this no problem.

 

Below is a screenshot of the JKI State Machine, available on VIPM. Notice there is an Event Case in an "Idle State" to handle UI Interactions. The default timeout for the Event case is -1, but you can change that with a New State called Set Timeout and a Shift Register. Notice there is a shift register with a cluster that has all the data the State Machine Needs.

 

You can have a case and check the temperature, if TMax reached then shutdown.

 

mcduff_0-1691168661632.png

mcduff_1-1691168718896.png

 

 

0 Kudos
Message 7 of 23
(1,252 Views)
Solution
Accepted by topic author cookie10

In this case you can't use the Wait function because you will be stuck. One option is to implement a "Wait function using Tick Count, the while loop start and then read the tick count every iteration and compare with the first iteration to calculate elapsed time, it stops when the elapsed time is higher than the wait time, in the same loop you read the variable for Emergency (I guess it's called AU in your code) to stop the loop and get out of the wait. 

 

 this is a simple version 

 

LVNinja_0-1691169255632.png

 

Message 8 of 23
(1,248 Views)

Do not rely on software to act as a safety mechanism for unattended high temperature control.

 

Also implement an independent hardware solution such as a temperature monitoring relay where you can set an upper temperature limit. If that limit is exceeded the relay can cut power to the heating element.

 

-AK2DM

~~~~~~~~~~~~~~~~~~~~~~~~~~
"It’s the questions that drive us.”
~~~~~~~~~~~~~~~~~~~~~~~~~~
0 Kudos
Message 9 of 23
(1,239 Views)

Thank you so much! This works! now I can go to sleep lol

0 Kudos
Message 10 of 23
(1,221 Views)