From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, 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: 

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,655 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,639 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,633 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,627 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,615 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,613 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,601 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,599 Views)

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

 

0 Kudos
Message 9 of 19
(5,597 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,596 Views)

I'm also not seeing a need for the second loop.  That sounds like it is just adding unneeded complexity.  Just use the shift register to hold your cound and increment it when your peak detection triggers a TRUE value.


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 11 of 19
(1,472 Views)

I understand what you guys are saying but I'm a litlle confused on how to pull it off.

0 Kudos
Message 12 of 19
(1,465 Views)

isn't this the same question as last time post? bool crossing will take care of your dwel time and count just once....again, we don't know your application and sampling rates, there are many different ways to get the same results  Smiley Wink

Example_VI.png

0 Kudos
Message 13 of 19
(1,463 Views)

I have this which is close, but still not exactly what I need.

0 Kudos
Message 14 of 19
(1,439 Views)
0 Kudos
Message 15 of 19
(1,439 Views)

Actually now I figured out how to do it, thanks everyone for the help with the shift registers instead of trying to use two loops!

0 Kudos
Message 16 of 19
(1,410 Views)

would this work?

would this work .png

Message 17 of 19
(1,408 Views)

Wow, I can't believe I didn't notice this was the same question I responded to a day or two back.  Getting old... Smiley Sad

 

I made this little VI to show you the simple way and it's pretty much the same as Apok's solution but he added the DAQ code and mine has some nice bells & whistles in case you want to get fancy.

Chart.jpg

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 18 of 19
(1,395 Views)

@NIquist wrote:

Wow, I can't believe I didn't notice this was the same question I responded to a day or two back.  Getting old... Smiley Sad

 

I made this little VI to show you the simple way and it's pretty much the same as Apok's solution but he added the DAQ code and mine has some nice bells & whistles in case you want to get fancy.

 


ahhh...well no.If your value is above your set point and dwells more than the loop iteration, your case statement will add those count. Bool crossing eliminates that and counts only at the crossing and not during the dwell period above the set point.

 

edit: and i failed to recognize your bells and whistle  Smiley Very Happy

0 Kudos
Message 19 of 19
(1,390 Views)