LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

boolean indicator event as trigger for counter

I've searched the entire board for triggering an event when a boolean indicator comes on. I only want the event to happen once, everytime the indicator comes on.
The vi has an event that should count, how many times the indicator came on. So far, the counter counts everytime the indicator lights up, but it keeps counting until the indicator goes out again.
This is my first event-thing I've done. I really would need the counter to get back to data that was taken before a specific count.
 
Thanks for your help.
The German Guy
0 Kudos
Message 1 of 6
(4,147 Views)
I am not entirely sure what you are trying to do... but...
it looks like you are passing the value of "rising" to a case structure in a loop. This would trigger the true state of that case each iteration of the loop, thus continuously incrementing your counter....

My suggestion would be to add a shift register that would provide the last state of "rising" rather than feeding this value to the case.
Now, you will control the case by making sure the last state was false and the current case is true...

See if this helps.
0 Kudos
Message 2 of 6
(4,141 Views)
The secret is in the proper use of "implies" from the boolean palette. Compare the old with the new state and implies gives you a false on a rising (off -> on) transition and true otherwise. Just place your counter logic in the false case. 😄
 
Still, I am not sure why you even need events and a second loop. You could do the counting right in the main loop.
 
Attached is a simplified version with all the fluff removed to show the technique (event or direct). LabVIEW 8.0.
 
 
0 Kudos
Message 3 of 6
(4,124 Views)


@the German guy wrote:
This is my first event-thing I've done.

Let me point out another possible problem in your code. The way you use the local variable of "raising" to switch the second case leads to unpredicatable code dues to race conditions. For each iteration of the loop, there is no way to tell if its value is written first to the terminal or read from the local variable. It may not behave as you expect and the lower case can be either in sync or lag one iteration behind the rest of the code. We cannot know!

Proper execution order can be enforced with dataflow. You simply wire the two together, eliminating the local variable. Now you ensure that the lower case can only execute once the comparison has been made (image).

Whenever possible, it is recommended to "go with the dataflow"! 🙂

If you use locals, there is always a potential for race conditions which some newbie programmers "solve" by peppering the diagram with sequence structures to enforce the lost execution order. Why complicate the code is this manner if all you need is a simple 1D object: a wire? 😉

For a similar perspective, have a look at this older thread:

http://forums.ni.com/ni/board/message?board.id=170&message.id=112401#M112401


@the German guy wrote:
 I really would need the counter to get back to data that was taken before a specific count.

Sorry, could you explain once more. I do not understand what you want to do here.

Message Edited by altenbach on 09-03-2006 09:25 AM

0 Kudos
Message 4 of 6
(4,097 Views)

Thanks for the help. I was not able to have a look into it during the weekend as I was not in the office. But I'll sure give it a try somewhen this week and let you know if it worked.

Thanks again

The German Guy
0 Kudos
Message 5 of 6
(4,071 Views)

Hey Guys,

Thanks again for your help. The "implies" really just looks like what I was searching for (you need to know what you are looking for, I didn't exactly). This should really work.

Yes, I think doing all in one loop would be fine. I just had seen some examples where the event structure was outside the main loop, so I copied that and gave it a try.

Thanks for the help.

The German Guy
0 Kudos
Message 6 of 6
(4,069 Views)