From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Case structure true/false loop counter

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
(6,643 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.

=======
My Channel: https://www.youtube.com/@LV_Lab

0 Kudos
Message 2 of 11
(6,631 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
(6,625 Views)

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

 

T-Fcnt.png

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 4 of 11
(6,578 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.)

0 Kudos
Message 5 of 11
(6,572 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.

Message 6 of 11
(6,569 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 🙂

=======
My Channel: https://www.youtube.com/@LV_Lab

0 Kudos
Message 7 of 11
(6,567 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
(6,559 Views)

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

=======
My Channel: https://www.youtube.com/@LV_Lab

0 Kudos
Message 9 of 11
(6,550 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.

0 Kudos
Message 10 of 11
(6,548 Views)