LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Timed sequences. Is that hte right choice and how does it works!

Solved!
Go to solution

Hi Henrik.

 

Could you send me a the overall diagram just to see your architecture? You should have the reading mechanisms inside the same while loop as the state machine is in.

 

In the design I have sent to you, for simplicity I have choosen a time delay to halt the system after opening and closing the valves (userdefined 2-7s and the 0,3s constants). This is not the best programming technique since it stops the while-loop and thereby the reading of sensors and freezes the control panel.

 

But know that you have understood the basis concept of the statemachine we can expand it with a better aproach, which is to start a timer and then continiously check whether the desired temperature has elapsed. If the time has elapsed we continue to the next state and if it haven't then be stay in the same state. This method will make sure that the while loop is repeated over and over again when waiting for the time to elapse.

 

I have attached an example program that toggles a LED and then waits a specific time before toggleing it again. The time check is created with the method explained above where the time is checked concurrently and thereby repeating the while loop. By doing this your are still able to rotate the knob and see the belonging indicator updating with the new value even though the dalay is large.

 

Notice the 50ms "wait untill nex ms" delay in the while loop this is for saving CPU ressources for updating the front panel which is a good thing to have. CPU usage is nearly 100% without this constant and just 1% with it. 

 

You should be able to implement this in your own state machine.

 

 

You will see when editing your own statemachine you

 

 

Best regards,

Anders Rohde

0 Kudos
Message 11 of 18
(786 Views)

You will see when editing your own statemachine that you have to create new constants for all states because the enum they are created from has changed. To avoid this a type definition can be used for the state, see this article about how to do it: http://zone.ni.com/devzone/cda/tut/p/id/5318

 

Best Regards,

Anders Rohde

Application Engineer

National Instruments, DK

 

0 Kudos
Message 12 of 18
(780 Views)

Hi Anders!

I have attached my VI. I hope you can open it as it is. As it is now it doesnt work. The state machine is OK, bit the rest is frozen. As soon as I remove the state machine, everything else is OK.

 

Best regards

 

Henrik

0 Kudos
Message 13 of 18
(777 Views)

Hi Henrik.

 

Two things has to be changed

 

1) You have 2 while loops inside each other. This means that the statemachine will loop runs untill you press the state machine stop button. When you have done this you other code will execute/update 1 time and the statemachine will then start to execute again until aborted with the stop button again. To fix this you should remove the statemachine while loop and incorporate it in the other while loop.

 

When you fix this you code should be able to run but front panel will hang during the 0,3s delay times.

 

To fix this:

2) You have to change the delay time as mentioned in the above posts.

 

Best Regards,

Anders Rohde

Application Engineer

National Instruments, DK

0 Kudos
Message 14 of 18
(770 Views)

Hi Anders!

You kind of lost me on this one. I have seen your comment on my VI, but is there a problem in implementing it in the existing while loop as it is? I have changed the timing as you said and included the existing structure in the while loop of the state machine. I dont understand your comment on changing the enums to type definitions and why??

 

Best regards

 

Henrik

0 Kudos
Message 15 of 18
(758 Views)
Solution
Accepted by Henrik1972

Hi Henrik

 

Yes there is a problem with just using my code as it is. Problem is that the code we have designed based on your flowchart with a statemachine is an overall system structure which is not intended to go inside another structure.

 

If you put an overall system structure inside another structure = (while loop inside another while loope). Then the inner while loop will take over and the outer while loop will not execute. In the code you have sent to me the statemachine will run and work fine because it is the inner while loop, but all the updating of you other indicators does not work because they are in the outer while loop which is not ran.

 

To fix this problem you should.

1) Delete the outer while  loop so you only have 1 while loop. Tip: Right click on the while loop and select "Remove While Loop" to keep the code inside from beeing deleted.

2) Now the indicators are not in a loop meaning that they will not be updated. To fix this move the indicators and controls inside the while loop belonging to the statemachine. Not inside the case structure but just inside the loop. Expand the loop so everything can fit.

3) Now you have the right structure and your statemachine will work together with the indicators and controls. While you wait for user to start the statemachine you should be able to see the indicators and controls working.

4) If you have fixed the timing as mentioned in my latest example vi: "State machine timing example.vi" then indicators and controls will update all the time, if you have kept the timing structure from my first vi "statemachine to forum.vi" then the indicators and controls will not update doing the time delay but will update between each state and in the waiting for start signal state.

 

 

 

 

Have you considered taking training in National Instruments LabVIEW? All the things we have discussed here are topics which are dealt with in the "LabVIEW Core 1" course.Contact you local National Instruments department for more information on when a course is avaliable at your country (http://www.ni.com). See the course outline here:

http://www.ni.com/pdf/products/us/mkt-course-outline-labview-core-1.pdf

 

There are also a couple of video ressources for getting started with LabVIEW, programming structures and how to debug your applications avaliable:

http://zone.ni.com/devzone/cda/tut/p/id/7466

http://www.ni.com/academic/students/learnlabview/

 

  

 

Best regards,

Anders Rohde

Application Engineer

National Instruments, DK

Message 16 of 18
(755 Views)

No different from a text based language, a While loop within a while loop requires the inner loop to finish for the outer to have the outer to run another loop.

 

While{

  While{ //Loop of state machine

    Switch{ //States

      Case0: asdf;

      Case1: asdf;

      Case2: asdf;

    }

  }

//State machine must finish for this loop to run

}

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 17 of 18
(747 Views)
Ho Yamaeda.
Your simpel explanation makes sense. I am familiar with LaTeX and Matlab. Forgetting a } in LaTeX or an "end" in Matlab is equal with failure. I have never seen the graphical programming in LabView as commands. More like placing icons with a function.
You just gave LabView a new dimension. Thanks 🙂

Henrik
0 Kudos
Message 18 of 18
(738 Views)