LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

passing shift register information through case structures

Solved!
Go to solution

Hello all,

 

I am trying to write a program that increments by 20, goes up to 40, waits for Boolean to be activated before continuing, then goes down to zero.

 

I currently am using a shift register within just one of the case structures (which is working as intended) but when I get to the 3rd case structure, the shift register resets back to zero and starts passing -20. So instead of starting at 40 and reducing to 20, it instead starts at 0 and reduces to -20, breaking the code. How can I change my code to pass the number 40 all the way to the start of the 3rd case structure? 

 

Thank you very much,

Josh

0 Kudos
Message 1 of 5
(1,035 Views)
Solution
Accepted by topic author Josh_Music

Hi Josh,

 

as a first step please learn about typedefining datatypes, like enums - and using the typedefinition for all instances of that enum! Especially as you try to build up a statemachine…

 

To improve your statemachine: Don't use while loops within the states: you already have a while loop around the whole statemachine!

 


@Josh_Music wrote:
when I get to the 3rd case structure, the shift register resets back to zero and starts passing -20. So instead of starting at 40 and reducing to 20, it instead starts at 0 and reduces to -20, breaking the code. How can I change my code to pass the number 40 all the way to the start of the 3rd case structure? 

When you want to avoid "default" values then you should not use "default if unwired" tunnels in your case structure!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 5
(1,031 Views)

@GerdW wrote:

 

Don't use while loops within the states: you already have a while loop around the whole statemachine!

 



I can imagine a VI without the outermost while loop, but in order to pass information through iterations using the shift register, the while loop is the most direct method. I cant think of any problems with putting a while loop nested in a case structure. Could you please explain that? 

 

Wiring the shift register through each of the cases solved my problem-thank you!

0 Kudos
Message 3 of 5
(1,014 Views)

@GerdW wrote:

Hi Josh,

 

as a first step please learn about typedefining datatypes, like enums - and using the typedefinition for all instances of that enum!


Agreed, especially since in your case you are connecting different enums in different cases, thus turning you cases into numbers instead of enum items.

 

Of course if the enum items are arranged in typical order  You can go to the next case with a +1, thus you only need one single instance of the constant on the diagram and making it a typedef is no longer really needed (but still highly recommended!)

 

To elaborate on that and what Gerd already mentioned, here's a quick rewrite. Note that I set the increment to 1 to make it look a little bit more interesting. Unless you can guarantee that the upper and lower limits are reached exactly, you should never do equal comparisons. For example if somebody changes the step to e.g. 19, a value of 40 never occurs and your instrument will blow up way before the value reaches a million volts. 😄

 

 

altenbach_0-1638308312286.png

 

0 Kudos
Message 4 of 5
(1,009 Views)

@Josh_Music wrote:

@GerdW wrote:

 

Don't use while loops within the states: you already have a while loop around the whole statemachine!

 



I can imagine a VI without the outermost while loop,!


Gerd told you to eliminate the inner loops. Not the toplevel loop! Right?

0 Kudos
Message 5 of 5
(1,007 Views)