Motion Control and Motor Drives

cancel
Showing results for 
Search instead for 
Did you mean: 

Count instances of "true" in case structure

I have a case structure with two cases, true and false. Id like to be able to count the number of "trues" and "falses" and keep a running tab. Ideas?
0 Kudos
Message 1 of 6
(4,156 Views)
Probably better posted in the LabVIEW general forum, but use  initialized shift registers to keep a running tally of the counts for true and false. Use an increment within in case to add one to the count.
~~~~~~~~~~~~~~~~~~~~~~~~~~
"It’s the questions that drive us.”
~~~~~~~~~~~~~~~~~~~~~~~~~~
0 Kudos
Message 2 of 6
(4,149 Views)
Hello mprover1. I was able to create a quick example of what you are looking for. The Random Number generator controls what case is exectuted in a Random fashion. Placing the case structure inside a while loop allows utilitzation of the shift registers as well as the ability to run this program for as long as you want. To stop the program, simply hit the stop button on the front panel.
0 Kudos
Message 3 of 6
(4,137 Views)
For those of you who do not have Labview 8.2, I have attached a screenshot of the Labview VI.

NOTE: This is not a picture of 2 parallel while loops! It is a screenshot of the VI when the case structure is true AND a screenshot of the VI when the case structure is false.

Brian F
0 Kudos
Message 4 of 6
(4,136 Views)
Hi,

I too want to count the instances of each case structure.

Using the example provided by Brian, the count will reset back to 0 when the case structure change, but I dont want that to happen. How do I keep record of previous reading and keep adding 1 to it everytime the same case structure come back? Please advise.

Ian
0 Kudos
Message 5 of 6
(4,034 Views)

Hello,

The counts for each structure will only be reset when you stop and start the VI - the initialization on the shift registers applies once before entering the while loop, and thereafter the shift register contains the value which was wired to it on the previous loop iteration.

If you would like to save the value of the shift register across distinct runs of the VI you have a couple options:

1. If the VI will be left in memory (ie. open in the LabVIEW environment) between runs, then you can simply remove the shift register initialization outside the while loop.  The result will be that the shift register will have an INITIAL value of 0 (the first time the VI is run, since opening it in the LabVIEW environment), but then will retain it's current value across subsequent runs of the VI, and therefore maintain your count across distinct runs of the VI.

2. If the VI will be open and closed between runs, then you'll need an external memory source, such as a file.  The idea here is that you would read the counts from a file at the beginning of your program, and write the counts to a file at the end of your program.  Basically you just retrieve the last count value from the file at the beginning, and make sure to update it when your VI is done so it has the updated value for the next run.  Check out the File I/O palette and the shipping examples (in LabVIEW: Help -> Find Examples...) to help you get started, if you're not already familiar.

I think that should solve your problem.

Best Regards,

JLS

Message Edited by JLS on 10-13-2006 02:07 PM

Best,
JLS
Sixclear
0 Kudos
Message 6 of 6
(4,021 Views)