LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

state machine::how to

Solved!
Go to solution

hi

i try to implement this state machine send below

where x :input and y output where both stream of one and zero

i read some tutorial i just need some help to complete the vi.

 

thank in advace

 

regards

m.s 

 

hi ?Q>

Download All
0 Kudos
Message 1 of 5
(2,330 Views)

I'm trying to understand your state machine...

 

You need to identify which state is which.  Your event is a new value of X.  Depending on the outcome it goes to a new state which assigns a value to Y.  Is that correct?
If so, at this state I would give the states an identifier.  It will allow you to create your state machine. 

You can use names or numbers (although names are a much better approach).

 

 

So the next thing to do is to drop a Case Structure inside your While Loop.

 

For the sake of an exercise and ability to explain, you could call them from left to right:

One, Two, Three, Four, Five, Six.

 

You can then create a type def enumerator and fill in those 6 names.

 

You then populate the entire Case Structure with those matching names.

Based on which state (case) you're in, you then go to the next state (case) based on the new value of X.  That's where the Shift Registers are useful.

 

Message 2 of 5
(2,294 Views)
Solution
Accepted by topic author mangood

State machines require a few things that you are missing from your VI.  Most importantly you are missing a Case Structure.  The Case Structure will perform different code based on which state you are in.  You also will need something that identifies which state you are in.  Usually this is a Enumerator. Inside the case structure you need to have code that will determine which state will be next.  In your case the value of x is what determines the next state.  Check out this VI Snippet, it should look similar to what you are trying to do.  

 

State Machine.png

Regards,

Eric L.
Applications Engineering Specialist
National Instruments
Message 3 of 5
(2,291 Views)

The shift register will provide the index to the Case Structure to which case is selected in the next iteration.  Within the Case, you can assign the new value for Y.

 

So that you can see what is going on, you may want to set a trigger....  If we keep it simple, you could create a popup message showing you the values for X & Y at the exit of the While Loop and also mention which State (One, Two... ) you were in.

Message 4 of 5
(2,289 Views)

Eric_L and 

hi ?Q>

0 Kudos
Message 5 of 5
(2,275 Views)