LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using a true Boolean to increment a counter

Solved!
Go to solution

Hi everyone,

 

I would like to make a simple counter that just waits until a true boolean is passed and then counts 1, then waits until it is passed again and goes up to 2, and so on. Just a single increment everytime a true is passed. I'm sure this is pretty simple but I have had no luck so far.

0 Kudos
Message 1 of 19
(5,659 Views)

This sounds like a homewrok question so please post whatever you have and we'll work through it.  You're right that it's extremely simple so give it your best shot and post it up...

 

HINT:  A shift register in a while-loop would be a good start. Smiley Wink

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019 - Unfortunately now moving back to C#, .NET, Python due to forced change to subscription model by NI. 8^{
0 Kudos
Message 2 of 19
(5,643 Views)

I guess this is what I described but I need it to work differently. I'm getting the true boolean from a different while loop, can I pass it between the two loop?

Message 3 of 19
(5,637 Views)

Why is the signal coming from another loop?  You might want to describe your system.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 19
(5,631 Views)

I'm guessing by "work differently" you are meaning you only want it to register once for each time you press the boolean.

 

If this is the case, you'll want to change from the polling you're currently doing to use an Event Structure.  You'll want a case for the boolean value change.  In that, you'll want to increment the value being sent to the shift register.

You'll also want to look at mechanical actions or property nodes to set the boolean back to false so the UI looks the same as it did prior to the button being pressed.

 

If you're getting the value from another loop, that's a bit... awkward.  You'd be better off implementing your code into this loop.  If you must use two loops, you might want to take a look at queues to understand how to pass data between loops.

Message 5 of 19
(5,619 Views)

It's being generated from the peaks of a waveform graph. Everytime it hits the peak it passes a true. When this true is passed I'd like it to increment a counter like the one posted.

0 Kudos
Message 6 of 19
(5,617 Views)

There are many ways to pass information between loops - some better than others.  One method would be to take the VI you already posted and turn it in to a functional global variable.

 

This document (http://www.ieee.li/pdf/viewgraphs/labview_design_patterns.pdf) discusses a few of the methods you can pass data around.

0 Kudos
Message 7 of 19
(5,605 Views)
Solution
Accepted by topic author winterfresh11

That doesn't sound like a need for a secondary loop.  You can add code to that loop to analyze the data.  If you're doing the calculations to determine there is a true, you're already doing the work.  Instead of outputting a true, simply increment a value to a shift register there.  That saves the hassle of sending a true constant to another loop to update a shift register.  Don't create excess code just to have more code.

0 Kudos
Message 8 of 19
(5,603 Views)

I guess it's just counting the number of true values being passed

 

0 Kudos
Message 9 of 19
(5,601 Views)

@BowenM wrote:

There are many ways to pass information between loops - some better than others.  One method would be to take the VI you already posted and turn it in to a functional global variable.

 

This document (http://www.ieee.li/pdf/viewgraphs/labview_design_patterns.pdf) discusses a few of the methods you can pass data around.


I'd suggest against this method here.  With two loops running in parallel, you'd have a hard time controlling which takes place first.  You also couldn't guarantee reading exactly once for each write.  This introduces more error to the solution than what is needed.

0 Kudos
Message 10 of 19
(5,600 Views)