LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

register time when switch closed briefly OR remains closed

Thanks for all your help! I'm currently working on your sugestions and incorporating them into my VI. I will let you know how it goes...

 

However, I don't think my problem seems that complicated and was wondering if maybe there was a more direct approach? All I need to change in my current VI is to record the first time that the stop switch closes (regardless if it reopens or is closed multiple times). RIght now, it records the time when it first closes but the switch MUST stay closed until the program stops inorder to record the time.

 

Forgive me if I am repeating myself...And maybe the solution given is already the simplest way...I'm trying the sugestions right now and I'll let you know if they work!

0 Kudos
Message 11 of 22
(1,381 Views)

I don't understand why you have a NOR function for your Start switch and an OR function for the Stop switch (before the loops with case structures)?  Does your DAQ Read return a high or a low when the switch is closed. 

 

For the Start switch, if the switch is open and the DAQ returns False, this would acitvate the True case and record a time before the switch is closed.

 

If the DAQ returns True for an open switch, then the shift register will hold a True on the second iteration. Then it doesn't matter what the DAQ returns, the case will continue to go to the False case, and the time will never be recorded.  Something is wrong here.

 

Same for your Stop switch.  Your shift register is initialized to True.  The True case will always execute, even before the stop switch is closed.  It will record a time every loop iteration.  This is not good.

 

Let me know what the DAQ returns (True for open or True for close).  Then I will fix your vi to capture the correct timestamp upon switch closure.

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 12 of 22
(1,365 Views)

I used NOR for the start switches because I simply close them and release them and the time the switch is released is recorded as the start time. I ended up using OR for the stop switches because I originally wanted to record the time the switch closed (and remained closed with the weight) but now I need to include parameters if the weight falls off and the switch reopens, to still record the initial switch closure.

 

When any switch is closed, the LED turns dark and when the switch reopens, the switch turns green again. I believe the DAQ returns true for closed because the time os recorded when the switch is closed...

 

Thanks for your help!

0 Kudos
Message 13 of 22
(1,344 Views)

I don't see how your time recording of the switches can be right.  For the Start switches, the very first inputs to the NOR will be False from the DAQ because the switch isn't closed yet, and False from the shift register.  False NOR False becomes True.  You are recording the time in the very first loop iteration.  No switch has been closed or released yet.  When you finally close the switch, the DAQ will return True and it will go to the shift register, and the output of NOR will be False.  Then when you release the switch, the NOR will receive False from the DAQ and True from the shift register.  The output will be False, no time recorded.  On the next loop iteration, now you will have two False inputs to the NOR and the output will be True, causing a time recording one loop after the switch has been released.  Then on the next loop iteration, it will record the time again, and again, and again.  You will not have a time recording of the time the switch was released.  You will have a time recording of the last loop iteration.  The code is wrong.

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 14 of 22
(1,332 Views)

Look at the attached vi.  The upper loop shows the right way to capture a time when the switch is released.  The lower loop is your way.  Run it.  Press the boolean to simulate your switch being closed.  Press the boolean again to simulate the switch being opened.  Notice that the upper loop records the value of i precisely when the switch is open.  Notice in the lower loop how the value of i is recorded over and over again.  It stops recording when the switch is closed, and starts again when the switch is open.  Don't use a NOR.  use a NOT-AND combo like in the top loop.

 

Switch.png 

 

Next we will tackle the stop switch.

 

- tbob

Inventor of the WORM Global
Message 15 of 22
(1,328 Views)
Thanks so much! I didn't even realize there was a problem there because I was too focused on the STOP switches! Could you push me in the right direction to the stop switches as well?
0 Kudos
Message 16 of 22
(1,319 Views)

Please explain again what time you want to record regarding the stop switch.  What do you want to do if the stop switch closes and opens several times, or if it closes and never opens?

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 17 of 22
(1,314 Views)

With the current set up, when I start the program, I see the six stop switches on the front panel as a running clock. They take the time from the computer and when the program is run (regardless if any switches have been pressed) the six stop switches are running. And with the current set up, when I close any stop switch and it remains closed, the time stops running the moment the switch is closed. That time is then used in the calculation of the time difference which is later written to a spreadsheet...

 

So since the clock is running when the program begins, I would like the stop switch to register when the switch closes and remains closed OR if it closes and opens again...

 

It may be easier to replicate the new set up you suggested for the start switches sop that the timer isn't always running...? But then it would still need to include recordind the time even when the switch remains closed or is presses multiple times.

 

 

Let me know if you need any further clearification!

0 Kudos
Message 18 of 22
(1,308 Views)

Actually, I think I may have just fixed the timing issue! Of course, it was much simplier than I was making it. I attached my updated VI with the new changes (just your previous suggestion in both the start and stop)

 

Would there be a way to make sure only the first time is recorded everytime the program is run? I only want to hit each STOP switch once and in case ther is bouncing and it is hit multiple times, I would only want the first time.

 

Wow, thanks so much for your help! One problem down, only one to go!

0 Kudos
Message 19 of 22
(1,304 Views)

I have attached the corrected vi.  For the stop switch, you want to record the time the switch closes (as opposed to opens for the start switch), so I moved the NOT function to the shift register side of the AND.  To prevent re-recording if the switch opens and closes again, I added another shift register to hold a flag.  The flag is false until the first time the timestamp is recorded.  Then the flag goes True.  As long as the flag is True, the extra AND gate prevents the time from being recorded again.  So the time gets recorded only once, the very first time the stop switch closes.

 

Clear_Patch[1]_BD.png

- tbob

Inventor of the WORM Global
0 Kudos
Message 20 of 22
(1,299 Views)