LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use elapsed time function with state machine in Lab VIEW

Solved!
Go to solution

Hello

 

I've been trying to use state machine with elapsed time function in order to sequentially start and stop my code. The arrangement is to start the code for 1 minute then stop for 5 minutes. I've attached the code, the problem is when I place the elapsed time function out of the while loop it doesn't work, on the other hand when I place it inside the loop it does work but it doesn't give the true  signal to move to the next state. 

 

Could you please have a look to my code and help me to solve this issue.

 

Regards 

 

Rajab

0 Kudos
Message 1 of 16
(5,591 Views)

Hi Rajab,

 

what is the difference between the first 5 states of your StateMachine? They all get some data using DAQAssistent and wait for some amount of time! So why create different states for them? I really start to shiver when I open a frontpanel and get 5 "Stop" buttons presented…

 

Why don't you call the first state with 5 different wait times?

 

check.png

What's the purpose of this construct?

 

Did you test the working principle of ElapsedTime in a simple example VI to understand it? After that you can incorporate it in your state machine…

Best regards,
GerdW


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

why all the while loops, wire bends...? how do you reset your elapsed timers? did you not like the example code given in your previous post.....    Smiley Indifferent 

0 Kudos
Message 3 of 16
(5,568 Views)

Hi GredW

 

I didn't think that the wait function will do the job as I want the code to stop and then start again.

I've used the true Boolean just to stop the code when the case wait 5 minutes called. 

I did use the elapsed time on the same code and I was able to stop it after 1 minute, but I don't know how to start it again after 5 minutes!!!

 By the way I'm still beginner in labview, that's why I'm asking for help !!!

 

Regards 

Rajab

0 Kudos
Message 4 of 16
(5,536 Views)

Hi apok

 

Honestly the code was a bit complicated for me, when I run it keep showing wait case only, didn't want to bother you for more explanation. So what I did I tried to simplified it 

 

thanks 

 

Rajab 

0 Kudos
Message 5 of 16
(5,531 Views)

@Rajab84 wrote:

... when I run it keep showing wait case only, 


yes it does, because it is waiting for you to press the "start" button to process....just drop your daq express vi into the state cases and change the elapsed timer constants to 60( 1minute) and 300(5minutes) Smiley Wink

 

inorder to use the elapsed timers again and again...you must reset the timer upon execution to start it, that is why we use a shift register to send amd hold boolean values.

Message 6 of 16
(5,519 Views)

Thanks apok for your help

 

even with pressing start it keeps running on wait case Smiley Sad

could you please explain the code for me, the use of Boolean crossing, increment , and equal functions 

 

Best Regards 

 

Rajab 

0 Kudos
Message 7 of 16
(5,503 Views)
Solution
Accepted by topic author Rajab84

@Rajab84 wrote:

Thanks apok for your help

 

even with pressing start it keeps running on wait case Smiley Sad

could you please explain the code for me, the use of Boolean crossing, increment , and equal functions 

 

Best Regards 

 

Rajab 


OK..I modded the example to stop after 2 cycles. Also recommend taking the free online LabVIEW tutorials.

  1. run vi. case statement goes to "initialize", shift registers are initialized to their constants. goto "wait"
  2. "start"= false, stay in current state. If true, transition to "1 min" case
  3. reset elapsed timer with True from shift register(counter starts at zero)."time has elapsed"=false, stay in current state(1 min). If true, goto "5min" case
  4. reset elapsed timer with True from shift register of previous case(counter starts at zero)."time has elapsed"=false, stay in current state(5 min). If true, goto "1min" case. Also, bool crossing is looking for "true-false" from "5 min" compare function to add cycle count.
  5. Once cycle count reaches 2, stop while loop.... 

 

 

Message 8 of 16
(5,486 Views)

Hi apoke 

 

thanks a lot for explaining, I really appreciate it. I still have a problem. When I run your code alone it works prefect but when I insert my code to the case (min 1) the elapsed time function stops working. Do I need to use my vi as a sub-vi??

 

I've attached simple example to explain what I mean, just run it and see how the code freezes on case (min 1)  and the elapsed time indicator  showing 00.

 

please frogive me for my question, Itried to solve it my self but I couldn't Smiley Sad

 

Regards 

 

 

Rajab

 

 

0 Kudos
Message 9 of 16
(5,452 Views)

Your 1-minute case structure has a while loop inside of it generating random numbers as fast as it can until you hit the Stop2 button.  Until that while loop stops, the other code in the case structure will not execute again until your outer while loop iterates again.

 

Try running your code with Highlight Execution on so you can understand how dataflow determines your execution order.

Message 10 of 16
(5,444 Views)