LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Labview State Machine

I need a state machine with three steps. Each step has a Led. I need to turn on each led one after the other. And each led should be on for a given time period. I could be able to add the time period.

 

Thank you

0 Kudos
Message 1 of 6
(323 Views)

Hi Rancat,

 


@Rancat wrote:

I need a state machine with three steps…


When you "need" code then you should create that code!

 

What have you tried?

Where are you stuck?

Which LabVIEW version do you use?

Have you tried to examine all the example code that comes with LabVIEW?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 6
(285 Views)

One way to build a State Machine is with a While Loop surrounding a Case Statement.  You also need a variable (call it "State") that holds the particular State.  What kind of variable do you want to use for State?  [Since you are new to LabVIEW, you probably don't know about Enums, but you could use a String control (and "name" the States) or an integer (I8, since you probably will not need more than 100 different states, so you can call them 1, 2, 3, ...) for the State.

 

Do you know about Shift Registers (on the While Loop) which you will use to "hold" the value of the State when the While Loop starts, and updates it when the While Loop reaches its "right edge")?  You initialize the Shift Register by writing the first State (1, or "Initialize" or "First State") to the left-hand Shift Register.

 

So now you put the Case Statement inside the While Loop and wire the "State" wire to the Case Selector, and carry this wire through the Case Statement, out the back end to the right Shift Register of the While Loop.

 

The Case Statement is where you put the code for each desired State.  If you have variables you need to change, you place these variables on Shift Registers in the While Loop (which serves as the "memory" for that State) and do whatever processing of the variables is required by the State.  If "timing" is involved (say, you want State 1 do increment a variable, wait 5 seconds, then go to State 2), you do all that programming within the State 1 Case.  So you'd put an "Increment" on the Variable wire, add a 5 second (5000 ms) "Wait (ms)" delay, and increment the "State" wire (I'm assuming you are using an Integer "wire" for the State).  So 5 seconds after you enter the Case Statement inside the While Loop, you'll exit it with the State incremented, and the While Loop will repeat (unless you wired "T" to the Stop control).

 

I've left out some steps (like how to initialize the Stop control), but you should be able to figure them out.  Ask your fellow students, or your instructor.

 

Bob Schor

0 Kudos
Message 3 of 6
(222 Views)

You can find examples and an explanation of a typical state machine at the LabVIEW wiki or the NI documentation.

0 Kudos
Message 4 of 6
(217 Views)

@Rancat wrote:

I need a state machine with three steps. Each step has a Led. I need to turn on each led one after the other. And each led should be on for a given time period. I could be able to add the time period.


From reading your question, you know what a state machine is and your program is almost complete except for the timing issue. Is this correct?

 

In that case, I would recommend to shows us your code draft (do a "save for previous", 2020 or below, because many don't have the newest version) and we will point you in the right direction.

 

  • What are the controls? (start, pause, stop, reset, duration for each step, etc)
  • What are the indicators? (just three LEDs, one for each step?)
  • Should the states have names or just numbers?
  • What other requirements should be met?
  • Is this homework for a course?

 

As an example of simple state timing, have a look at my old traffic light example here. I am sure you can adapt it to your requirements once you understand the basic principle.

0 Kudos
Message 5 of 6
(199 Views)

have you tried chat gpt ? 

0 Kudos
Message 6 of 6
(144 Views)