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.