LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Case structure true/false loop counter

Highlighted

Hi,

 

Good Morning.

If someone could help me setup a case structure inside a while loop and count each true/false cycle. 

Not the iteration counter. 

whenever a boolean does true/false loop inside a while loop, that's 1 cycle. 

Apologies for not uploading a test VI, I made a mess trying to figure out and it looks horrible. 

 

Kind Regards,
Ash

0 Kudos
Message 1 of 11
(980 Views)

counter.png

 

Do you need a Case Structure? Or it was just an idea?

I made this, check out if it does what you need.

0 Kudos
Message 2 of 11
(968 Views)

Hi AldhairGarza,

 

I am looking for a case structure inside a while loop.  

And count true/false cycle. 

Ill check your VI now, maybe it might work. 

Thanks,
Ash

0 Kudos
Message 3 of 11
(962 Views)

Right off the top of my head I would do this...

 

T-Fcnt.png

-------------------------------------------------------------------
Unfortunately, most readers of this Forum, including some real Experts, have not mastered the skill of being able to read the code that Posters fail to post. If we cannot see "what you did wrong", we are unable to tell you how to fix it. (Bob Schor 28 August 2018)
0 Kudos
Message 4 of 11
(915 Views)

@Ash_zh wrote:

 

whenever a boolean does true/false loop inside a while loop, that's 1 cycle. 

 


You need to define what "true/false" actually means. Your description is ambiguous.

  1. Going form TRUE to FALSE? (T>F)
  2. Going from FALSE to TRUE? (F>T)
  3. Boolean changes (T>F or F>T)

Let's assume you want to count whenever it goes from TRUE to FALSE. Here's what I would do. It can easily adapted for the other conditions by changing the comparison. (larger, smaller, not equal).

 

TtoFcount.png

 

(Of course I am assuming that you are polling some real data from an instrument. If it is just a button, an event structure seems a better choice because you don't need to spin the loop unless the value changes.)


LabVIEW Champion Do more with less code and in less time
0 Kudos
Message 5 of 11
(909 Views)

@AldhairGarza wrote:

counter.png

 

Do you need a Case Structure? Or it was just an idea?

I made this, check out if it does what you need.


It seems incorrect to use an expanded shift register and compare the i-1 and i-2 values. Typically one would use a plain shift register (or feedback node as in my example) and compare the current value (from the terminal!) with the immediately previous value (i-1) from the shift register.


LabVIEW Champion Do more with less code and in less time
Message 6 of 11
(906 Views)

@altenbach  ha escrito:

@AldhairGarza wrote:

counter.png

 

Do you need a Case Structure? Or it was just an idea?

I made this, check out if it does what you need.


It seems incorrect to use an expanded shift register and compare the i-1 and i-2 values. Typically one would use a plain shift register (or feedback node as in my example) and compare the current value (from the terminal!) with the immediately previous value (i-1) from the shift register.


You are right! Thanks for the observation Smiley Happy

0 Kudos
Message 7 of 11
(904 Views)

Hi,

 

I have a case structure inside a while loop.

Case structure is controlled by a boolean (T/F). 

For my test, boolean ON(true) and OFF(false) represents 1 cycle. (Boolean default position is OFF)

I need to count every cycle and not every loop iteration.

Ash

0 Kudos
Message 8 of 11
(896 Views)

I think you can use the code from altenbach, set the comparison to not equal and then divide the number (counter) by two.

0 Kudos
Message 9 of 11
(887 Views)

@Ash_zh wrote:

 

 

For my test, boolean ON(true) and OFF(false) represents 1 cycle. (Boolean default position is OFF)

 


You are still not concise enough. It cannot be ON -AND- OFF at the same time of course, so don't say "and"., so do you want to count (1) all changes, (2) all raising edges or (3) all falling edges. My solution above has information for all three. (It does not matter if the boolean is also connected to a case structure)

 

If you want to count e.g. cycles (e.g. OFF-ON-OFF), that's the same as (OFF-ON), except you need to adjust based on the last boolean value.


LabVIEW Champion Do more with less code and in less time
0 Kudos
Message 10 of 11
(885 Views)