LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Boolean Counter and Reset

Solved!
Go to solution

Hello,

 

I would like to create a LabVIEW counter display which increments with every boolean click (i.e. user input, Start button). Each boolean click is currently running one cycle of my test i.e. in a State Machine. So far, the counter increments with each click correctly.

 

Problem: I haven't found a way to reset the counter at will. I would like to reset this counter when the user selects a Stop button.

 

PS: I dont have Event Structures since im using LV Base. Your help will be appreciated, thanks!

 

File IO Problem.png

0 Kudos
Message 1 of 11
(6,193 Views)

That's an unusual use of a for loop combined with the boolean to 0,1.

 

I don't know what the rest of your code does, but I'd recommend one of two approaches:

 

1) a dedicated VI containing a while or for loop with shift register that stores your value.  There should also be an "action" input; in your case the actions you would need are "reset" and "increment."  The output would be the count.  This is known as an "action engine" or a "functional global variable" and you can search this forum for those terms.

 

2) Keep the counter in a shift register in a while loop that surrounds most of your code, instead of just that single for loop.  Put a "select" function in line somewhere; wire the stop button to the center boolean input.  Wire the true input to the existing value (from the shift register) and the false input to 0.

0 Kudos
Message 2 of 11
(6,181 Views)

Thanks for your respose, still having the same issue, the counter wont reset.

 

0 Kudos
Message 3 of 11
(6,163 Views)

Can you upload your entire VI, instead of just a screenshot of one small section of it?  Which approach are you using to reset the counter?  The existing screenshot doesn't show anything that would reset it.

 

Or, are you asking about how to get it to reset when you click the "Stop" button in the LabVIEW toolbar?

0 Kudos
Message 4 of 11
(6,161 Views)
0 Kudos
Message 5 of 11
(6,156 Views)
Solution
Accepted by topic author PSerial

Still not quite sure what you're trying to accomplish here since hitting the stop button will stop the loop, and if you simply initialize the counter shift register (as shown) outside the loop, it will reset to 0 when you start the code again.  The attached snippet also demonstrates how you could reset it when the stop button is pushed by using the select function.state machine with counter.png

Message 6 of 11
(6,152 Views)

Have you tried the following in your for loop?

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
Message 7 of 11
(6,144 Views)

I have modified your code, and it should do what you want.  

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 8 of 11
(6,135 Views)

Looks to me like you're making it much more complicated than it needs to be.  That loop in the first post doesn't do anything and the un-initialized shift register could cause a problem.

 

Here's an easy way which I think will work for you:

 

Basically, there are just two buttons.  If Increment is pressed, it adds 1 to the current value.  If Reset is pressed, it sets the value back to zero.  In this configuration, Reset over-rules Increment.

 

 

0 Kudos
Message 9 of 11
(6,127 Views)

Thank you all for the solutions! I think nathand's statement "if you simply initialize the counter shift register (as shown) outside the loop, it will reset to 0 when you start the code again" was the missing part of the puzzle for me. Once again, thank you all! 🙂 

0 Kudos
Message 10 of 11
(6,121 Views)