LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Building a simple counter

Solved!
Go to solution

Hi, I'm just getting started in LABView, and i'm learning very slowly. I have build a counter to count my joystick actuations as it is cycled on a life tester. I have it set up to count the individual directional actuations, but I would also like it to have it count total cycles. I am posting up the VI I have made so far. How do I make it so that after it has been cycled once in each direction(Up, Left, Down, Right), it counts one cycle? Thank for any help in advance.

 

- Jerrod

0 Kudos
Message 1 of 8
(4,092 Views)

Hi Jerrod,

 

  A couple of comments about your VI as-is.  Are you aware that if you don't initialize your shift registers, each time you run the VI the shift register will start with the value from the last time it was run?  Why are you using a local variable rather than the data wire to select your cases?  Why are you type casting the result of the addition?  As to your question, are you looking for a total of the times that all four directions have been actuated, or count once for moving all 4 directions and then look for the next full cycle?

Jim

LV 2020
0 Kudos
Message 2 of 8
(4,066 Views)

Thanks for your response lmtis. I'm going to go ahead and correct the deficiencies you pointed out. Like I said i'm extremely new to this go what might seem simple or intuitive to most really isn't to me. To answer your question, I want for it to count once after moving in all four directions, and only count if all four directions have been actuated in the correct sequence. This way if the joystick breaks, I know after now many cycles it broke. Thanks for your help.

 

Jerrod

0 Kudos
Message 3 of 8
(4,057 Views)

Hey Jerrod,

 

This is a simpler way to get started.  Try it out and let me know.  I don't have a joystick to test it with.

Jim

LV 2020
Message 4 of 8
(4,046 Views)

This actually works pretty brilliantly except for one thing. On the last actuation, which makes the counter go up by 1, that direction remains "true" so it only takes the other 3 directions to get another cycle rather than having to do all four again. How can I rectify this?

0 Kudos
Message 5 of 8
(4,033 Views)

What's happening is when the final switch actuates, the inner while loop exits, the outer loop executes, and re-enters the inner loop before you have released the switch.  In the outer loop you need to put some code that will check for all of the of joystick values to be false before entering the inner loop.

Jim

LV 2020
0 Kudos
Message 6 of 8
(4,017 Views)
Solution
Accepted by topic author GHLabTech

I think the only problem is that it is looping so fast (10mS) that by the time the counter increments it has already counted the next event.  You could add additional logic to prevent the inner while loop from stopping until the joystick direction returns to boolean 0.  The idea is that only stop once all 4 have been activated AND all 4 are no longer in an active state.  I used the NOT function to make it more obvious what the logic was, you can also have the output of the compound arithmetic set to be inverted but that only shows up as a small dot on the line.

 

Like the other post, I do not have a way to test this but I think my logic was sound.

 

Edit1: The post above beat me to it, and his suggestion would work just as well as mine, we just thought of it differently.

Edit2: I noticed in one of your posts above you mentioned that you want it to count only when it was activated in a certain order.  This VI doesn't work that way, it would take more complicated logic to do that.  I can think of a couple ways that might be done but don't have time to work it out to see what would be best.  Good luck and have fun.

0 Kudos
Message 7 of 8
(4,014 Views)

Thanks for your help both of you!

0 Kudos
Message 8 of 8
(3,998 Views)