LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

simple counter between 1-11

Solved!
Go to solution

hey guys,

 

 I just need a quick review on simple counter app. The main idea is that when user clicks on the button (+)  the counter increments +1 and when user clicks button (-) it decrements. In any case the value should remain between 1-11 and should be in sequence, that means 1-2-3-4.....-11 or in reverse oder 11-10-9....-2-1 ... soo I came up with this solution that I am attaching but I want to know if there is a much simpler way of doing this.

 

Best Regards

Regards
Download All
0 Kudos
Message 1 of 22
(3,289 Views)

Yes, there is.

 

Mike...

 

 

 

PS: Sorry, I couldn't help myself...

 

 

To begin with, use events to catch the button presses.

Next, store the counter value in a shift register on the loop.

Finally, use the Min-Max Value function to constrain the count in the limits you specified.


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 2 of 22
(3,282 Views)

@nolsqn wrote:

... but I want to know if there is a much simpler way of doing this.


There definitely is!

 

You don't need any local variables.

You don't need any subVIs

You don't need any comparison operations

You don't need to consume 100% CPU.

 

Code could proably fit on a postage stamp!

Try it!

0 Kudos
Message 3 of 22
(3,278 Views)

hi mike,

 

i cannot use even structure as the boolean buttons actually later will be digital inputs. but i will update the VI with max -min function 🙂 and post the new version later

 

regards

Regards
0 Kudos
Message 4 of 22
(3,267 Views)

hi alten,

 

any example you can tell me for reference ?

 

regards.

Regards
0 Kudos
Message 5 of 22
(3,266 Views)

You can create what are essentially value change events on digital IO points -- and don't forget to lose the local variables and hold the number in a shift-register...

 

Mike...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 6 of 22
(3,264 Views)

 

Get rid of the local variables

You only need one shift register to store the single value that you need not one for both + and -

No need for the two sub VI

 

Look at using

Event Structure

Quotient & Remainder

 

I have put all the stuff you need in this VI and left it to you to figure out how to wire it up.

 

Main_vi.png

Omar
0 Kudos
Message 7 of 22
(3,261 Views)

hi omar,

 

I appreciate your design but as I said later my boolean buttons will be replaced with DI , hence I cannot use event structure.

 

 

Regards
0 Kudos
Message 8 of 22
(3,257 Views)

nolsqn wrote:

any example you can tell me for reference ?


Well, this is obviously homework, so you need to make sure you understand every little wrinkle of the code. Try this.

 

 

 

If you don't want to use an event structure, it would be simple to adapt using a case structure. You also need to simulate the off-on transition.

Download All
0 Kudos
Message 9 of 22
(3,254 Views)

Hi alten,

 

as far as I know Digital inputs from a DAQ card doesnt work with event structure, so  I could have used event structure from start as well, but since I will be using DI's later thats the reason for a solution.

 

p.s its not homework, i was just hoping to see if I can implement it in a more better way.

Regards
0 Kudos
Message 10 of 22
(3,244 Views)