LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Trigger event from number of times switch is pressed

Hi,

I am trying to write a code that when a long arm switch is pressed twice, a solenoid is activated, but when the switch is pressed once, it is not activated. The stimulus is on a moving cylinder rotating at about 5 rpm and so the switch will be alternating between being pressed once or twice (there's four protrusions evenly spaced around the cylinder that are one and two pronged to trigger the switch). I've thought about a case structure but I'm not sure how to indicate whether the switch has been pressed twice. Any help would me much appreciated! Thanks so much. 

0 Kudos
Message 1 of 2
(2,716 Views)

You should break this down in terms of the algorithm you want to use to determine if the output should be triggered.

 

It sounds like what you want is something like (pseudo text-code):

on Input:
new_time = getTime()
if (new_time - last_input_time < some_fixed_time) {
    output = true;
}
last_input_time = new_time;

So if it is, code that in LabVIEW!

 

You can use for example the Tick Count (ms) function to get the current time (or at least, a number that increases with time) and store the previous time in a Shift Register.

You then compare the difference with some constant value - if it is more than the constant value, do nothing - the previous trigger was too far before (i.e. a quarter circle). If the difference is small, then the previous trigger just happened - it was the first prong, and this is the second.

 

If you place this in an Event Structure (I don't know how you're detecting the switch presses) then the Time value is the same as the Tick Count (ms), I believe.

A Case Structure will be the same as an Event Structure, except that you have to use the Timing function explicitly. Both will need the previous time/count to be kept in a Feedback Node or Shift Register.

 

As an extension, you can make the constant that you compare with variable, if for example you can measure the rotation speed. Faster rotation means you'll need a smaller comparison value.


GCentral
Message 2 of 2
(2,653 Views)