LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Counting Boolean Values, resetting shift register

Hi All,

I am currently working on a VI that requires something I have yet to find on the site.

 

Speaking broadly, I have a while loop with two options for stopping it. The first is the traditional stop button. The other is a local variable I created. The local variable is currently a boolean value, and when it turns true, it stops the program.

This worked [hooray!], however upon further investigation I've realized this true value can pop up several times. Now the REAL test is this:

 

Somehow I must "count" every time I see a true value. When I have 10 in a row [approximately 10s worth of data] THAT is when the local variable should stop the loop. However, the trick is that if there is ONE true value followed by a false value, I need whatever it is counting these boolean values to reset, so that i get a count of 10 consecutive trues rather then a total count of true values throughout the program.

 

 

**Also, if anyone can give me a good suggestion on how to reinitialize the program to its default values [LED off, graphs and arrays empty], that'd be awesome too!

 

Sorry for the tiny picture, I couldn't tell where a subVI would be useful.

Thank you in advance for the help!

0 Kudos
Message 1 of 10
(9,611 Views)

Use a numeric shift register that increments with each true and zeroes with each false. Stop the loop once the count is 10.

 

 

Message 2 of 10
(9,603 Views)

Here's the picture of the last post.

 

 

 

And here's a variation without case structure.

 

Message Edited by altenbach on 09-10-2008 02:14 PM
Message 3 of 10
(9,598 Views)

Thank you altenbach.

 

Two questions; first, what is the purpose of the random number generator? Can I replace that with the output from my Boolean comparison? [Also outputs a true or false].

 

Second, the shift register will zero out its count with each false?

0 Kudos
Message 4 of 10
(9,565 Views)

cgy5002 wrote:

Two questions; first, what is the purpose of the random number generator? Can I replace that with the output from my Boolean comparison? [Also outputs a true or false].


Well, we need to simulate some boolean because I don't have your hardware or the rest of your code. All you need to copy is the code after the comparison operation. The dice generates a random number between 0 and 1, so checking if the random number is >0.1 will give a TRUE 90% of the time, making the chance of 10 in a row relatively high.

 

Replace the dice and the comparison with your real boolean from your code. 🙂

 


cgy5002 wrote:

Second, the shift register will zero out its count with each false?


Yes, it will. The FALSE case is empty and the output tunnel is set to "use default if unwired". (that's why it is not solid green if you look carefully ;)). Every time the FALSE case executes, the shift register will get a zero. In the seond case, it gets multiplied by zero, which also results in zero.

Message 5 of 10
(9,558 Views)

Altenbach, you rock!

I used your example in my program, but substituted a for loop instead of the while loop. Since it was already all within a while loop, my program would get stuck waiting for this while loop to finish.

 

I really appreciated your help!

0 Kudos
Message 6 of 10
(9,552 Views)

cgy5002 wrote:

I used your example in my program, but substituted a for loop instead of the while loop. Since it was already all within a while loop, my program would get stuck waiting for this while loop to finish.


A FOR loop seems incorrect. A while loop is much more appropriate, because you cannot know hown many iteration it takes to get 10 consecutive TRUEs, so the number of iterations is variable.

 

If the while loop does not finish, it simply means you never meet the desired condition. 😉

 

Since your statement does not really make sense, maybe I misunderstood. Can you show us some simplified version of your program?

Message 7 of 10
(9,548 Views)

Here are some images of my program, as well as my program.

 

I used a while loop prior to the for loop, but found my agilent would take one measurement, then the inner while loop kept running with the single false value trying to satisfy that loop.

 

So, I changed it to a for loop. I illuminated the program while it ran, and to me it looked like a new value came off the comparison into the for loop [at the Boolean to 0,1 function]. Maybe I was wrong and it's actually the same initial value i see running?

 

 

And yes, after I replied to your post about the random number generator, I realized it's purpose. ha! Smiley Very Happy

0 Kudos
Message 8 of 10
(9,544 Views)

I haven't had a chance to study your program, but looking at the code picture, you need to place the shift register in the existing while loop!!!

 

The way you have it now makes no sense, because the FOR loop only spins once and the shift register is initialized with zero every time the FOR loop is called.

Message 9 of 10
(9,540 Views)

Doh! Talk about a "Homer" move.

 

I'm sure this will work [I'll be testing it tomorrow].

If not, expect a new reply. Smiley Happy

 

Thank you for all of your help!!

I may post back with the few errors I still have.

0 Kudos
Message 10 of 10
(9,535 Views)