meocop Posted June 12, 2006 Report Share Posted June 12, 2006 Hello all, 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. Attached is my code, which does not work. Please help modify my code. Thanks, MC Download File:post-4960-1150148738.vi Quote Link to comment
Guillaume Lessard Posted June 12, 2006 Report Share Posted June 12, 2006 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 Quote Link to comment
meocop Posted June 13, 2006 Author Report Share Posted June 13, 2006 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 Quote Link to comment
Guillaume Lessard Posted June 13, 2006 Report Share Posted June 13, 2006 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 Quote Link to comment
Phillip Brooks Posted June 13, 2006 Report Share Posted June 13, 2006 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. 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. Quote Link to comment
meocop Posted June 13, 2006 Author Report Share Posted June 13, 2006 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. 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 Quote Link to comment
LAVA 1.0 Content Posted June 13, 2006 Report Share Posted June 13, 2006 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 . 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 ) Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.