LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

State Machine Shift Register

Solved!
Go to solution

Attached is a state machine I created to illustrate a problem I am having with a larger program.  It doesn't do much but the concept is the same.

 

I created two program buttons (run & abort).  If I abort the count down timer (suspend to idle state) then select run it begins counting down from previous counter value.  I need to begin counting down from 1 min.

 

The shift register of the state machine while loop retains value when last selecting the abort button.  I need state machine while loop shift register to be reinitialized each time the run button is selected while in the idle state.

 

Thx 

0 Kudos
Message 1 of 11
(4,345 Views)

Then feed the constant into the shift register rather than the wire that is going into it now.

0 Kudos
Message 2 of 11
(4,343 Views)

sorry i dont get it.  i think you are saying wire the value from the idle loop ?  can you show me what that looks like ?

 

thx

0 Kudos
Message 3 of 11
(4,337 Views)
Solution
Accepted by ggress1

There is no "idle loop".  You have an idle case.  Instead of wiring through the count from the left side shift register.  Just feed a constant to the wire that goes to the right side shift register.

Message 4 of 11
(4,323 Views)

Wire the upper shift regsiter also across the inner case structure of the "idle" case and reset it in the true case.

 

Overall, you should re-think this entire code. It could be made much simpler.

  • I don't think you need the inner while loop, it just constipates everything. Use the outer while loop for this (it is just a different state!).
  • There is an "equal zero" primitive.
  • Why do you need a local variable for the abort?
  • Just place the terminal right there instead. Your VI uses 100% CPU while idle. ...
0 Kudos
Message 5 of 11
(4,319 Views)

ok i got it, thanks.

0 Kudos
Message 6 of 11
(4,317 Views)

Here's quick cleanup that should give you some general ideas (LV2013). Probably needs a few tweaks.

 

Of course you could use the high resolution timer to keep track of the countdown clock, eliminating the cntr state entirely.

Message 7 of 11
(4,316 Views)

The inner while loop is there so the "facility reg" control gets sampled at a faster rate than one second.  Maybe there is another method.

 

Thanks for the input; I will review.  I don't want my code to use excessive cpu resources.

 

Thx

0 Kudos
Message 8 of 11
(4,312 Views)

hey thanks for the code, very streamline compared to my code.  I will reverse engineer it and hopefully pickup some new techniques.

 

thx

0 Kudos
Message 9 of 11
(4,310 Views)

@ggress1 wrote:

The inner while loop is there so the "facility reg" control gets sampled at a faster rate than one second.  Maybe there is another method.


Nobody forces you to use an integer for the timer.


altenbach wrote:

Of course you could use the high resolution timer to keep track of the countdown clock, eliminating the cntr state entirely.


Attached is what I had in mind. Now the countdown is accurate, because it does not rely on any loop rate. Only two states needed.

0 Kudos
Message 10 of 11
(4,307 Views)