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.
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.
12-17-2014 11:43 AM
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.
Solved! Go to Solution.
12-17-2014 11:53 AM
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.
12-17-2014 12:00 PM
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?
12-17-2014 12:05 PM
Why is the signal coming from another loop? You might want to describe your system.
12-17-2014 12:12 PM
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.
12-17-2014 12:12 PM
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.
12-17-2014 12:16 PM
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.
12-17-2014 12:16 PM
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.
12-17-2014 12:17 PM
I guess it's just counting the number of true values being passed
12-17-2014 12:18 PM
@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.
12-17-2014 12:23 PM
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.
12-17-2014 12:29 PM
I understand what you guys are saying but I'm a litlle confused on how to pull it off.
12-17-2014 12:29 PM - edited 12-17-2014 12:39 PM
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
12-17-2014 12:54 PM
I have this which is close, but still not exactly what I need.
12-17-2014 12:54 PM
this
12-17-2014 01:24 PM
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!
12-17-2014 01:26 PM
would this work?
12-17-2014 01:40 PM
Wow, I can't believe I didn't notice this was the same question I responded to a day or two back. Getting old...
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.
12-17-2014 01:48 PM - edited 12-17-2014 01:50 PM
@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...
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