cancel
Showing results for 
Search instead for 
Did you mean: 

Using a true Boolean to increment a counter

SOLVED
winterfresh11
Member
Solved!

Using a true Boolean to increment a counter

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.

18 REPLIES 18
NIquist
Trusted Enthusiast

Re: Using a true Boolean to increment a counter

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
Highlighted
winterfresh11
Member

Re: Using a true Boolean to increment a counter

Message contains an attachment

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?

crossrulz
Knight of NI

Re: Using a true Boolean to increment a counter

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



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
natasftw
Active Participant

Re: Using a true Boolean to increment a counter

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.

winterfresh11
Member

Re: Using a true Boolean to increment a counter

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.

BowenM
Active Participant

Re: Using a true Boolean to increment a counter

Message contains a hyperlink

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.

natasftw
Active Participant
Solution

Re: Using a true Boolean to increment a counter

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.

winterfresh11
Member

Re: Using a true Boolean to increment a counter

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

 

natasftw
Active Participant

Re: Using a true Boolean to increment a counter

Message contains a hyperlink

@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.