LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Event structure really needed for latch start button?

Refer attached 3 vi from CLD exam sample answers. 

 

In Boiler and sprinkler vi, the latched Start button is a simple button wired to a conditional function. No need for event structure. 

 

ScreenHunter_01 Mar. 11 22.15.gif

 

But in the Carwash vi, the Start button is in a event structure! 

 

 

 

ScreenHunter_02 Mar. 11 22.23.gif

 

 

 

 

Why the difference? Is this due to personal preference/programming style? Or is there a deeper reason I am not aware of? 

 

Or is the Carwash programmer trying to be fancy not following KISS principle? Smiley Tongue  In the CLD exam, if I dont need to complicate matters with event structures, I wont use them!

0 Kudos
Message 1 of 4
(4,082 Views)

You've already gotten most of the answer in Need to paste on/off button in its own event structure.

 

The real question is why did the programmer not use an event structure in the Boiler example?  They just probably didn't see a need to use it in the way that program will flow.

 

When you have latching booleans, you want to put them in a location so that when that portion of the code executes, the terminal for the button will be read causing the button to "pop back up".  When you have an event structure, it is most logical to put it in the event case that handles that button.  In the boiler and sprinkler examples, the button is actually a part of a cluster.  The button will pop back up when the terminal for the cluster gets read which is happening at the beginning of the loop ahead of the case structure.  That means the button is getting read on every iteration of the loop.  Depending on how long a given state of the state machine takes (the time inside of any given case of the case structure) will determine when the button pops up.

 

Event structures are not intended to be fancy, or a situation where the programmer is trying to showw by "not following the KISS principle".  If you think event structures are too complicated to use, I suggest you spend more time learning to use them before you start taking the CLD exam.  Event structures are a powerful tool, and often the correct tool for certain program architectures.  There are also program architectures where the use of the event structure might not be necessary.  It's one of those things you'll have to figure out on a case by case basis when you start to design your program before you ever drop your first function or connect your first wire.  You can have an application where you could write a program with an event structure, or write a different, perfectly legitimate program without an event structure.  But you might find that the one with the event structure is easier to write and does the job better.

Message 2 of 4
(4,075 Views)

The difference is synchronous vs. Asynchronous state machines.

 

The first pic is a synchronous state machine where a state executes every 50 ms (because of the wait). This is useful when you need a defined timing (such as PID control loop).

 

The second pic is an asynchronous state-machine. The state transition is triggered immediately when an event is received.

 

Felix

Message 3 of 4
(4,044 Views)

 


The first pic is a synchronous state machine where a state executes every 50 ms (because of the wait). This is useful when you need a defined timing (such as PID control loop).

 

Felix's explanation is a very good explanation but I wanted to clarify a couple of points. While this is most likely the case it is not guaranteed. If any one state takes longer than 50 ms to execute you will not see a state machine executing every 50 ms. In the situation if you graphed the start time for every state you would see that over time the overall execution drifts from a perfect 50 ms tick on the graph. In addition, unless this is running on a RT system, you will not be guaranteed a 50 ms timing as other things on the system (web browsing, file access, network activity, etc.) will impact perfromance.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 4 of 4
(4,031 Views)