LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

can you add how many "trues" have ocurred?

I have a vi that generates a "pass" of "fail" indication of a measurement. Can I incrementally add how many times "true" or "false" has been generated? I have the vi in a 'while' loop but I don't exit it until I shut the program down and the rest is in a flat sequence structure.

Tay
0 Kudos
Message 1 of 12
(3,646 Views)
Yes you can, with a little code. Create a shift register and initialise it (LHS input) to 0. Have a case structure inside the loop that is wired to the pass (here, "pass" will be translated as "True").  Inside the case True, increment the count from the shift register.  At the end of the looping, the output from the shift register will be the number of passes.
0 Kudos
Message 2 of 12
(3,645 Views)
Here is what I did. Thanks for the help!

Tay
0 Kudos
Message 3 of 12
(3,612 Views)
Yes, you're incrementing the value, but inside a For Loop instead of a Case structure.
0 Kudos
Message 4 of 12
(3,607 Views)
The loop should be inside a case structure.
0 Kudos
Message 5 of 12
(3,605 Views)


slipstick wrote:
Here is what I did. Thanks for the help!

Looks functionally fine. I am assuming this code is in a subVI and place inside a while loop in the toplevel VI.
 
Howewer:
  1. There is no need for three seperate FOR loops, you can place three shift registers in one while loop and nothing will change except for cleaner code.
  2. Even better, you should combine the three counters into one array, now the code is three times less complex and you only need a single connector to the calling program. (The picture shows one possibility). Note that you need to use the "first call?" primitive to initialize the array on the first call.


Message Edited by altenbach on 12-11-2007 07:47 PM
0 Kudos
Message 6 of 12
(3,598 Views)

Yes, the whole thing is inside a While loop. I used a for loop for each indicator because I couldn't figure out how to exit a while loop with the data and have it execute only once each time the data changes. It still looks to me in your example like the loop will cycle until the stop button is pressed, but you have a few things in there I am unfamiliar with. I'll have to study some more.

The array idea hadn't occurred to me, but you are right. That would make it cleaner. I'll have to change that. Thanks!

Tay

edit - I see what's up. The for loop allows me to see each increment of the counters, but the while loop doesn't update until you leave it. That was why I used the for loop.


Message Edited by slipstick on 12-11-2007 10:28 PM

Message Edited by slipstick on 12-11-2007 10:29 PM
0 Kudos
Message 7 of 12
(3,591 Views)


slipstick wrote:

edit - I see what's up. The for loop allows me to see each increment of the counters, but the while loop doesn't update until you leave it. That was why I used the for loop.

Your FOR loop makes no difference for the indicator update. The loops iterates once, then finishes in a blink. Updating the indicator inside the loop (for or while, same difference!) is only nanoseconds faster and not significant for any practical purpose.
 
My while loop will run exactly once per call of the subVI, so with each call of the while loop it will increment the three counters and exit, storing the last values in the uninitialzied shift register to be added to the new counts at the next call.
 
Please attach your code so I can see how you are calling this.
0 Kudos
Message 8 of 12
(3,579 Views)
Here you go.

Tay
0 Kudos
Message 9 of 12
(3,558 Views)
  • OK, place the shift register in the outer while loop, there is no need to have the inner loops.  (see image below)
  • Use the array method and initialize the shift register with a 3-element I32 array outside the big loop. Now you don't even need the "first run?" primitive.
  • Delete the two "toEXT", they make no sense at all!
  • Keep the representations consistent (e.g. you convert DBL to EXT, then use a SGL indicator!)
  • Replace the case structure with an event structure and place the bulk of your code in it. Make the event "take a meaurement: value change". Rremove all waits, they are no longer needed.
  • Add an empty event for "stop: value change" containing only the stop terminal wired to the loop condition.
  • Note that if you expect to count more than 2^16 counts, you should convert to I32 after the "boolean to 0,1" or you'll overflow. If you can guarantee that the counts wil remain below that, you can leave the "to I32" out and initialize the array with U16.
  • Your sequence structure has no purpose, delete it! There is no reason to delay the analysis by 1000ms.



Message Edited by altenbach on 12-12-2007 09:24 AM
0 Kudos
Message 10 of 12
(3,528 Views)