Jump to content

Keeping count


Recommended Posts

How do I do this in Labview?

- Generate a number between 0-1

- If the number is less than .5, increase my count by 1

I read about shift register, but it's for For loop and While loop only.

You got the first part and most of the second part.

It seems like the shift register is precisely what you need. Use it to keep track of a value from one iteration to the next. Currently you always add one to zero; with a shift register you would increment a value that has potentially been incremented at previous iterations. Sounds more useful to me...

Guillaume Lessard

Link to comment
You got the first part and most of the second part.

It seems like the shift register is precisely what you need. Use it to keep track of a value from one iteration to the next. Currently you always add one to zero; with a shift register you would increment a value that has potentially been incremented at previous iterations. Sounds more useful to me...

Guillaume Lessard

Thanks Guillaume. The problem is I'm not quite sure how to use the shift register with my Case Loop.

MC

Thanks Guillaume. The problem is I'm not quite sure how to use the shift register with my Case Loop.

MC

Well, I changed my code a bit but it's working better, but not totally right. It's resetting my Count to 0 when the comparitor is false. I don't want it to that. What changes do I need to make here?

MC

Download File:post-4960-1150153978.vi

Link to comment
Thanks Guillaume. The problem is I'm not quite sure how to use the shift register with my Case Loop.

MC

Well, I changed my code a bit but it's working better, but not totally right. It's resetting my Count to 0 when the comparitor is false. I don't want it to that. What changes do I need to make here?

MC

In the "false" case, simply wire the input to the output as a pass-through. Then it won't reset anymore and you'll have the monotonically increasing value you expect. You shouldn't have selected "use default if unwired" option of the output tunnel from your case structure -- in fact, I would personally recommend against using it in general, as it tends to hide the data flow (as well as errors.)

Cheers,

Guillaume Lessard

Link to comment

Are you using the continuous run button? If so, the counter is reset to zero each time you press the stop button.

I've attached a modified version of your vi (LabVIEW 8.0).

I made the following changes;

Used a Select operator from the comparison palette instead of a true/false case statement. This makes the code generally easier to read.

Changed the while loop's conditional terminal to stop on true. (stop sign in lower right corner; right click to change)

Changed the mechanical action for the Stop button on your front panel to latch on release.

Changed the value for the Less? comparison operator to 0.5, as you indicated in your original post.

post-949-1150195711.gif?width=400

Download File:post-949-1150195544.vi

:thumbup: Great job! You might want to explore the comparison palette a bit more. Press <CTRL-H> to turn on the context help and you will see some basic info on the different operators.

Link to comment
In the "false" case, simply wire the input to the output as a pass-through. Then it won't reset anymore and you'll have the monotonically increasing value you expect. You shouldn't have selected "use default if unwired" option of the output tunnel from your case structure -- in fact, I would personally recommend against using it in general, as it tends to hide the data flow (as well as errors.)

Cheers,

Guillaume Lessard

Great, great tip Guillaume. I appreciate it.

MC

Are you using the continuous run button? If so, the counter is reset to zero each time you press the stop button.

I've attached a modified version of your vi (LabVIEW 8.0).

I made the following changes;

Used a Select operator from the comparison palette instead of a true/false case statement. This makes the code generally easier to read.

Changed the while loop's conditional terminal to stop on true. (stop sign in lower right corner; right click to change)

Changed the mechanical action for the Stop button on your front panel to latch on release.

Changed the value for the Less? comparison operator to 0.5, as you indicated in your original post.

post-949-1150195711.gif?width=400

Download File:post-949-1150195544.vi

:thumbup: Great job! You might want to explore the comparison palette a bit more. Press <CTRL-H> to turn on the context help and you will see some basic info on the different operators.

Thank you for your help as well Phillip. I got most of what you said except the "reset to zero each time pressing the stop button". With your program, the counter is still reset to zero each time I stop and start, is it not?

MC

Link to comment

It is set to zero at the start of the vi.

Note that there are two ways to run the vi. Run, and Run Continiously. (ying-yang type arrows?).

If you press Run Continiously (not generally advised), the counter will increase and increase until you press it again, or Abort Execution. If you press the front panel stop button while using Run Continiously, the loop will exit, reset the counter to zero and start running again.

You should always include a stop button on looping vis (as you did), and ONLY use that to stop the vi; do NOT use the Abort Execution (stop sign) at the top of the window :nono:. This is for aborting a hung vi during development. Looping vis should always initialize shift registers on entry and have a clear method to exit and close any references (if you haven't wotked with these yet, you will soon :) )

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.